Advertisement
Guest User

CEF3 Test Classes

a guest
Jul 14th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. InterfaceRenderHandler::InterfaceRenderHandler()
  2. {
  3.     width = 500;
  4.     height = 500;
  5.  
  6.     x = 0;
  7.     y = 0;
  8.  
  9.     size_t size = width * height * 4;
  10.  
  11.     frameReady = false;
  12.     buffer = new unsigned char[size];
  13. }
  14.  
  15. InterfaceRenderHandler::~InterfaceRenderHandler()
  16. {
  17.  
  18. }
  19.  
  20. bool InterfaceRenderHandler::hasFrame()
  21. {
  22.     return frameReady;
  23. }
  24.  
  25. unsigned char *InterfaceRenderHandler::getFrame()
  26. {
  27.     if (frameReady)
  28.     {
  29.         frameReady = false;
  30.         return buffer;
  31.     }
  32.     else
  33.     {
  34.         return nullptr;
  35.     }
  36. }
  37.  
  38. bool InterfaceRenderHandler::GetRootScreenRect(CefRefPtr<CefBrowser> browser, CefRect& rect)
  39. {
  40.     rect.width = width;
  41.     rect.height = height;
  42.     rect.x = x;
  43.     rect.y = y;
  44.  
  45.     return true;
  46. }
  47.  
  48. bool InterfaceRenderHandler::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect)
  49. {
  50.     rect.width = width;
  51.     rect.height = height;
  52.     rect.x = x;
  53.     rect.y = y;
  54.  
  55.     return true;
  56. }
  57.  
  58. void InterfaceRenderHandler::OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList& dirtyRects, const void* buffer, int width, int height)
  59. {
  60.     cout << "Frame delivered.\n";
  61.  
  62.     size_t size = width * height * 4;
  63.    
  64.     unsigned char *inBuffer = (unsigned char *)buffer;
  65.  
  66.     memcpy(this->buffer, inBuffer, size);
  67.  
  68.     frameReady = true;
  69. }
  70.  
  71. InterfaceBrowserClient::InterfaceBrowserClient()
  72. {
  73.     handler = nullptr;
  74. }
  75.  
  76. InterfaceBrowserClient::InterfaceBrowserClient(CefRenderHandler *renderHandler)
  77.     : handler(renderHandler)
  78. {
  79.  
  80. }
  81.  
  82. InterfaceBrowserClient::~InterfaceBrowserClient()
  83. {
  84.     if (handler != nullptr)
  85.     {
  86.         delete handler;
  87.     }
  88. }
  89.  
  90. CefRefPtr<CefRenderHandler> InterfaceBrowserClient::GetRenderHandler()
  91. {
  92.     return handler;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement