summaryrefslogtreecommitdiff
path: root/src/lib/efl/interfaces/efl_gfx_buffer.eo
blob: 0b19b98ec13ac72a9b1de240bbecf014666ad122 (plain)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import efl_gfx_types;

/* FIXME: this is very very low level. expose to apps? */
enum Efl.Gfx.Buffer.Access_Mode {
   none      = 0x0,
   read      = 0x1,
   write     = 0x2,
   cow       = 0x4,  [[Forces copy-on-write if already mapped as read-only. Requires write.]]
}

interface Efl.Gfx.Buffer ()
{
   [[Common APIs for all objects representing images and 2D pixel buffers.]]
   legacy_prefix: null;

   methods {
      @property buffer_size {
         [[Rectangular size of the pixel buffer as allocated in memory.]]
         set {
            [[Potentially not implemented, @.buffer_size may be read-only.]]
         }
         get {}
         values {
            w: int; [[Width in pixels.]]
            h: int; [[Height in pixels.]]
         }
      }
      @property colorspace {
         [[The colorspace defines how pixels are encoded in the image in memory.

           By default, images are encoded in 32-bit BGRA, ie. each pixel takes
           4 bytes in memory, with each channel B,G,R,A encoding the color with
           values from 0 to 255.

           All images used in EFL use alpha-premultipied BGRA values, which
           means that for each pixel, B <= A, G <= A and R <= A.
         ]]
         get {
            [[Returns the current encoding of this buffer's pixels.

              See @Efl.Gfx.Colorspace for more information on the supported
              formats.
            ]]
         }
         values {
            cspace: Efl.Gfx.Colorspace;
         }
      }

      @property stride {
         [[Length in bytes of one row of pixels in memory.

           Usually this will be equal to width * 4, with a plain BGRA image.
           This may return 0 if the stride is not applicable.

           When applicable, this will include the @.buffer_borders as well
           as potential extra padding.
         ]]
         get {}
         values {
            stride: int;
         }
      }

      buffer_update_add {
         [[Mark a sub-region of the given image object to be redrawn.

           This function schedules a particular rectangular region of an
           image object to be updated (redrawn) at the next rendering cycle.
         ]]
         params {
            @in x: int; [[X-offset of the region to be updated.]]
            @in y: int; [[Y-offset of the region to be updated.]]
            @in w: int; [[Width of the region to be updated.]]
            @in h: int; [[Height of the region to be updated.]]
         }
      }

      /* FIXME: too low-level? */
      @property buffer_borders {
         [[Duplicated pixel borders inside this buffer.

           Internally, EFL may require an image to have its border pixels
           duplicated, in particular for GL textures. This property exposes
           the internal duplicated borders to allow calling @.buffer_map
           with the entire pixel data, including those edge pixels.
         ]]
         get {}
         values {
            l: uint(0); [[Left border pixels, usually 0 or 1]]
            r: uint(0); [[Right border pixels, usually 0 or 1]]
            t: uint(0); [[Top border pixels, usually 0 or 1]]
            b: uint(0); [[Bottom border pixels, usually 0 or 1]]
         }
      }

      /* FIXME: split into read-only and writeable methods? */
      /* FIXME: This was copy pasta from ector generic buffer. changed a bit. */
      buffer_map {
         [[Map a region of this buffer for read or write access by the CPU.

           Fetches data from the GPU if needed. This operation may be slow if
           cpu_readable_fast or cpu_writeable_fast are not true, or if the
           required colorspace is different from the internal one.

           Note that if the buffer has @.buffer_borders, then $x and $y may
           be negative.
         ]]
         params {
            @out length: uint @nonull; [[Accessible buffer size in bytes, should not be $null.]]
            @in mode: Efl.Gfx.Buffer.Access_Mode; [[Specifies whether to map for read-only,
                                                    write-only or read-write access (OR combinaison of flags).]]
            @in x: int @optional;  [[X position of the top-left pixel to map, defaults to 0.]]
            @in y: int @optional;  [[Y position of the top-left pixel to map, defaults to 0.]]
            @in w: uint @optional; [[If 0, defaults to the buffer width.]]
            @in h: uint @optional; [[If 0, defaults to the buffer height.]]
            @in cspace: Efl.Gfx.Colorspace @optional; [[Requested colorspace. If differen from the internal cspace,
                                                        map should try to convert the data into a new buffer.
                                                        argb8888 by default.]]
            @out stride: uint @optional; [[Returns the length in bytes of a mapped line]]
         }
         return: ubyte* @warn_unused; [[Pointer to the top-left pixel data. Returns $null in case of failure]]
      }
      buffer_unmap {
         [[Unmap a region of this buffer, and update the internal data if needed.

           EFL will update the internal image if the map had write access.
         ]]
         params {
            @in data: ubyte*; [[Data pointer returned by a previous call to map]]
            @in length: uint; [[Must be the same as returned by map.]]
         }
      }
      /* note: not a property because the refcount needs to be explicit
       * between set and get */
      /* FIXME: not bindable to JS, potentially tricky to bind to Lua */
      buffer_set {
         [[Set the pixels for this buffer, or allocate a new memory region.

           EFL will use $pixels directly, and update the GPU-side texture
           if required. This will mark the image as dirty.

           If $pixels is $null, then a new empty buffer will be allocated.
           If the buffer already had pixel data, the previous image data will
           be dropped. This is the same as @.buffer_copy_set.

           If $pixels is the return value of @.buffer_get then EFL will
           decrement its internal reference count on the buffer data. Call
           @.buffer_update_add to flush updates and indicate changes in
           the pixel data.

           The memory buffer $pixels must be large enough to hold
           $width x $height pixels encoded in the colorspace $cspace.
           Alternatively $pixels must be larger than $height x $stride
           in bytes.

           See also @.buffer_copy_set if you want EFL to copy the input buffer
           internally.
         ]]
         params {
            @in pixels: void* @nullable; [[If $null, allocates an empty buffer]]
            @in width: int;
            @in height: int;
            @in stride: int @optional; [[If 0, automatically guessed from the $width.]]
            @in cspace: Efl.Gfx.Colorspace @optional; [[argb8888 by default.]]
            @in alpha: bool; [[$true if the alpha channel is used.]]
            @in l: uint @optional; [[Left border pixels, usually 0 or 1. Not supported yet!]]
            @in r: uint @optional; [[Right border pixels, usually 0 or 1. Not supported yet!]]
            @in t: uint @optional; [[Top border pixels, usually 0 or 1. Not supported yet!]]
            @in b: uint @optional; [[Bottom border pixels, usually 0 or 1. Not supported yet!]]
            /* FIXME: do we need writable flag? */
         }
         return: bool @warn_unused; [[This function returns $false in case of failure.]]
      }
      buffer_copy_set {
         [[Set the pixels for this buffer by copying them, or allocate
           a new memory region.

           This will allocate a new buffer in memory and copy the input
           $pixels to it. The internal colorspace is not guaranteed to
           be preserved, and colorspace conversion may happen internally.

           If $pixels is $null, then a new empty buffer will be allocated.
           If the buffer already had pixel data, the previous image data will
           be dropped. This is the same as @.buffer_set.

           The memory buffer $pixels must be large enough to hold
           $width x $height pixels encoded in the colorspace $cspace.
           Alternatively $pixels must be larger than $height x $stride
           in bytes.

           $pixels should not be the return value of @.buffer_get.

           There is no copy equivalent to this function, as you can easily
           call @.buffer_get and allocate the proper buffer on your side,
           followed by a memory copy and @.buffer_set.
         ]]
         params {
            @in pixels: const(void)* @nullable; [[If $null, allocates an empty buffer]]
            @in width: int;
            @in height: int;
            @in stride: int @optional; [[If 0, automatically guessed from the $width.]]
            @in cspace: Efl.Gfx.Colorspace @optional; [[argb8888 by default.]]
            @in alpha: bool; [[$true if the alpha channel is used.]]
            @in l: uint @optional; [[Left border pixels, usually 0 or 1. Not supported yet!]]
            @in r: uint @optional; [[Right border pixels, usually 0 or 1. Not supported yet!]]
            @in t: uint @optional; [[Top border pixels, usually 0 or 1. Not supported yet!]]
            @in b: uint @optional; [[Bottom border pixels, usually 0 or 1. Not supported yet!]]
         }
         return: bool @warn_unused; [[This function returns $false in case of failure.]]
      }
      buffer_get {
         [[Get a direct pointer to the internal pixel data.

           This will increment an internal reference counter on the internal
           buffer.

           If $to_write is $true, this may trigger a copy of the internal
           pixel data, and return a writable memory block.

           Call @.buffer_size.get and @.buffer_borders.get to determine the
           value of width, height and l, r, t, b.

           Warning: @.buffer_set MUST be called as soon as possible after
           calling @.buffer_get. @.buffer_update_add should be called after
           @.buffer_set if $to_write was $true and the pixel data has been
           modified. Once @.buffer_set is called, the pointer return from
           @.buffer_get is not valid anymore.
         ]]
         params {
            @in to_write: bool; [[If $true, requests write access]]
            @out length: uint @optional; [[Size of the buffer in bytes.]]
            @out width: int @optional;
            @out height: int @optional;
            @out stride: int @optional; [[Returns the length of one row of pixels in bytes.]]
            @out cspace: Efl.Gfx.Colorspace @optional; [[Pixel encoding of the returned buffer.]]
            @out alpha: bool; [[$true if the alpha channel is used.]]
            @out l: uint @optional; [[Left border pixels, usually 0 or 1. Not supported yet!]]
            @out r: uint @optional; [[Right border pixels, usually 0 or 1. Not supported yet!]]
            @out t: uint @optional; [[Top border pixels, usually 0 or 1. Not supported yet!]]
            @out b: uint @optional; [[Bottom border pixels, usually 0 or 1. Not supported yet!]]
         }
         return: void* @warn_unused;
      }
      /* Note: border, span and buffer flags not imported from ector buffer */
   }
}