-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_handler.hpp
63 lines (47 loc) · 1.58 KB
/
render_handler.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef RENDER_HANDLER_HPP
#define RENDER_HANDLER_HPP
// Libraries
#include <cstdint>
#include <functional>
#include <utility>
#include <include/cef_app.h>
#include <include/cef_client.h>
// Forward Declarations
///////////////////////////////////////////////////////////////////////////
class render_handler final : public virtual CefRenderHandler
{
public:
typedef std::function<void(const void *, int, int)> render_callback;
render_handler() = delete;
render_handler(const uint32_t nWidth,
const uint32_t nHeight,
render_callback &&callback) :
m_nWidth(nWidth),
m_nHeight(nHeight),
m_fnRenderCallback(std::forward<render_callback>(callback))
{
}
~render_handler() override = default;
void GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) override
{
rect.Set(0, // x
0, // y
static_cast<int>(m_nWidth), // width
static_cast<int>(m_nHeight)); // height
}
void OnPaint(CefRefPtr<CefBrowser> browser, CefRenderHandler::PaintElementType type,
const CefRenderHandler::RectList &dirtyRects, const void *buffer, int width, int height) override
{
if (m_fnRenderCallback)
{
m_fnRenderCallback(buffer, width, height);
}
}
private:
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(render_handler);
const uint32_t m_nWidth{0};
const uint32_t m_nHeight{0};
const render_callback m_fnRenderCallback;
};
#endif //RENDER_HANDLER_HPP