source: svn/newcon3bcm2_21bu/BSEAV/api/include/bsettop_graphics.h

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 40.8 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2010, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bsettop_graphics.h $
11 * $brcm_Revision: 23 $
12 * $brcm_Date: 3/1/10 10:42a $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /BSEAV/api/include/bsettop_graphics.h $
19 *
20 * 23   3/1/10 10:42a jgarrett
21 * SW7550-272: Adding 32-bit YCbCr graphics format
22 *
23 * 22   11/10/09 3:42p jgarrett
24 * SW7420-166: Adding graphics heap index
25 *
26 * 21   10/5/09 11:06a jgarrett
27 * SW7325-612: Fixing bitmasks for certain blending operations
28 *
29 * 20   10/21/08 10:26a vsilyaev
30 * PR 46638: Added  blit opearations
31 *
32 * 19   6/26/08 11:11a jgarrett
33 * PR 36285: Fixing deep copy inside blit_params
34 *
35 * 18   12/18/07 10:49a vsilyaev
36 * PR 38269: Added new parameters to change scan-order
37 *
38 * 17   6/20/07 10:26a jgarrett
39 * PR 31505: Unifying name of graphics handle in prototypes
40 *
41 * 16   4/13/07 3:51p vsilyaev
42 * PR 29840: Added API to render graphics surface as the decoder output
43 *
44 * 15   3/22/07 1:35p vsilyaev
45 * PR 28558: Added bsurface_extended_blit function
46 *
47 * 14   1/30/07 11:22a vsilyaev
48 * PR 25685: Improve documentation and operation types for
49 * bsurface_blended_fill
50 *
51 * 13   12/14/06 3:15p ahulse
52 * PR25685: Add function bsurface_blended_fill to allow a blended fill of
53 * a surface
54 *
55 * 12   8/29/06 1:43p erickson
56 * PR23964: added BSURFACE_SELECT_PALETTE_WITH_COLORKEY support
57 *
58 * 11   7/7/06 10:17a erickson
59 * PR22272: Add ability to specify alignment for
60 * bgraphics_create_framebuffer()
61 *
62 * PR22272/1   6/23/06 1:21p nilesh
63 * PR22272: Add ability to specify alignment for
64 * bgraphics_create_framebuffer()
65 *
66 * 10   6/8/06 10:27a erickson
67 * PR20908: added double buffering API changes
68 *
69 * 9   5/4/06 12:38p erickson
70 * PR19334: added bsurface_settings.disable_automatic_cache_flush to
71 * eliminate unnecessary cache flushes if app wants to handle manual
72 * flushing
73 *
74 * 8   4/28/06 2:26p jgarrett
75 * PR 21279: Adding option to create surface using externally allocated
76 * memory
77 *
78 * 7   12/13/05 4:53p erickson
79 * PR18439: added bdecode_acquire_capture_buffer et al to return capture
80 * buffer to application
81 *
82 * 6   7/1/05 2:50p erickson
83 * PR15351: modified bgraphics_sync to clear entire framebuffer if any
84 * surface is visible. This handles all conditions and changes behavior
85 * only slightly.
86 *
87 * 5   6/30/05 1:08p erickson
88 * PR15352: change meaning of BSURFACE_SET_DEST_ALPHA_WITH_AVG_ALPHA to
89 * blend src1 and src2 alpha, not average. Then use it in bgraphics_sync
90 * if not using per-surface alpha and offscreen_framebuffer is false.
91 *
92 * 4   3/15/05 5:01p erickson
93 * PR14343: added condition to bsurface_blit that src2 cannot scale to
94 * dest
95 *
96 * 3   3/8/05 4:39p erickson
97 * PR14343: fixed comment
98 *
99 * 2   3/8/05 9:49a erickson
100 * PR14343: added bsurface_blit
101 *
102 * 1   2/7/05 7:05p dlwin
103 * Merge down for release 2005_REFSW_MERGETOMAIN:
104 *
105 * Irvine_BSEAVSW_Devel/39   1/17/05 10:33a erickson
106 * PR13325: updated docs
107 *
108 * Irvine_BSEAVSW_Devel/38   12/17/04 9:10a erickson
109 * PR13325: added bsurface_sync and updated docs
110 *
111 * Irvine_BSEAVSW_Devel/37   11/4/04 12:28p erickson
112 * PR13101: added a8 pixel_format support, tweaked comments
113 *
114 * Irvine_BSEAVSW_Devel/36   10/25/04 12:08p erickson
115 * PR12934: added async_blits parameter instead of compile-time option
116 *
117 * Irvine_BSEAVSW_Devel/35   9/22/04 5:02p erickson
118 * PR12751: updated example
119 *
120 * Irvine_BSEAVSW_Devel/34   9/13/04 1:58p erickson
121 * PR11081: clarified comment on pixel format related to palettized values
122 *
123 * Irvine_BSEAVSW_Devel/33   9/2/04 3:40p erickson
124 * PR12553: clarified bgraphics_pixel when pixel value is less than 32
125 * bits
126 *
127 * Irvine_BSEAVSW_Devel/32   9/2/04 11:59a erickson
128 * PR12555: modified comments for palettized color support
129 *
130 * Irvine_BSEAVSW_Devel/31   7/13/04 6:31p dlwin
131 * PR11578: Added API to load CLUT for clut surfaces.
132 *
133 * Irvine_BSEAVSW_Devel/30   7/6/04 3:53p erickson
134 * PR11771: settop api dataflow redesign
135 *
136 * Irvine_BSEAVSW_Devel/29   6/30/04 4:26p bandrews
137 * PR11578: Moved palette member from bsurface_create_settings to
138 * bsurface_settings.
139 *
140 * Irvine_BSEAVSW_Devel/28   6/21/04 7:53p dlwin
141 * PR11432: Adding CLUT2 and CLUT4 support.
142 *
143 * Irvine_BSEAVSW_Devel/27   6/2/04 2:44p erickson
144 * PR11204: changed/removed deprecated settop api functions
145 *
146 * Irvine_BSEAVSW_Devel/26   5/17/04 11:03a erickson
147 * PR11135: renamed prototype parameter names for autoparsing code
148 *
149 * Irvine_BSEAVSW_Devel/25   4/14/04 5:58p vsilyaev
150 * PR 8850: Fixed comments, replaced blit with copy.
151 *
152 * Irvine_BSEAVSW_Devel/24   3/23/04 9:02a erickson
153 * PR9835: removed documentation that says implicit bgraphics_sync's will
154 * be called
155 *
156 * Irvine_BSEAVSW_Devel/23   3/22/04 9:36a erickson
157 * PR10166: updated documentation on bgraphics_sync
158 *
159 * Irvine_BSEAVSW_Devel/22   3/19/04 2:34p erickson
160 * PR8850: Changed documentation for bgraphics_pixel in bsurface_fill. It
161 * is now consistently ARGB8888 format and not an exception as it was
162 * documented.
163 *
164 * Irvine_BSEAVSW_Devel/21   2/13/04 4:49p marcusk
165 * PR9728: Updated to keep API the same (added a new function call)
166 *
167 * Irvine_BSEAVSW_Devel/20   2/13/04 11:37a marcusk
168 * PR9728: Updated code to support different formats and new method of
169 * scaling.
170 *
171 * Irvine_BSEAVSW_Devel/19   2/10/04 4:06p erickson
172 * PR9691: updated comments for 7038
173 *
174 * Irvine_BSEAVSW_Devel/18   2/10/04 11:46a erickson
175 * PR9691: bgraphics_update was a bogus name for bgraphics_sync. Renamed
176 * it in the documentation. No api change.
177 *
178 * Irvine_BSEAVSW_Devel/Irvine_BSEAVSW_Devel_7038/2   12/17/03 10:00p vsilyaev
179 * Pass pixel by value not by reference.
180 *
181 * Irvine_BSEAVSW_Devel/Irvine_BSEAVSW_Devel_7038/1   12/5/03 9:17p vsilyaev
182 * Changed return type of bsurface_destroy to void.
183 *
184 * Irvine_BSEAVSW_Devel/16   11/11/03 4:56p erickson
185 * PR8600: graphics are disabled when the display format is set because
186 * the app must adjust scaling and other
187 * parameters, and settop api can't do it automatically.
188 *
189 * Irvine_BSEAVSW_Devel/15   11/7/03 4:28p erickson
190 * PR8583: removing, fixing or implementing TODO's
191 *
192 * Irvine_BSEAVSW_Devel/14   11/4/03 2:42p erickson
193 * documentation changes
194 *
195 * Irvine_BSEAVSW_Devel/13   10/31/03 11:58a erickson
196 * settop api changes after internal review
197 *
198 * Irvine_BSEAVSW_Devel/12   10/28/03 11:27a erickson
199 * settop api reworks after internal design view
200 *
201 * Irvine_BSEAVSW_Devel/11   10/22/03 11:23a erickson
202 * settop api pass-through type conversion
203 *
204 * Irvine_BSEAVSW_Devel/10   10/1/03 10:16a erickson
205 * updated information for docjet
206 *
207 * Irvine_BSEAVSW_Devel/9   9/30/03 1:13a erickson
208 * updated docjet documentation
209 *
210 * Irvine_BSEAVSW_Devel/8   9/17/03 5:04p erickson
211 * updated documentation for DocJet
212 *
213 * Irvine_BSEAVSW_Devel/7   8/12/03 9:42a erickson
214 * changes after pre-review meeting
215 *
216 * Irvine_BSEAVSW_Devel/6   7/30/03 10:20a erickson
217 * enfore the settings.position.width/height are not modified
218 *
219 * Irvine_BSEAVSW_Devel/5   7/30/03 9:38a erickson
220 * added cplusplus wrappers
221 *
222 * Irvine_BSEAVSW_Devel/4   7/28/03 3:47p erickson
223 * removed _impl
224 *
225 * Irvine_BSEAVSW_Devel/3   7/25/03 4:22p erickson
226 * in the middle of rework, does not compile
227 *
228 * Irvine_BSEAVSW_Devel/2   7/8/03 3:19p erickson
229 * added graphics api
230 *
231 ***************************************************************************/
232#ifndef BSETTOP_GRAPHICS_H__
233#define BSETTOP_GRAPHICS_H__
234
235#ifdef __cplusplus
236extern "C" {
237#endif
238
239/*=********************************************
240The graphics interface supports Broadcom's newest framebuffer graphics
241model as well as the mulitple-surface graphics architecture.
242
243All pixel formats are supported along with chromakey and alphablending
244effects.
245
246On some platforms the hardware supports copy and fill, otherwise it is supported
247with the CPU.
248***********************************************/
249
250/*
251Summary:
252For non-palettized surfaces, this is a ARGB8888 pixel.
253When used, it will be converted into the desired pixel for a surface.
254For palettized surfaces, this is the palette index plus possible alpha value.
255
256Description:
257For palette indexes, values should be packed into the least significant bits
258of bgraphics_pixel. For instance, a8_palette8 uses byte[0] for the palette8 index,
259byte[1] for alpha8 value and ignores byte[2] and byte[3].
260palette2 uses bits 0 and 1 of byte[0] and ignores the rest.
261*/
262typedef uint32_t bgraphics_pixel;
263
264/*
265Summary:
266        Pixel format of a surface.
267*/
268typedef enum bgraphics_pixel_format {
269        bgraphics_pixel_format_r5_g6_b5,         /* 16-bit, no per-pixel alpha */
270        bgraphics_pixel_format_a1_r5_g5_b5,      /* 16-bit */
271        bgraphics_pixel_format_r5_g5_b5_a1,      /* 16-bit */
272        bgraphics_pixel_format_a4_r4_g4_b4,      /* 16-bit */
273        bgraphics_pixel_format_r4_g4_b4_a4,      /* 16-bit */
274        bgraphics_pixel_format_a8_r8_g8_b8,      /* 32-bit */
275
276        bgraphics_pixel_format_palette8,         /* 8-bit Palette index */
277        bgraphics_pixel_format_a8_palette8,      /* A8 and 8-bit Palette index */
278
279        bgraphics_pixel_format_a0,               /* 0-bit surface (constant color, constant alpha) */
280        bgraphics_pixel_format_a8,               /* 8-bit alpha-only surface (constant color) */
281
282        bgraphics_pixel_format_y08_cb8_y18_cr8,  /* 32-bit Y0_8 Cb_8 Y1_8 Cr_8 */
283        bgraphics_pixel_format_cr8_y18_cb8_y08,  /* 32-bit Cr_8 Y1_8 Cb_8 Y0_8 */
284        bgraphics_pixel_format_a8_y8_cb8_cr8,    /* 32-bit A_8 Y_8 Cb_8 Cr_8 */
285
286        bgraphics_pixel_format_video_tunnel,      /* 0-bit tunnel to video. Use to allow video to show through graphics
287                                                                                                without chromakey and without per-pixel alpha. */
288        bgraphics_pixel_format_palette2,                  /* 2-bit palette index */
289        bgraphics_pixel_format_palette4                   /* 4-bit palette index */
290} bgraphics_pixel_format;
291
292/*
293Summary:
294A palette of colors to be used with palettized surfaces.
295*/
296typedef struct bgraphics_palette {
297        const bgraphics_pixel *palette; /* [size_is(length)] */
298        unsigned length;
299} bgraphics_palette;
300
301/*
302Summary:
303        Universal settings for a graphics engine.
304Description:
305        Graphics scaling is calculated by comparing the source width/height
306        with the destination width/height.
307
308        Instead of assuming the destination width/height is the width/height of the
309        display format, the application must specify it independently. This is because
310        the real issue is not the width/height of the display forward, but the x/y/width/height
311        of the viewable area of the TV. This can vary depending on the application and
312        target platform.
313
314        The source width/height are used to define the scale factor used by graphic
315        surfaces.
316*/
317typedef struct bgraphics_settings{
318        bool enabled;                                           /* Is the graphics engine enabled? If disabled,
319                                                                                        no graphics will appear and no changes will
320                                                                                        be applied until it is reenabled. */
321        bool chromakey_enabled;                         /* should the chromakey values be applied? */
322        bgraphics_pixel lower_chromakey;        /* lower bound of chromakey range */
323        bgraphics_pixel upper_chromakey;        /* lower bound of chromakey range */
324        bool antiflutter_filter;                        /* should the antiflutter filter be enabled? */
325        bool async_blits;                                       /* Performs asynchronous blits and fills if
326                                                                                        possible. If false, then bgraphics_sync does
327                                                                                        not need to be called between fill/blits and
328                                                                                        memory writes. */
329        bool offscreen_framebuffer;     /* A common technique is for an application to create
330                a single fixed-size surface, then blit the entire surface to the actual
331                framebuffer. This handles scaling, and double-buffering. By setting this
332                parameter to true, the bgraphics_sync call will assume this is the technique
333                you are using. Therefore, it will do two things:
334                1) when double-buffering, it will not update the other framebuffer surface
335                        because it will be completely overwritte
336                2) do a copy, not a blend, when writing to the framebuffer.
337                If you do not use bgraphics_sync, this parameter has no effect. */
338        unsigned source_width; /* The virtual width of the graphics area
339                                                                that will be displayed. It used for scaling up to the destination
340                                                                width. */
341        unsigned source_height; /* The virtual height of the graphics area
342                                                                that will be displayed. It used for scaling up to the destination
343                                                                height. */
344        unsigned destination_width; /* Width of the display. This could be the same as the
345                                                                width of the display format, but it might be different
346                                                                because the real issue is the viewable area. Adjust this
347                                                                for different scaling. */
348        unsigned destination_height; /* Width of the display. This could be the same as the
349                                                                width of the display format, but it might be different
350                                                                because the real issue is the viewable area. Adjust this
351                                                                for different scaling. */
352        bsettop_callback operation_complete_callback; /* This optional callback notifies the
353                user that all asynchronous fills and blits have completed. */
354        void *callback_context; /* User defined context which is passed into the
355                above callback function. */
356} bgraphics_settings;
357
358/**
359Summary:
360        Open and enable a graphics engine.
361Description:
362        Each display can have only one graphics engine. A graphics
363        engine can only go to one display.
364
365        Graphics can also appear on a second
366        display when it is driven by a cloned window (see bdecode_window_close),
367        however those graphics are identical to the other display.
368
369        When the display format for the linked display changes, the graphics engine
370        will be automatically disabled. See bdisplay_set for details.
371**/
372bgraphics_t bgraphics_open(
373        bobject_t id,
374        bdisplay_t display      /* display on which the graphics are displayed */
375        );
376
377/*
378Summary:
379        Close a graphics engine.
380Description:
381        You should close all surfaces before closing a graphics engine.
382        Also, you must close graphics before closing the display to which it is linked.
383        Generally, close things in the opposite order in which you brought them up.
384*/
385void bgraphics_close(
386        bgraphics_t graphics    /* handle returned by bgraphics_open */
387        );
388
389/**
390Summary:
391        Get current graphics engine settings.
392**/
393void bgraphics_get(
394        bgraphics_t graphics,   /* handle returned by bgraphics_open */
395        bgraphics_settings *settings /* [out] */
396        );
397
398/**
399Summary:
400        Set graphics engine settings.
401**/
402bresult bgraphics_set(
403        bgraphics_t graphics,   /* handle returned by bgraphics_open */
404        const bgraphics_settings *settings
405        );
406
407/**
408Summary:
409Sync all visible surfaces and automatically blit visible surfaces to the
410framebuffer on framebuffer-enabled systems.
411
412Description:
413This is an optional and a potentially very disagreeable call.
414It was designed to provide compatibility betweeen legacy (i.e. pre-7038) real-time graphics
415compositor systems and magnum (i.e. 7038 and beyond) framebuffer based system.
416If you have complex graphics operations and have no need for legacy support, you probably should
417not use this call. Instead, you can draw, copy, blit or fill directly into the framebuffer from any surface.
418bgraphics_sync will constrain your scaling and blending capabilities. Performing these operations manually without
419bgraphics_sync will give you much more flexibility.
420
421The behavior of bgraphics_sync depends on whether the platform uses a real-time
422graphics compositor or not. On legacy systems, visible surfaces are composited
423for each field with real-time priority and make up a "virtual framebuffer." In this case,
424bgraphics_sync is equivalent to bsurface_sync on all visible surfaces.
425
426The following comments only apply to magnum-based systems:
427
428On magnum systems, surfaces which are marked visible in the
429Settop API are not visible in and of themselves. Instead, the visible flag means that bgraphics_sync will
430automatically blend or copy the surface to the one and only visible surface (called the framebuffer).
431The process is as follows:
432
4331. The framebuffer's cached memory will be flushed.
434
4352. A check is performed to see if any surfaces are marked visible. If not, skip to step 6.
436This is equivalent to bsurface_sync(framebuffer).
437
4383. The framebuffer will be cleared with a background color, using either the chromakey value or all 0's
439(black with possible alpha 0). All user operations drawn directly to the framebuffer will be wiped out.
440This mimics the legacy "virtual framebuffer" where no surface simply meant no graphics.
441If bgraphics_settings.offscreen_framebuffer is true, then it is assumed that the visible surface(s) will
442completely cover the entire framebuffer. In this case, no clearing or per-pixel blending is performed.
443
4444. Cached memory for every visible surface is flushed.
445
4465. Every visible surface is copied to the framebuffer with possible blending, scaling and translation.
447Blending is based on the bsurface_settings.alpha value or alpha-per-pixel values.
448Scaling and translation of the surface's x,y,width and height is based on the proportion of
449bgraphics_settings.source_width to destination_width and source_height to destination_height.
450
4516. Wait for all async fills and blits to complete.
452**/
453bresult bgraphics_sync(
454        bgraphics_t graphics    /* handle returned by bgraphics_open */
455        );
456
457/**
458Summary:
459Sync a surface by flushing cached memory and waiting for any async blits or fills.
460
461Description:
462If bgraphics_settings.async_blits is true, then fills and blits are executed
463asynchrously. If you are using these in conjunction with CPU writes, then you must
464sync before doing CPU writes.
465
466On magnum platforms, if bsurface_sync is called on the framebuffer, it calls bgraphics_sync(surface->graphics).
467If you have visible surfaces, they will be automatically blitted. If you do not have
468visible surfaces, it will simply sync the framebuffer's surface like all other surfaces.
469
470bsurface_get_memory returns a pointer to cached memory, and so bsurface_sync
471will flush the cache.
472
473bsurface_sync should be called at the boundary between fills/blits and CPU accesses. The following
474example illustrates why.
475
476Example:
477        s1 = bsurface_create(g, &create_settings);
478        bsurface_get_mem(s1, &mem);
479
480        bsurface_fill(s1, &rect, BLACK);
481        bsurface_sync(s1, NULL); // this waits until fill is done
482        ((uin32_t*)mem.buffer)[10] = BLUE; // this blue pixel is now guaranteed to
483                // be drawn on top of the black box
484        bsurface_sync(); // this guarantees that you can see the BLUE pixel on the screen
485                // it also makes sure the cache is flushed before doing the next fill
486        bsurface_fill(s1, &rect, BLACK);
487        bgraphics_sync(g, NULL);
488**/
489bresult bsurface_sync(
490        bsurface_t surface      /* handle returned by bsurface_create */
491        );
492
493/*
494Summary:
495Switch between framebuffers in double-buffered mode.
496
497Description:
498Double-buffered mode is enabled by a parameter to bgraphics_create_framebuffer. Implicitly created
499framebuffers are not double-buffered.
500
501bgraphics_flip performs an implicit call to bgraphics_sync.
502
503bgraphics_flip will copy the contents of the currently displayed buffer into the
504new off-screen buffer. The app can then make incremental updates to the framebuffer instead of redrawing
505the entire framebuffer. However, if bgraphics_settings.offscreen_framebuffer is true, then this copy
506will not occur because the app will be redrawing the entire framebuffer.
507*/
508bresult bgraphics_flip(
509        bgraphics_t graphics    /* handle returned by bgraphics_open */
510        );
511
512/*
513Summary:
514Waits for previous call to bgraphics_flip to complete.
515
516Description:
517This function waits for the previous call to bgraphics_flip to finish flipping the back
518buffer to the front buffer. This function should be called before calling bgraphics_flip
519again.
520*/
521bresult bgraphics_flip_sync(
522        bgraphics_t graphics    /* handle returned by bgraphics_open */
523        );
524
525/*
526Summary:
527        Information about the memory used by a surface.
528*/
529typedef struct bsurface_memory {
530        void *buffer; /* pointer to mapped memory. Directly accessible by the application.
531                                                This must be typecasted to the correct pixel format, for example
532                                                unsigned short * for a 16 bit pixel format or unsigned long *
533                                                for a 32 bit pixel format. */
534        unsigned int pitch; /* The memory width of the surface in bytes. The visible width
535                                                        is <= pitch. Pitch must be used to calculate the next
536                                                        line of the surface. See the example in the bsurface_get_memory
537                                                        documentation. */
538} bsurface_memory;
539
540/*
541Summary:
542Settings needed to create a surface.
543Description:
544These cannot be changed after the surface has been created.
545
546For palettized surfaces, a default palette of all black will be created. You must
547call bsurface_set or bsurface_load_clut to set your desired palette.
548*/
549typedef struct bsurface_create_settings {
550        bgraphics_pixel_format pixel_format;    /* format of the surface. */
551        unsigned int width;                                             /* visible width of the surface. The pitch
552                                                                                        may be wider. */
553        unsigned int height;                                    /* visible height of the surface. */
554
555        unsigned int alignment; /* optional buffer alignment specified
556                                 * as a power of 2, measured in bytes.
557                                 * 0 is default alignment (default), 1
558                                 * is 2-byte aligned, 2 is 4-byte
559                                 * aligned, etc. */
560
561        unsigned int pitch; /* optional buffer pitch, measured in
562                             * bytes. 0 is the default pitch (width *
563                             * sizeof(pixel)). */
564
565        unsigned int heap_index; /* optional heap index setting */
566} bsurface_create_settings;
567
568/*
569Summary:
570        Initialize the bsurface_create_settings structure with defaults.
571Description:
572        This is required before using a bsurface_create_settings structure.
573*/
574void bsurface_create_settings_init(
575        bsurface_create_settings *create_settings,      /* [out] */
576        bgraphics_t graphics            /* required for possible resource-dependent defaults */
577        );
578
579/**
580Summary:
581Creates a frame buffer, or master surface, using the create settings.
582
583Description:
584On legacy platforms, this function is optional because visible surfaces will be
585composited with video at realtime. However the Settop API will mimic a framebuffer
586for API compatibility.
587
588On magnum platforms, a framebuffer is an essential part of the graphics architecture.
589If you do not explicity create a framebuffer using this function, a framebuffer
590will be implicitly created when you create the first surface.
591
592Care should be taken when specifying the frame buffer size and
593pixel format, as all other surfaces will need to be mapped to this frame buffer.
594If the width is smaller than the destination_width specified by the bgraphics_set()
595function, the horizontal graphics scaler will be used.
596
597The framebuffer can be reconfigured with the bsurface routines, however the
598framebuffer will never be reallocated, thus any changes made to the framebuffer
599result in a framebuffer no larger than the one created by this routine.
600Therefore, if you plan to switch between 480i and 1080i, be sure to create a
6011080i-sized framebuffer at first.
602
603Unlike bsurface_create, the framebuffer will default to being visible.
604
605If back_buffer_count is not zero, 1 or 2 back buffers will also be created,
606although you will only get one bsurface_t handle. bsurface_get_memory will return
607information about the hidden surface. Call bgraphics_flip to hide one or more surfaces
608and show the other. The call bsurface_get_memory to get the information about the other
609surface.
610**/
611bsurface_t bgraphics_create_framebuffer(
612        bgraphics_t graphics,   /* handle returned by bgraphics_open */
613        const bsurface_create_settings *create_settings,
614        unsigned int back_buffer_count /* 0, 1 or 2 back buffers */
615        );
616
617/**
618Summary:
619        Creates a new, invisible surface using the create settings.
620Description:
621        After creating the surface, you can make it visible using get and set_settings.
622Example:
623        bsurface_create_settings create_settings;
624        bsurface_settings settings;
625        bsurface_t surface;
626
627        bsurface_init_create_settings(&create_settings);
628        create_settings.width = 100;
629        create_settings.height = 100;
630        surface = bsurface_create(g, &create_settings);
631        assert(surface);
632        bsurface_get(surface, &settings);
633        settings.visible = true;
634        bsurface_set(surface, &settings);
635**/
636bsurface_t bsurface_create(
637        bgraphics_t graphics,   /* handle returned by bgraphics_open */
638        const bsurface_create_settings *create_settings
639        );
640
641/**
642Summary:
643DEPRECATED: Please use bgraphics_create_framebuffer().
644**/
645bsurface_t bsurface_get_display(
646        bgraphics_t graphics,   /* handle returned by bgraphics_open */
647        const bsurface_create_settings *create_settings
648        );
649
650/**
651Summary:
652Destroy a surface.
653
654Description:
655Destroying a surface also hides it.
656
657It is invalid to destroy the surface return by bgraphics_create_framebuffer(), even on
658legacy architectures.
659**/
660void bsurface_destroy(
661        bsurface_t surface      /* handle returned by bsurface_create */
662        );
663
664/**
665Summary:
666        Returns information needed for direct memory writes.
667
668Description:
669        In order for direct memory writes to be successful, you must know the
670        format specified by bgraphics_pixel_format.
671        You cannot assume that pitch == width * sizeof(pixelformat).
672
673        You cannot cache the value of bsurface_memory->buffer. This value may
674        change if the surface is the display buffer and you're using double
675        buffering.
676
677        You should use bsurface_sync or bgraphics_sync when interleaving fill/blit/copy
678        commands with CPU writes to make your code resilient to asynchronous
679        operation.
680
681Example:
682        // example of using bsurface_memory's buffer and pitch to do a CPU-based fill
683        // fill entire 16 bits/pixel surface, using pitch and knowledge of pixel format
684        bsurface_settings settings;
685        bsurface_memory mem;
686        int bytes_per_pixel = 2;
687        bsurface_get(s1, &settings);
688        bsurface_get_memory(s1, &mem);
689        for (y=0;y<settings.height;y++)
690                for (x=0;x<settings.width;x++) {
691                        unsigned short *ptr = (unsigned short *)mem.buffer;
692                        ptr[y * mem.pitch/bits_per_pixel + x] = color;
693                }
694
695        // After calling flip, you must call bsurface_get_memory again.
696        bsurface_t fb = bgraphics_create_framebuffer(graphics, &cs, true);
697        ...
698        bsurface_get_memory(fb, &mem);
699        mem.buffer[10] = BLACK;
700        bgraphics_flip();
701        bsurface_get_memory(fb, &mem);
702        mem.buffer[10] = BLACK; // Correct. mem->buffer will be updated if necessary.
703**/
704bresult bsurface_get_memory(
705        bsurface_t s,
706        bsurface_memory *memory /* [out] */
707        );
708
709/*
710Summary:
711Settings for a surface returned by bsurface_get.
712Description:
713These settings control the appearance of a surface, including visibility,
714position, overlapping (zorder), transparency and palette.
715*/
716typedef struct bsurface_settings {
717        bsettop_rect position; /* Position and size of the surface.
718                position.width and height are readonly */
719        bsettop_rect cliprect; /* The area within the surface that should be shown,
720                relative to 0,0. If you want to show the entire surface, cliprect
721                should be 0,0,position.width,position.height. If you specify a cliprect
722                which is smaller, only that portition will be shown, and it will be
723                scaled to fit the rectangle of size position.width and .height. */
724        bool visible; /* Defaults to false. On magnum platforms, this causes a
725                surface to be automatically blitted to the framebuffer when bgraphics_sync
726                is called. On legacy platforms, this causes the surface to be blended into
727                the display by the compositor. */
728        unsigned zorder; /* 0 is on bottom. If two surfaces have the same zorder value,
729                their position relative to each other is undefined. You cannot rely on
730                creation order to provide an implicit zorder because the behavior may
731                change. */
732        uint8_t alpha; /* 0x00 to 0xFF where 0xFF is opaque and 0x00 is transparent.
733                On magnum platforms, this is only used when automatically blitting to
734                the framebuffer with bgraphics_sync. On legacy platforms, this controls
735                the alpha blending with the compositor. */
736        bgraphics_pixel color;  /* Constant color for any surface that doesn't have a
737                per-pixel color value (e.g. bgraphics_pixel_format_a0 or a8).
738                This should be used mutual exclusively with the palette member, if either
739                are to be used.*/
740        bgraphics_palette palette;      /* For legacy platforms, there is only one palette
741                for the entire graphics engine; therefore, the last palette set is the
742                global palette for all surfaces. On magnum platforms, each surface can
743                have its own palette. */
744        bool disable_automatic_cache_flush; /* By default, the settop api will assume that
745                every surface's cache must be flushed before performing a HW fill/blit.
746                This is only needed if the application is combining CPU writes with HW fill/blits.
747                If the app is not, this cache flush is wasteful. If you set this param
748                to true, no default cache flush will be performed. The app can call bsurface_sync
749                to manually flush the cache when needed. */
750} bsurface_settings;
751
752/**
753Summary:
754Apply bsurface_settings to a surface.
755
756Description:
757On magnum platforms, the bsurface_settings.alpha value is applied differently to the framebuffer
758and non-framebuffer surfaces. For the framebuffer, this alpha controls blending with
759video. For non-framebuffer surfaces, this alpha specifies the level of transparency
760when blitting the visible surface to the framebuffer. See bgraphics_sync for details on this process.
761**/
762bresult bsurface_set(
763        bsurface_t s,
764        const bsurface_settings *settings
765        );
766
767/*
768Summary:
769        Get the bsurface_settings for a surface.
770*/
771void bsurface_get(
772        bsurface_t s,
773        bsurface_settings *settings /* [out] */
774        );
775
776/**
777Summary:
778        Fill rectangle with pixel value.
779Description:
780        This operation may be asynchronous. You must call bgraphics_sync, or call
781        bsurface_set with visible == true in order to synchronize.
782        If you write directly to memory before synchronizing, the result is indeterminate.
783**/
784bresult bsurface_fill(
785        bsurface_t surface,             /* Surface to be filled */
786        const bsettop_rect *rect,       /* rectangle within the surface that will be filled.
787                                                                It will be clipped to the surface's visible area. */
788        bgraphics_pixel pixel /*
789                For non-palettized surfaces, this is a universal ARBG8888
790                value which will be used to fill the surface.
791                For YCrCb surfaces, the colorspace will be converted from ARGB8888
792                before the fill.
793                For palettized surfaces, this is the index value. */
794        );
795
796
797/**
798Summary:
799        Copy from a rectangle to another rectangle with possible scaling and
800        pixel format conversion.
801Description:
802        This operation may be asynchronous. You must call bgraphics_sync, or call
803        bsurface_set with visible == true in order to synchronize.
804        If you write directly to memory before synchronizing, the result is indeterminate.
805
806        If the size of the destrect and srcrect differ, the content will be scaled.
807
808        There is no alpha blending with this operation. If the dest has an alpha
809        channel, then it will be filled either with the src's alpha channel or with
810        0xFF (opaque).
811**/
812bresult bsurface_copy(
813        bsurface_t destsurface,         /* Destination surface to be copied into */
814        const bsettop_rect *destrect,    /* Rectangle in the destination surface where the
815                                                                        pixels will be copied. It will be clipped with
816                                                                        the visible area of the surface. */
817        bsurface_t srcsurface,          /* Source surface to be copied from */
818        const bsettop_rect *srcrect      /* Rectangle in the source surface where the
819                                                                        pixels will be copied from. It will be clipped with
820                                                                        the visible area of the surface. */
821        );
822
823/**
824BSURFACE_BLEND_XXXX are values to be used in the bsurface_blit operation
825parameter. You should chose one value.
826
827Alpha values are always relative to src1 and should be between 0x00 and 0xFF.
828Therefore alpha of 0xFF means take all of src1, none of src2.
829Likewise alpha of 0x00 means take none of src1, all of src2.
830
831There are some special cases which are enforced and optimized in the implementation.
832For instance, if you don't want to blend colors, you can set src2 to NULL,
833use BSURFACE_BLEND_WITH_SRC1_ALPHA, and set pixel1 == 0xFF, and the color blend
834will be bypassed. You can still use the BSURFACE_SET_DEST_ALPHA to manipulate
835the alpha-per-pixel.
836**/
837
838/* Use the pixel1 parameter to blend the sources. */
839#define BSURFACE_BLEND_WITH_PIXEL1                      0x0000
840/* Copy src1's alpha-per-pixel to blend the sources */
841#define BSURFACE_BLEND_WITH_SRC1_ALPHA          0x0001
842/* Copy src2's alpha-per-pixel to blend the sources */
843#define BSURFACE_BLEND_WITH_SRC2_ALPHA          0x0002
844/* Blend two palettized surfaces using colorkey to select per pixel */
845#define BSURFACE_SELECT_PALETTE_WITH_COLORKEY 0x0004
846/* Copy source (blend with one) */
847#define BSURFACE_BLEND_WITH_ONE                 0x0008
848
849/**
850BSURFACE_BLIT_DEST_ALPHA_XXX specifies how the alpha-per-pixel values of the dest
851surface should be filled. If the dest has no alpha-per-pixel, any setting is ignored.
852**/
853
854/* Copy the pixel2 parameter into the dest's alpha-per-pixel. */
855#define BSURFACE_SET_DEST_ALPHA_WITH_PIXEL2                     0x0000
856/* Copy src1's alpha channel into dest's alpha-per-pixel. */
857#define BSURFACE_SET_DEST_ALPHA_WITH_SRC1_ALPHA         0x0010
858/* Copy src2's alpha channel into dest's alpha-per-pixel. */
859#define BSURFACE_SET_DEST_ALPHA_WITH_SRC2_ALPHA         0x0020
860/* Blend src1's and src2's alpha-per-pixel into dest's alpha-per-pixel.
861The formula is dest = src1 + src2 * (1-src1). */
862#define BSURFACE_SET_DEST_ALPHA_WITH_AVG_ALPHA          0x0040
863/* Blend pixel2 parameter and src2's alpha-per-pixel into dest's alpha-per-pixel.
864The formula is dest = pixel2 + src2 * (1-pixel2). */
865#define BSURFACE_SET_DEST_ALPHA_WITH_AVG_ALPHA_PIXEL2   0x0080
866 /* Multiply src1's alpha-per-pixel with pixel2 parameter.
867The formula is dest = src1 * pixel2. */
868#define BSURFACE_SET_DEST_ALPHA_WITH_SRC1_TIMES_PIXEL2  0x0100
869
870/**
871Summary:
872Blit two surfaces together into a destination surface.
873
874Desription:
875Blit is a superset of copy. It gives you more control over how two surfaces
876will be blended together and how the destination surface's alpha-per-pixel (or
877alpha channel) will be populated if present.
878
879src1 or src2 can be the same as dest.
880
881If src2 is NULL, then you must use BSURFACE_BLEND_WITH_SRC1_ALPHA and
882have pixel1 of 0xFF. Anything else implies that you are blending between src1
883and src2, which cannot be done. Likewise for src1.
884
885If both src1 and src2 are null, then operation is ignored and pixel1 is regarded
886as a fill color.
887
888There are some operations that will internally result as a two-pass operation.
889This is hardware specific. In general, the Settop API will fulfill your request
890or return an error code if it cannot. Please see the implementation for more
891details.
892
893Scaling and clipping are specified by the proportion of the src1, src2 and
894dest rectangles. The entire src1_rect is combined with the entire src2_rect and
895the result is copied into the entire dest_rect. Some platforms have
896scaling limitations. For instance, on 7038 src2 cannot scale, therefore its
897width and height must match dest's.
898
899Example:
900        // bsurface_copy is equivalent to:
901        bsurface_blit(destsurface, destrect,
902                BSURFACE_BLEND_WITH_PIXEL1|BSURFACE_SET_DEST_ALPHA_WITH_SRC1_ALPHA,
903                src1, src1rect, NULL, NULL, 0xFF, 0xFF);
904
905        // blend two surfaces together using a constant alpha, and set
906        // the dest's alpha channel with a constant alpha
907        bsurface_blit(destsurface, destrect,
908                BSURFACE_BLEND_WITH_PIXEL1|BSURFACE_SET_DEST_ALPHA_WITH_PIXEL2,
909                src1, src1rect, src2, src2rect, 0xA0, 0xFF);
910
911        // blend two surfaces together using src1's alpha channel, and set
912        // the dest's alpha channel to be src1's alpha. The pixel1 and pixel2
913        // values are ignored.
914        bsurface_blit(destsurface, destrect,
915                BSURFACE_BLEND_WITH_SRC1_ALPHA|BSURFACE_SET_DEST_ALPHA_WITH_SRC1_ALPHA,
916                src1, src1rect, src2, src2rect, 0, 0);
917**/
918bresult bsurface_blit(
919        bsurface_t destsurface,                 /* Destination surface to be copied into */
920        const bsettop_rect *destrect,   /* Rectangle of destsurface that will be filled.
921                If NULL, use the whole destsurface. */
922        uint32_t operation,                             /* Combination of BSURFACE_BLEND_XXXX and
923                BSURFACE_SET_DEST_ALPHA_XXXX values.
924                The choice of operation determines the meaning of pixel1 and pixel2 parameters
925                and requirements for src1 and src2.
926                See documentation above. */
927        bsurface_t src1,                                /* 1st source surface to be copied from.
928                Can be NULL if not used. */
929        const bsettop_rect *src1_rect,  /* Rectangle of src1_surface to be used.
930                If NULL, use the whole src1 surface. */
931        bsurface_t src2,                                /* 2nd source surface to be copied from.
932                Can be NULL if not used. */
933        const bsettop_rect *src2_rect,  /* Rectangle of src2_surface to be used.
934                If NULL, use the whole src2 surface. */
935        bgraphics_pixel pixel1,                 /* 1st constant value specified by some operations */
936        bgraphics_pixel pixel2                  /* 2nd constant value specified by some operations */
937        );
938
939
940typedef struct bsurface_blit_params {
941    uint32_t operation;             /* Combination of BSURFACE_BLEND_XXXX and
942        BSURFACE_SET_DEST_ALPHA_XXXX values.
943        The choice of operation determines the meaning of pixel1 and pixel2 parameters
944        and requirements for src1 and src2.
945        See documentation above. */
946    bsurface_t src1;                /* 1st source surface to be copied from.
947                                       Can be NULL if not used. */
948    bsettop_rect src1_rect;    /* Rectangle of src1_surface to be used.
949                                  If width == height == 0 (default), use
950                                  the whole src1 surface. */
951    bsurface_t src2;                /* 2nd source surface to be copied from.
952                                       Can be NULL if not used. */
953    bsettop_rect src2_rect;    /* Rectangle of src2_surface to be used.
954                                  If width == height == 0 (default), use
955                                  the whole src2 surface. */
956    bgraphics_pixel pixel1;    /* 1st constant value specified by some operations */
957    bgraphics_pixel pixel2;    /* 2nd constant value specified by some operations */
958    int16_t brightness;  /* Color space conversion for the surface (not the GFD).
959                            Ranges between -32768 and 32767. Default is 0. */
960    int16_t contrast;       /* Color space conversion for the surface (not the GFD).
961                            Ranges between -32768 and 32767. Default is 0. */
962    int16_t saturation; /* Color space conversion for the surface (not the GFD).
963                            Ranges between -32768 and 32767. Default is 0. */
964    int16_t hue;            /* Color space conversion for the surface (not the GFD).
965                            Ranges between -32768 and 32767. Default is 0. */
966
967    bool src1_right_to_left;    /* If true, src1 will be inverted horizontally during blit */
968    bool src1_bottom_to_top;    /* If true, src1 will be inverted vertically during blit */
969    bool src2_right_to_left;    /* If true, src2 will be inverted horizontally during blit */
970    bool src2_bottom_to_top;    /* If true, src2 will be inverted vertically during blit */
971} bsurface_blit_params;
972
973
974void bsurface_blit_params_init(bsurface_blit_params *params);
975
976bresult bsurface_extended_blit(
977        bsurface_t destsurface,
978        const bsettop_rect *destrect,
979        const bsurface_blit_params *params
980        );
981
982
983
984/**
985BSURFACE_FILL_XXXX are values to be used in the bsurface_blended_fill operation
986
987**/
988
989/* pick one of the following color operations: */
990/* Blend fill color with destsurface using fillcolor alpha */
991#define BSURFACE_FILL_BLEND_WITH_PIXEL_ALPHA        0x0000
992/* Do not blend the color. Simply copy the color to the surface. This is equivalent to bsurface_fill().
993Other BSURFACE_FILL operations are ignored. */
994#define BSURFACE_FILL_COPY_COLOR                    0x0001
995/* Do not change the color. This is used if you want to change the alpha channel only. */
996#define BSURFACE_FILL_BLEND_DONT_CHANGE_COLOR       0x0002
997
998/* pick one of the following alpha operations: */
999/* set destsurface alpha channel with fill color alpha */
1000#define BSURFACE_FILL_SET_ALPHA_WITH_PIXEL_ALPHA    0x0000
1001/* leave destsurface alpha channel unchanged */
1002#define BSURFACE_FILL_DONT_CHANGE_ALPHA             0x0010
1003/* set destsurface alpha channel with average of destsurface and fill color */
1004#define BSURFACE_FILL_SET_ALPHA_WITH_AVG_ALPHA      0x0020
1005
1006/**
1007Summary:
1008        Blend Fill rectangle with pixel value.
1009Description:
1010        This operation may be asynchronous. You must call bgraphics_sync, or call
1011        bsurface_set with visible == true in order to synchronize.
1012        If you write directly to memory before synchronizing, the result is indeterminate.
1013**/
1014bresult
1015bsurface_blended_fill(
1016        bsurface_t surface,         /* Surface to be filled */
1017        const bsettop_rect *rect,   /* rectangle within the surface that will be filled.
1018                                                                It will be clipped to the surface's visible area. */
1019        bgraphics_pixel pixel,      /*
1020                For non-palettized surfaces, this is a universal ARBG8888
1021                value which will be used to fill the surface.
1022                For YCrCb surfaces, the colorspace will be converted from ARGB8888
1023                before the fill.
1024                For palettized surfaces, this is the index value. */
1025        uint32_t operation         /* gfx operation to perform, eg, simple fill or blend with specified pixel color.
1026                                  see BSURFACE_FILL_BLEND_XXXX above for options. */
1027
1028        );
1029
1030/**
1031Summary:
1032Load a CLUT for palettized surfaces.
1033
1034Description:
1035CLUT means "color look up table" which means the same as "palette."
1036
1037The palette memory is copied. The number of entries in the palette can be any amount,
1038however it may be truncated based on the number of palette entries required for
1039the pixel format.
1040
1041For legacy devices there can be only one clut per graphics devices. So changing
1042the palette for one palettized surface will affect all the other palettized surfaces
1043in the same graphics device.
1044
1045For magnum platforms, each surface has a separate palette.
1046**/
1047bresult bsurface_load_clut(
1048        bsurface_t s,
1049        bgraphics_palette palette);
1050
1051#ifdef __cplusplus
1052}
1053#endif
1054
1055#endif /* BSETTOP_GRAPHICS_H__ */
1056
Note: See TracBrowser for help on using the repository browser.