Using the pixel data from CEF's offscreen rendering the data is converted by PIL into a SDL2 surface which can then be rendered as a SDL2 texture.
(self, element_type, paint_buffer, **_)
| 503 | return True |
| 504 | |
| 505 | def OnPaint(self, element_type, paint_buffer, **_): |
| 506 | """ |
| 507 | Using the pixel data from CEF's offscreen rendering |
| 508 | the data is converted by PIL into a SDL2 surface |
| 509 | which can then be rendered as a SDL2 texture. |
| 510 | """ |
| 511 | if element_type == cef.PET_VIEW: |
| 512 | image = Image.frombuffer( |
| 513 | 'RGBA', |
| 514 | (self.__width, self.__height), |
| 515 | paint_buffer.GetString(mode="rgba", origin="top-left"), |
| 516 | 'raw', |
| 517 | 'BGRA' |
| 518 | ) |
| 519 | # Following PIL to SDL2 surface code from pysdl2 source. |
| 520 | mode = image.mode |
| 521 | rmask = gmask = bmask = amask = 0 |
| 522 | depth = None |
| 523 | pitch = None |
| 524 | if mode == "RGB": |
| 525 | # 3x8-bit, 24bpp |
| 526 | if sdl2.endian.SDL_BYTEORDER == sdl2.endian.SDL_LIL_ENDIAN: |
| 527 | rmask = 0x0000FF |
| 528 | gmask = 0x00FF00 |
| 529 | bmask = 0xFF0000 |
| 530 | else: |
| 531 | rmask = 0xFF0000 |
| 532 | gmask = 0x00FF00 |
| 533 | bmask = 0x0000FF |
| 534 | depth = 24 |
| 535 | pitch = self.__width * 3 |
| 536 | elif mode in ("RGBA", "RGBX"): |
| 537 | # RGBX: 4x8-bit, no alpha |
| 538 | # RGBA: 4x8-bit, alpha |
| 539 | if sdl2.endian.SDL_BYTEORDER == sdl2.endian.SDL_LIL_ENDIAN: |
| 540 | rmask = 0x00000000 |
| 541 | gmask = 0x0000FF00 |
| 542 | bmask = 0x00FF0000 |
| 543 | if mode == "RGBA": |
| 544 | amask = 0xFF000000 |
| 545 | else: |
| 546 | rmask = 0xFF000000 |
| 547 | gmask = 0x00FF0000 |
| 548 | bmask = 0x0000FF00 |
| 549 | if mode == "RGBA": |
| 550 | amask = 0x000000FF |
| 551 | depth = 32 |
| 552 | pitch = self.__width * 4 |
| 553 | else: |
| 554 | logging.error("ERROR: Unsupported mode: %s" % mode) |
| 555 | exit_app() |
| 556 | |
| 557 | pxbuf = image.tobytes() |
| 558 | # Create surface |
| 559 | surface = sdl2.SDL_CreateRGBSurfaceFrom( |
| 560 | pxbuf, |
| 561 | self.__width, |
| 562 | self.__height, |
nothing calls this directly
no test coverage detected