| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2012, 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: $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | ***************************************************************************/ |
|---|
| 21 | |
|---|
| 22 | #include "nexus_surface.h" |
|---|
| 23 | #include "nexus_graphics2d.h" |
|---|
| 24 | #include "nexus_display.h" |
|---|
| 25 | #include "nexus_platform.h" |
|---|
| 26 | #include "nexus_core_utils.h" |
|---|
| 27 | |
|---|
| 28 | #include "bstd.h" |
|---|
| 29 | #include "bkni.h" |
|---|
| 30 | #include "bsettop_display.h" |
|---|
| 31 | #include "bsettop_graphics.h" |
|---|
| 32 | #include "bsettop_display_n_priv.h" |
|---|
| 33 | |
|---|
| 34 | BDBG_MODULE(bgraphics); |
|---|
| 35 | |
|---|
| 36 | struct bgraphics |
|---|
| 37 | { |
|---|
| 38 | NEXUS_Graphics2DHandle gfx; |
|---|
| 39 | NEXUS_SurfaceHandle offscreen; |
|---|
| 40 | NEXUS_SurfaceHandle back; |
|---|
| 41 | NEXUS_SurfaceHandle overlay; |
|---|
| 42 | NEXUS_SurfaceHandle osd[2]; /* frame buffer */ |
|---|
| 43 | NEXUS_SurfaceMemory mem[2]; |
|---|
| 44 | NEXUS_SurfaceMemory off_mem; |
|---|
| 45 | NEXUS_SurfaceMemory overlay_mem; |
|---|
| 46 | BKNI_EventHandle event; |
|---|
| 47 | |
|---|
| 48 | NEXUS_DisplayHandle display[eBDISPLAY_ID_MAX]; |
|---|
| 49 | NEXUS_VideoFormat osd_format; |
|---|
| 50 | |
|---|
| 51 | struct bsettop_surf surf_off; |
|---|
| 52 | struct bsettop_surf surf_overlay; |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | struct bgraphics s_graphics; |
|---|
| 56 | NEXUS_DisplayHandle bdisplay_p_get_handle(bdisplay_t disp, int id); |
|---|
| 57 | void bgraphics_checkpoint(void); |
|---|
| 58 | |
|---|
| 59 | static void bgraphics_complete(void *data, int unused) |
|---|
| 60 | { |
|---|
| 61 | BSTD_UNUSED(unused); |
|---|
| 62 | BKNI_SetEvent((BKNI_EventHandle)data); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | bgraphics_t bgraphics_open(int id, bdisplay_t p_disp) |
|---|
| 67 | { |
|---|
| 68 | NEXUS_SurfaceCreateSettings createSettings; |
|---|
| 69 | NEXUS_SurfaceMemory mem; |
|---|
| 70 | NEXUS_Graphics2DOpenSettings openSettings; |
|---|
| 71 | NEXUS_Graphics2DSettings gfxSettings; |
|---|
| 72 | NEXUS_GraphicsSettings graphicsSettings; |
|---|
| 73 | NEXUS_VideoFormatInfo oinfo, vinfo; |
|---|
| 74 | NEXUS_DisplaySettings dsettings; |
|---|
| 75 | int i; |
|---|
| 76 | |
|---|
| 77 | BSTD_UNUSED(id); |
|---|
| 78 | BKNI_Memset(&s_graphics, 0, sizeof(s_graphics)); |
|---|
| 79 | s_graphics.osd_format = NEXUS_VideoFormat_eNtsc; |
|---|
| 80 | NEXUS_VideoFormat_GetInfo(s_graphics.osd_format, &oinfo); |
|---|
| 81 | |
|---|
| 82 | for (i=0; i<eBDISPLAY_ID_MAX; i++) |
|---|
| 83 | s_graphics.display[i] = bdisplay_p_get_handle(p_disp, i); |
|---|
| 84 | |
|---|
| 85 | NEXUS_Display_GetSettings(s_graphics.display[eBDISPLAY_HDMI], &dsettings); |
|---|
| 86 | |
|---|
| 87 | BKNI_CreateEvent(&s_graphics.event); |
|---|
| 88 | NEXUS_Surface_GetDefaultCreateSettings(&createSettings); |
|---|
| 89 | createSettings.pixelFormat = NEXUS_PixelFormat_eA8_R8_G8_B8; |
|---|
| 90 | createSettings.width = oinfo.digitalWidth; |
|---|
| 91 | createSettings.height = oinfo.digitalHeight; |
|---|
| 92 | createSettings.heap = NEXUS_Platform_GetFramebufferHeap(0); |
|---|
| 93 | s_graphics.offscreen = NEXUS_Surface_Create(&createSettings); |
|---|
| 94 | NEXUS_Surface_GetMemory(s_graphics.offscreen, &s_graphics.off_mem); |
|---|
| 95 | BKNI_Memset(s_graphics.off_mem.buffer, 0, createSettings.height*s_graphics.off_mem.pitch); |
|---|
| 96 | |
|---|
| 97 | s_graphics.overlay = NEXUS_Surface_Create(&createSettings); |
|---|
| 98 | NEXUS_Surface_GetMemory(s_graphics.overlay, &s_graphics.overlay_mem); |
|---|
| 99 | BKNI_Memset(s_graphics.overlay_mem.buffer, 0, createSettings.height*s_graphics.overlay_mem.pitch); |
|---|
| 100 | |
|---|
| 101 | s_graphics.osd[eBDISPLAY_HDMI] = NEXUS_Surface_Create(&createSettings); |
|---|
| 102 | NEXUS_Surface_GetMemory(s_graphics.osd[eBDISPLAY_HDMI], &s_graphics.mem[0]); |
|---|
| 103 | BKNI_Memset(s_graphics.mem[0].buffer, 0, createSettings.height*s_graphics.mem[0].pitch); |
|---|
| 104 | |
|---|
| 105 | s_graphics.back = NEXUS_Surface_Create(&createSettings); |
|---|
| 106 | NEXUS_Surface_GetMemory(s_graphics.back, &mem); |
|---|
| 107 | BKNI_Memset(mem.buffer, 0x0, createSettings.height*mem.pitch); |
|---|
| 108 | |
|---|
| 109 | createSettings.pixelFormat = NEXUS_PixelFormat_eA8_Y8_Cb8_Cr8; |
|---|
| 110 | s_graphics.osd[eBDISPLAY_COMPOSITE] = NEXUS_Surface_Create(&createSettings); |
|---|
| 111 | NEXUS_Surface_GetMemory(s_graphics.osd[eBDISPLAY_COMPOSITE], &s_graphics.mem[1]); |
|---|
| 112 | BKNI_Memset(s_graphics.mem[1].buffer, 0x0, createSettings.height*s_graphics.mem[1].pitch); |
|---|
| 113 | |
|---|
| 114 | NEXUS_Graphics2D_GetDefaultOpenSettings(&openSettings); |
|---|
| 115 | openSettings.hwFifoSize = 300*1024; |
|---|
| 116 | openSettings.packetFifoSize = 500*1024; |
|---|
| 117 | openSettings.packetFifoThreshold = openSettings.packetFifoSize; |
|---|
| 118 | s_graphics.gfx = NEXUS_Graphics2D_Open(0, &openSettings); |
|---|
| 119 | |
|---|
| 120 | NEXUS_Graphics2D_GetSettings(s_graphics.gfx, &gfxSettings); |
|---|
| 121 | gfxSettings.checkpointCallback.callback = bgraphics_complete; |
|---|
| 122 | gfxSettings.checkpointCallback.context = s_graphics.event; |
|---|
| 123 | NEXUS_Graphics2D_SetSettings(s_graphics.gfx, &gfxSettings); |
|---|
| 124 | |
|---|
| 125 | NEXUS_VideoFormat_GetInfo(dsettings.format, &vinfo); |
|---|
| 126 | NEXUS_Display_GetGraphicsSettings(s_graphics.display[eBDISPLAY_HDMI], &graphicsSettings); |
|---|
| 127 | graphicsSettings.enabled = true; |
|---|
| 128 | graphicsSettings.zorder = 2; |
|---|
| 129 | graphicsSettings.position.width = vinfo.digitalWidth; |
|---|
| 130 | graphicsSettings.position.height = vinfo.digitalHeight; |
|---|
| 131 | graphicsSettings.clip.width = oinfo.digitalWidth; |
|---|
| 132 | graphicsSettings.clip.height = oinfo.digitalHeight; |
|---|
| 133 | NEXUS_Display_SetGraphicsSettings(s_graphics.display[eBDISPLAY_HDMI], &graphicsSettings); |
|---|
| 134 | |
|---|
| 135 | NEXUS_Display_GetGraphicsSettings(s_graphics.display[eBDISPLAY_COMPOSITE], &graphicsSettings); |
|---|
| 136 | graphicsSettings.enabled = true; |
|---|
| 137 | NEXUS_Display_SetGraphicsSettings(s_graphics.display[eBDISPLAY_COMPOSITE], &graphicsSettings); |
|---|
| 138 | |
|---|
| 139 | NEXUS_Display_SetGraphicsFramebuffer(s_graphics.display[eBDISPLAY_HDMI], s_graphics.osd[eBDISPLAY_HDMI]); |
|---|
| 140 | NEXUS_Display_SetGraphicsFramebuffer(s_graphics.display[eBDISPLAY_COMPOSITE], s_graphics.osd[eBDISPLAY_COMPOSITE]); |
|---|
| 141 | |
|---|
| 142 | s_graphics.surf_off.hSurface = s_graphics.offscreen; |
|---|
| 143 | s_graphics.surf_overlay.hSurface = s_graphics.overlay; |
|---|
| 144 | return &s_graphics; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | NEXUS_Graphics2DColorMatrix s_matrix_RGBtoYCbCr = |
|---|
| 148 | { |
|---|
| 149 | 8, |
|---|
| 150 | { |
|---|
| 151 | (int32_t) ( 0.183f * (1 << 8)), /* R factor for Y */ |
|---|
| 152 | (int32_t) ( 0.614f * (1 << 8)), /* G factor for Y */ |
|---|
| 153 | (int32_t) ( 0.062f * (1 << 8)), /* B factor for Y */ |
|---|
| 154 | (int32_t) 0, /* A factor for Y */ |
|---|
| 155 | (int32_t) (16 * (1 << 8)), /* Increment for Y */ |
|---|
| 156 | (int32_t) (-0.101f * (1 << 8)), /* R factor for Cb */ |
|---|
| 157 | (int32_t) (-0.339f * (1 << 8)), /* G factor for Cb */ |
|---|
| 158 | (int32_t) ( 0.439f * (1 << 8)), /* B factor for Cb */ |
|---|
| 159 | (int32_t) 0, /* A factor for Cb */ |
|---|
| 160 | (int32_t) (128 * (1 << 8)), /* Increment for Cb */ |
|---|
| 161 | (int32_t) ( 0.439f * (1 << 8)), /* R factor for Cr */ |
|---|
| 162 | (int32_t) (-0.339f * (1 << 8)), /* G factor for Cr */ |
|---|
| 163 | (int32_t) (-0.040f * (1 << 8)), /* B factor for Cr */ |
|---|
| 164 | (int32_t) 0, /* A factor for Cr */ |
|---|
| 165 | (int32_t) (128 * (1 << 8)), /* Increment for Cr */ |
|---|
| 166 | (int32_t) 0, /* R factor for A */ |
|---|
| 167 | (int32_t) 0, /* G factor for A */ |
|---|
| 168 | (int32_t) 0, /* B factor for A */ |
|---|
| 169 | (int32_t) (1 << 8), /* A factor for A */ |
|---|
| 170 | (int32_t) 0, /* Increment for A */ |
|---|
| 171 | } |
|---|
| 172 | }; |
|---|
| 173 | |
|---|
| 174 | void bgraphics_close(bgraphics_t graphics) |
|---|
| 175 | { |
|---|
| 176 | BSTD_UNUSED(graphics); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | NEXUS_SurfaceHandle bsurface_get_offscreen_surface(void) |
|---|
| 180 | { |
|---|
| 181 | return s_graphics.offscreen; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | NEXUS_SurfaceHandle bsurface_get_overlay_surface(void) |
|---|
| 185 | { |
|---|
| 186 | return s_graphics.overlay; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | NEXUS_Graphics2DHandle bgraphics_get_gfx(void) |
|---|
| 190 | { |
|---|
| 191 | return s_graphics.gfx; |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | bresult bgraphics_osd_flush(bgraphics_t graphics, bgraphics_id id, bool overlay) |
|---|
| 195 | { |
|---|
| 196 | NEXUS_Graphics2DBlitSettings blitSettings; |
|---|
| 197 | if (id & eGRAPHICS_HD) { |
|---|
| 198 | NEXUS_Graphics2D_GetDefaultBlitSettings(&blitSettings); |
|---|
| 199 | blitSettings.output.surface = graphics->osd[eBDISPLAY_HDMI]; |
|---|
| 200 | blitSettings.output.rect.width = 720; |
|---|
| 201 | blitSettings.output.rect.height = 480; |
|---|
| 202 | if (!overlay) { |
|---|
| 203 | blitSettings.source.surface = graphics->offscreen; |
|---|
| 204 | blitSettings.source.rect = blitSettings.output.rect; |
|---|
| 205 | blitSettings.colorOp = NEXUS_BlitColorOp_eCopySource; |
|---|
| 206 | blitSettings.alphaOp = NEXUS_BlitAlphaOp_eCopySource; |
|---|
| 207 | } |
|---|
| 208 | else { |
|---|
| 209 | blitSettings.source.surface = graphics->overlay; |
|---|
| 210 | blitSettings.source.rect = blitSettings.output.rect; |
|---|
| 211 | blitSettings.dest.surface = graphics->offscreen; |
|---|
| 212 | blitSettings.dest.rect = blitSettings.source.rect; |
|---|
| 213 | blitSettings.alphaOp = NEXUS_BlitAlphaOp_eCombine; |
|---|
| 214 | blitSettings.colorOp = NEXUS_BlitColorOp_eUseSourceAlpha; |
|---|
| 215 | } |
|---|
| 216 | NEXUS_FlushCache(graphics->off_mem.buffer, 2880*480); |
|---|
| 217 | NEXUS_FlushCache(graphics->mem[0].buffer, 2880*480); |
|---|
| 218 | NEXUS_Graphics2D_Blit(graphics->gfx, &blitSettings); |
|---|
| 219 | } |
|---|
| 220 | if (id & eGRAPHICS_SD) { |
|---|
| 221 | NEXUS_Graphics2D_GetDefaultBlitSettings(&blitSettings); |
|---|
| 222 | if (!overlay) { |
|---|
| 223 | blitSettings.output.surface = graphics->osd[eBDISPLAY_COMPOSITE]; |
|---|
| 224 | blitSettings.output.rect.width = 720; |
|---|
| 225 | blitSettings.output.rect.height = 480; |
|---|
| 226 | blitSettings.source.surface = graphics->offscreen; |
|---|
| 227 | blitSettings.source.rect = blitSettings.output.rect; |
|---|
| 228 | blitSettings.conversionMatrixEnabled = true; |
|---|
| 229 | blitSettings.conversionMatrix = s_matrix_RGBtoYCbCr; |
|---|
| 230 | blitSettings.colorOp = NEXUS_BlitColorOp_eCopySource; |
|---|
| 231 | blitSettings.alphaOp = NEXUS_BlitAlphaOp_eCopySource; |
|---|
| 232 | NEXUS_FlushCache(graphics->mem[1].buffer, 2880*480); |
|---|
| 233 | NEXUS_Graphics2D_Blit(graphics->gfx, &blitSettings); |
|---|
| 234 | } |
|---|
| 235 | else { |
|---|
| 236 | blitSettings.source.surface = graphics->overlay; |
|---|
| 237 | blitSettings.dest.surface = graphics->offscreen; |
|---|
| 238 | blitSettings.output.surface = graphics->back; |
|---|
| 239 | |
|---|
| 240 | blitSettings.source.rect.width = 720; |
|---|
| 241 | blitSettings.source.rect.height = 480; |
|---|
| 242 | blitSettings.dest.rect = blitSettings.source.rect; |
|---|
| 243 | blitSettings.output.rect = blitSettings.source.rect; |
|---|
| 244 | blitSettings.colorOp = NEXUS_BlitColorOp_eUseSourceAlpha; |
|---|
| 245 | blitSettings.alphaOp = NEXUS_BlitAlphaOp_eCombine; |
|---|
| 246 | NEXUS_FlushCache(graphics->mem[1].buffer, 2880*480); |
|---|
| 247 | NEXUS_Graphics2D_Blit(graphics->gfx, &blitSettings); |
|---|
| 248 | |
|---|
| 249 | blitSettings.source.surface = graphics->back; |
|---|
| 250 | blitSettings.dest.surface = NULL; |
|---|
| 251 | blitSettings.output.surface = graphics->osd[eBDISPLAY_COMPOSITE]; |
|---|
| 252 | blitSettings.colorOp = NEXUS_BlitColorOp_eCopySource; |
|---|
| 253 | blitSettings.alphaOp = NEXUS_BlitAlphaOp_eCopySource; |
|---|
| 254 | blitSettings.conversionMatrixEnabled = true; |
|---|
| 255 | blitSettings.conversionMatrix = s_matrix_RGBtoYCbCr; |
|---|
| 256 | NEXUS_Graphics2D_Blit(graphics->gfx, &blitSettings); |
|---|
| 257 | } |
|---|
| 258 | } |
|---|
| 259 | bgraphics_checkpoint(); |
|---|
| 260 | return 0; |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | bresult bgraphics_sync(bgraphics_t graphics, bool overlay) |
|---|
| 264 | { |
|---|
| 265 | return bgraphics_osd_flush(graphics, eGRAPHICS_BOTH, overlay); |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | bresult bgraphics_sync_partial(bgraphics_t graphics, bgraphics_id id, bool overlay) |
|---|
| 269 | { |
|---|
| 270 | if (!(id&eGRAPHICS_BOTH)) |
|---|
| 271 | id = eGRAPHICS_BOTH; |
|---|
| 272 | |
|---|
| 273 | return bgraphics_osd_flush(graphics, id, overlay); |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | void bgraphics_checkpoint(void) |
|---|
| 277 | { |
|---|
| 278 | NEXUS_Error rc ; |
|---|
| 279 | rc = NEXUS_Graphics2D_Checkpoint(s_graphics.gfx, NULL); |
|---|
| 280 | if (rc == NEXUS_GRAPHICS2D_QUEUED) { |
|---|
| 281 | BKNI_WaitForEvent(s_graphics.event, 0xFFFFFFFF); |
|---|
| 282 | } |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | bresult bgraphics_p_format_change(NEXUS_DisplayHandle display, int id) |
|---|
| 286 | { |
|---|
| 287 | NEXUS_DisplaySettings dsettings; |
|---|
| 288 | NEXUS_GraphicsSettings gsettings; |
|---|
| 289 | |
|---|
| 290 | NEXUS_VideoFormatInfo vinfo, oinfo; |
|---|
| 291 | |
|---|
| 292 | NEXUS_Display_GetSettings(display, &dsettings); |
|---|
| 293 | NEXUS_VideoFormat_GetInfo(dsettings.format, &vinfo); |
|---|
| 294 | NEXUS_VideoFormat_GetInfo(s_graphics.osd_format, &oinfo); |
|---|
| 295 | NEXUS_Display_GetGraphicsSettings(display, &gsettings); |
|---|
| 296 | gsettings.position.width = vinfo.digitalWidth; |
|---|
| 297 | gsettings.position.height = vinfo.digitalHeight; |
|---|
| 298 | gsettings.clip.width = oinfo.digitalWidth; |
|---|
| 299 | gsettings.clip.height = oinfo.digitalHeight; |
|---|
| 300 | NEXUS_Display_SetGraphicsSettings(display, &gsettings); |
|---|
| 301 | NEXUS_Display_SetGraphicsFramebuffer(display, s_graphics.osd[id]); |
|---|
| 302 | |
|---|
| 303 | return b_ok; |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | void bgraphics_get(bgraphics_settings *settings) |
|---|
| 307 | { |
|---|
| 308 | BSTD_UNUSED(settings); |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | bresult bgraphics_get_osd_params(bgraphics_t graphics, |
|---|
| 312 | bsettop_surf_t *p_osd_surf, |
|---|
| 313 | void **osd_buffer, |
|---|
| 314 | bsettop_surf_t *p_overlay_surf, |
|---|
| 315 | void **overlay_mem) |
|---|
| 316 | { |
|---|
| 317 | if (p_osd_surf && osd_buffer) { |
|---|
| 318 | *p_osd_surf = &graphics->surf_off; |
|---|
| 319 | *osd_buffer = graphics->off_mem.buffer; |
|---|
| 320 | } |
|---|
| 321 | if (p_overlay_surf && overlay_mem) { |
|---|
| 322 | *p_overlay_surf = &graphics->surf_overlay; |
|---|
| 323 | *overlay_mem = graphics->overlay_mem.buffer; |
|---|
| 324 | } |
|---|
| 325 | return b_ok; |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | bresult bgraphics_set(const bgraphics_settings *settings) |
|---|
| 330 | { |
|---|
| 331 | BSTD_UNUSED(settings); |
|---|
| 332 | return b_ok; |
|---|
| 333 | } |
|---|
| 334 | |
|---|
| 335 | bresult bgraphics_get_framebuffer(bgraphics_t graphics, |
|---|
| 336 | void **buffer, |
|---|
| 337 | unsigned int **palette, |
|---|
| 338 | int *width, |
|---|
| 339 | int *height, |
|---|
| 340 | int *pitch) |
|---|
| 341 | { |
|---|
| 342 | NEXUS_VideoFormatInfo oinfo; |
|---|
| 343 | |
|---|
| 344 | NEXUS_VideoFormat_GetInfo(graphics->osd_format, &oinfo); |
|---|
| 345 | |
|---|
| 346 | *buffer = graphics->off_mem.buffer; |
|---|
| 347 | *pitch = graphics->off_mem.pitch; |
|---|
| 348 | *width = oinfo.digitalWidth; |
|---|
| 349 | *height = oinfo.digitalHeight; |
|---|
| 350 | *palette = NULL; |
|---|
| 351 | return b_ok; |
|---|
| 352 | } |
|---|
| 353 | |
|---|
| 354 | bresult bgraphics_load_palette(bgraphics_t graphics) |
|---|
| 355 | { |
|---|
| 356 | BSTD_UNUSED(graphics); |
|---|
| 357 | return b_ok; |
|---|
| 358 | } |
|---|
| 359 | |
|---|
| 360 | bresult bgraphics_get_overlay(bgraphics_t graphics, void **buffer) |
|---|
| 361 | { |
|---|
| 362 | NEXUS_SurfaceMemory mem; |
|---|
| 363 | |
|---|
| 364 | NEXUS_Surface_GetMemory(graphics->overlay, &mem); |
|---|
| 365 | *buffer = mem.buffer; |
|---|
| 366 | return b_ok; |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | bresult bsurface_fill(bsettop_surf_t surface, bsettop_rect *rect, bgraphics_pixel pixel) |
|---|
| 370 | { |
|---|
| 371 | NEXUS_Graphics2DFillSettings fillSettings; |
|---|
| 372 | NEXUS_Graphics2D_GetDefaultFillSettings(&fillSettings); |
|---|
| 373 | fillSettings.surface = surface->hSurface; |
|---|
| 374 | fillSettings.rect.x = rect->x; |
|---|
| 375 | fillSettings.rect.y = rect->y; |
|---|
| 376 | fillSettings.rect.width = rect->width; |
|---|
| 377 | fillSettings.rect.height = rect->height; |
|---|
| 378 | fillSettings.color = pixel; |
|---|
| 379 | fillSettings.colorOp = NEXUS_FillOp_eCopy; |
|---|
| 380 | fillSettings.alphaOp = NEXUS_FillOp_eCopy; |
|---|
| 381 | NEXUS_Surface_Flush(surface->hSurface); |
|---|
| 382 | NEXUS_Graphics2D_Fill(s_graphics.gfx, &fillSettings); |
|---|
| 383 | bgraphics_checkpoint(); |
|---|
| 384 | return b_ok; |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | bresult bsurface_create_surface(uint32_t width, uint32_t height, |
|---|
| 388 | bgraphics_pixel_format format, |
|---|
| 389 | uint8_t **mem, |
|---|
| 390 | uint32_t *pitch, bsettop_surf_t *surface) |
|---|
| 391 | { |
|---|
| 392 | NEXUS_SurfaceCreateSettings createSettings; |
|---|
| 393 | NEXUS_SurfaceHandle handle; |
|---|
| 394 | NEXUS_SurfaceMemory smem; |
|---|
| 395 | |
|---|
| 396 | *surface = BKNI_Malloc(sizeof(struct bsettop_surf)); |
|---|
| 397 | |
|---|
| 398 | NEXUS_Surface_GetDefaultCreateSettings(&createSettings); |
|---|
| 399 | createSettings.pixelFormat = (format==bgraphics_pixel_format_a8_r8_g8_b8)?NEXUS_PixelFormat_eA8_R8_G8_B8:NEXUS_PixelFormat_eA8_Y8_Cb8_Cr8; |
|---|
| 400 | createSettings.width = width; |
|---|
| 401 | createSettings.height = height; |
|---|
| 402 | createSettings.heap = NEXUS_Platform_GetFramebufferHeap(0); |
|---|
| 403 | handle = NEXUS_Surface_Create(&createSettings); |
|---|
| 404 | |
|---|
| 405 | if (!handle ) { |
|---|
| 406 | BDBG_WRN(("fail to create surface (%dx%d)",width, height)); |
|---|
| 407 | return -1; |
|---|
| 408 | } |
|---|
| 409 | NEXUS_Surface_GetMemory(handle, &smem); |
|---|
| 410 | |
|---|
| 411 | (*surface)->format = createSettings.pixelFormat; |
|---|
| 412 | (*surface)->width = width; |
|---|
| 413 | (*surface)->height = height; |
|---|
| 414 | (*surface)->hSurface = handle; |
|---|
| 415 | BKNI_Memset(smem.buffer, 0, height*smem.pitch); |
|---|
| 416 | *pitch = smem.pitch; |
|---|
| 417 | *mem = smem.buffer; |
|---|
| 418 | return b_ok; |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | bresult bsurface_blit_surface( |
|---|
| 422 | bsettop_surf_t src_surf, bsettop_rect *src_r, |
|---|
| 423 | bsettop_surf_t dst_surf, bsettop_rect *dst_r, |
|---|
| 424 | bsettop_surf_t out_surf, bsettop_rect *out_r) |
|---|
| 425 | { |
|---|
| 426 | NEXUS_Graphics2DBlitSettings blitSettings; |
|---|
| 427 | NEXUS_Graphics2D_GetDefaultBlitSettings(&blitSettings); |
|---|
| 428 | blitSettings.source.surface = src_surf->hSurface; |
|---|
| 429 | blitSettings.source.rect.x = src_r->x; |
|---|
| 430 | blitSettings.source.rect.y = src_r->y; |
|---|
| 431 | blitSettings.source.rect.width = src_r->width; |
|---|
| 432 | blitSettings.source.rect.height = src_r->height; |
|---|
| 433 | |
|---|
| 434 | blitSettings.output.surface = out_surf->hSurface; |
|---|
| 435 | blitSettings.output.rect.x = out_r->x; |
|---|
| 436 | blitSettings.output.rect.y = out_r->y; |
|---|
| 437 | blitSettings.output.rect.width = out_r->width; |
|---|
| 438 | blitSettings.output.rect.height = out_r->height; |
|---|
| 439 | |
|---|
| 440 | if (dst_surf && dst_r) { |
|---|
| 441 | blitSettings.dest.surface = dst_surf->hSurface; |
|---|
| 442 | blitSettings.dest.rect.x = dst_r->x; |
|---|
| 443 | blitSettings.dest.rect.y = dst_r->y; |
|---|
| 444 | blitSettings.dest.rect.width = dst_r->width; |
|---|
| 445 | blitSettings.dest.rect.height = dst_r->height; |
|---|
| 446 | } |
|---|
| 447 | blitSettings.colorOp = NEXUS_BlitColorOp_eCopySource; |
|---|
| 448 | blitSettings.alphaOp = NEXUS_BlitAlphaOp_eCopySource; |
|---|
| 449 | |
|---|
| 450 | NEXUS_Surface_Flush(src_surf->hSurface); |
|---|
| 451 | NEXUS_Surface_Flush(out_surf->hSurface); |
|---|
| 452 | if (dst_surf && (dst_surf->hSurface != out_surf->hSurface)) { |
|---|
| 453 | NEXUS_Surface_Flush(dst_surf->hSurface); |
|---|
| 454 | } |
|---|
| 455 | NEXUS_Graphics2D_Blit(s_graphics.gfx, &blitSettings); |
|---|
| 456 | bgraphics_checkpoint(); |
|---|
| 457 | |
|---|
| 458 | return b_ok; |
|---|
| 459 | } |
|---|