-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscreencaptureresults.go
More file actions
129 lines (111 loc) · 3.32 KB
/
Copy pathscreencaptureresults.go
File metadata and controls
129 lines (111 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package gui
import (
"fmt"
"github.com/AndroidGoLab/binder/gralloc"
"github.com/AndroidGoLab/binder/parcel"
)
// ScreenCaptureResults holds the result of a SurfaceFlinger screen
// capture. The wire format is defined in C++ (ScreenCaptureResults.cpp),
// not AIDL.
type ScreenCaptureResults struct {
// Buffer contains the captured pixels as a gralloc GraphicBuffer.
// Nil if capture failed.
Buffer *gralloc.Buffer
// CapturedSecureLayers indicates if secure content was captured.
CapturedSecureLayers bool
// CapturedHdrLayers indicates if HDR content was captured.
CapturedHdrLayers bool
// CapturedDataspace is the dataspace of the captured content.
CapturedDataspace uint32
// HdrSdrRatio is the HDR/SDR luminance ratio.
HdrSdrRatio float32
}
var _ parcel.Parcelable = (*ScreenCaptureResults)(nil)
func (s *ScreenCaptureResults) MarshalParcel(
p *parcel.Parcel,
) error {
return fmt.Errorf("ScreenCaptureResults.MarshalParcel: not implemented")
}
func (s *ScreenCaptureResults) UnmarshalParcel(
p *parcel.Parcel,
) error {
// GraphicBuffer (nullable).
hasBuffer, err := p.ReadBool()
if err != nil {
return fmt.Errorf("reading hasBuffer: %w", err)
}
if hasBuffer {
buf, err := gralloc.ReadGraphicBuffer(p)
if err != nil {
return fmt.Errorf("reading GraphicBuffer: %w", err)
}
s.Buffer = buf
}
// Fence (nullable). We skip it — just need to advance the parcel.
hasFence, err := p.ReadBool()
if err != nil {
return fmt.Errorf("reading hasFence: %w", err)
}
if hasFence {
// Fence is flattened as: int32(flattenedSize) + int32(fdCount)
// + raw[flattenedSize] + fds. For a valid fence, flattenedSize=4,
// fdCount=1, raw=uint32(0), fd=fenceFd.
fenceSize, err := p.ReadInt32()
if err != nil {
return fmt.Errorf("reading fence size: %w", err)
}
fenceFdCount, err := p.ReadInt32()
if err != nil {
return fmt.Errorf("reading fence fd count: %w", err)
}
if fenceSize > 0 {
if _, err := p.Read(int(fenceSize)); err != nil {
return fmt.Errorf("reading fence data: %w", err)
}
}
for i := int32(0); i < fenceFdCount; i++ {
if _, err := p.ReadFileDescriptor(); err != nil {
return fmt.Errorf("reading fence fd: %w", err)
}
}
} else {
// No fence — read the status int32.
if _, err := p.ReadInt32(); err != nil {
return fmt.Errorf("reading fence status: %w", err)
}
}
s.CapturedSecureLayers, err = p.ReadBool()
if err != nil {
return fmt.Errorf("reading capturedSecureLayers: %w", err)
}
s.CapturedHdrLayers, err = p.ReadBool()
if err != nil {
return fmt.Errorf("reading capturedHdrLayers: %w", err)
}
dataspace, err := p.ReadUint32()
if err != nil {
return fmt.Errorf("reading capturedDataspace: %w", err)
}
s.CapturedDataspace = dataspace
// gainMap and hdrSdrRatio were added in Android 15 (API 35).
// Older versions end the parcel after capturedDataspace.
if p.Position() >= p.Len() {
return nil
}
// Optional gain map (nullable GraphicBuffer).
hasGainMap, err := p.ReadBool()
if err != nil {
return fmt.Errorf("reading hasGainMap: %w", err)
}
if hasGainMap {
// Skip the gain map buffer — we don't need it.
if _, err := gralloc.ReadGraphicBuffer(p); err != nil {
return fmt.Errorf("reading gain map: %w", err)
}
}
s.HdrSdrRatio, err = p.ReadFloat32()
if err != nil {
return fmt.Errorf("reading hdrSdrRatio: %w", err)
}
return nil
}