Draw context for a graphics driver
#include <draw.h>
typedef struct disp_draw_context {
int size;
disp_adapter_t *adapter;
void *gd_ctx;
struct disp_draw_corefuncs *cfuncs;
unsigned flags;
disp_color_t fgcolor;
disp_color_t bgcolor;
uint8_t *pat;
unsigned short pat_xoff;
unsigned short pat_yoff;
unsigned short pattern_format;
unsigned short rop3;
unsigned short chroma_mode;
disp_color_t chroma_color0;
disp_color_t chroma_color1;
disp_color_t chroma_mask;
unsigned alpha_mode;
unsigned s_alpha;
unsigned d_alpha;
unsigned alpha_map_width;
unsigned alpha_map_height;
unsigned alpha_map_xoff;
unsigned alpha_map_yoff;
unsigned char *alpha_map;
disp_surface_t *dsurf
char *sysram_workspace;
int sysram_workspace_size;
} disp_draw_context_t;
The disp_draw_context_t structure defines the graphics
driver's draw context.
The graphics framework passes this structure to of all the 2D drawing entry
points.
The members include:
- size
- The size of the structure, in bytes.
- adapter
- A pointer to the
disp_adapter_t
structure.
- gd_ctx
- The 2D module's private context structure.
- cfuncs
- A pointer to the
disp_draw_corefuncs_t
structure that lists the core functions for rendering into the currently
targeted draw surface.
This surface is of the type specified by the dsurf structure's
pixel_format member.
- flags
- Flags that indicate what kind of operations should be performed in all
subsequent "context draw" functions.
Selected from one or more of the following (bitmap):
- DISP_DRAW_FLAG_SIMPLE_ROP
- DISP_DRAW_FLAG_COMPLEX_ROP
- DISP_DRAW_FLAG_USE_ALPHA
- DISP_DRAW_FLAG_USE_CHROMA
- DISP_DRAW_FLAG_MONO_PATTERN
- DISP_DRAW_FLAG_TRANS_PATTERN
- fgcolor
- The foreground color.
- bgcolor
- The background color.
- pat
- Pattern buffer; see the description in
"Patterns"
(in the
"Conventions"
section of the Writing a Graphics Driver chapter), as well as the
context functions
draw_rect_pat8x8(),
and
draw_rect_trans8x8().
- pat_xoff, pat_yoff
- Horizontal and vertical offsets for the pattern to cause it to be shifted.
For more information, see
"Patterns"
in the Writing a Graphics Driver chapter.
- pattern_format
- One of DISP_PATTERN_FORMAT_MONO_8x1 or
DISP_PATTERN_FORMAT_MONO_8x8 (from draw.h).
- rop3
- Bitmapped raster operations, range between 0 and 255 inclusive.
See the memcpy_x.c file in the flat framebuffer library
source for a sample implementation.
- chroma_mode
- Selected from the following, see
"Chroma mode bits,"
below:
either DISP_CHROMA_OP_SRC_MATCH or
DISP_CHROMA_OP_DST_MATCH, and/or
either DISP_CHROMA_OP_DRAW or
DISP_CHROMA_OP_NO_DRAW.
(In other words, SRC and DST are mutually
exclusive, as are DRAW and NO_DRAW.)
- chroma_color0
- The chroma key; indicates the color to test on.
- chroma_color1, chroma_mask
- Reserved; don't examine or modify.
- alpha_mode
- A bitmask indicating alpha blending operations, see
"Alpha mode bits,"
below.
For unrecognized alpha operations, call the supplied flat frame buffer
functions.
- s_alpha
- The source alpha blending factor. For layers' blending
configurations, multiplier 1, (M1),
is the global alpha multiplier equivalent to s_alpha.
- d_alpha
- The destination alpha blending factor. For layers' blending
configuration, multiplier 2 M2,
is the global alpha multiplier equivalent to d_alpha.
- alpha_map_width, alpha_map_height
- The width and height of the alpha map (below) in pixels.
- alpha_map_xoff, alpha_map_yoff
- The X and Y offset of the alpha map (below).
See the discussion above in
"Patterns"
for more information.
- alpha_map
- The alpha mapping grid, whose size is determined by
alpha_map_width and alpha_map_height (above).
Each element of the map is one byte, corresponding to one pixel.
If this member is NULL, there's no alpha map.
The stride here is equal to the width, i.e. one byte per element.
- dsurf
- A pointer to a
disp_surface_t
structure that contains the definition of the currently targeted draw
surface.
All draw operations target this surface by default, unless parameters to the
draw function explicitly override this.
- sysram_workspace
- A "scratch" area that the 2D driver and FFB library routines
may use for temporary storage.
- sysram_workspace_size
- The size of the workspace, in bytes.
If the driver wishes, it may reallocate the workspace in order to increase
its size.
This member should be updated to reflect the change in size.
The driver should never decrease the size of the workspace.
When using an alpha map, blending factors come from the alpha_map,
and not from the s_alpha or d_alpha members.
The following bits apply to the chroma mode flag mode,
which performs a per-pixel test:
- DISP_CHROMA_OP_SRC_MATCH
- Perform match on source image.
- DISP_CHROMA_OP_DST_MATCH
- Perform match on destination image.
- DISP_CHROMA_OP_DRAW
- If match, draw pixel.
- DISP_CHROMA_OP_NO_DRAW
- If match, don't draw pixel.
Note that DISP_CHROMA_OP_SRC_MATCH and
DISP_CHROMA_OP_DST_MATCH are mutually exclusive,
as are DISP_CHROMA_OP_DRAW and
DISP_CHROMA_OP_NO_DRAW.
The (Group 1) alpha modes are:
- DISP_ALPHA_M1_SRC_PIXEL_ALPHA
- Use the M1 multiplier for the Alpha component of the source
pixels.
- DISP_ALPHA_M1_DST_PIXEL_ALPHA
- Use the M1 multiplier for the Alpha component of the
destination pixels.
- DISP_ALPHA_M1_GLOBAL
- Use global blend factor from the M1multiplier.
The (Group 2) alpha modes are:
- DISP_ALPHA_M2_SRC_PIXEL_ALPHA
- Use the M2 multiplier for the Alpha component of the source pixels.
- DISP_ALPHA_M2_DST_PIXEL_ALPHA
- Use the M2 multiplier for the Alpha component of the destination pixels.
- DISP_ALPHA_M2_GLOBAL
- Use global destination blend factor from the M2 multiplier.
The (Group 3) alpha_mode source operations are:
- DISP_BLEND_SRC_M1_ALPHA
- Ms = M1
- DISP_BLEND_SRC_ONE_MINUS_M1_ALPHA
- Ms = 1 -M1
- DISP_BLEND_SRC_M2_ALPHA
- Ms = M2
- DISP_BLEND_SRC_ONE_MINUS_M2_ALPHA
- Ms = 1 - M2
The (Group 4) alpha_mode destination operations are:
- DISP_BLEND_DST_M1_ALPHA
- Md =M1
- DISP_BLEND_DST_ONE_MINUS_M1_ALPHA
- Md = 1 -M1
- DISP_BLEND_DST_M2_ALPHA
- Md = M2
- DISP_BLEND_DST_ONE_MINUS_M2_ALPHA
- Md = 1 -M2
|
For each pixel, the value of the blended pixel
is derived by combining the source and the destination pixels
with the multipliers, as shown in the following equation:
Pd = Ps * Ms + Pd * Md, where
Pd is the destination pixel value, and Ps
is the source pixel value. |
Photon
disp_adapter_t,
disp_draw_corefuncs_t,
disp_surface_t