1 // Copyright 2018 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that 3 // can be found in the LICENSE file. 4 5 #ifndef CEF_TESTS_CEFCLIENT_BROWSER_OSR_RENDER_HANDLER_WIN_H_ 6 #define CEF_TESTS_CEFCLIENT_BROWSER_OSR_RENDER_HANDLER_WIN_H_ 7 #pragma once 8 9 #include "include/base/cef_weak_ptr.h" 10 #include "include/cef_render_handler.h" 11 #include "tests/cefclient/browser/osr_renderer_settings.h" 12 13 namespace client { 14 15 // Abstract base class for implementing OSR rendering with different backends on 16 // Windows. Methods are only called on the UI thread. 17 class OsrRenderHandlerWin { 18 public: 19 OsrRenderHandlerWin(const OsrRendererSettings& settings, HWND hwnd); 20 virtual ~OsrRenderHandlerWin(); 21 22 void SetBrowser(CefRefPtr<CefBrowser> browser); 23 24 // Rotate the texture based on mouse events. 25 virtual void SetSpin(float spinX, float spinY) = 0; 26 virtual void IncrementSpin(float spinDX, float spinDY) = 0; 27 28 // Popup hit testing. 29 virtual bool IsOverPopupWidget(int x, int y) const = 0; 30 virtual int GetPopupXOffset() const = 0; 31 virtual int GetPopupYOffset() const = 0; 32 33 // CefRenderHandler callbacks. 34 virtual void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) = 0; 35 // |rect| must be in pixel coordinates. 36 virtual void OnPopupSize(CefRefPtr<CefBrowser> browser, 37 const CefRect& rect) = 0; 38 39 // Used when not rendering with shared textures. 40 virtual void OnPaint(CefRefPtr<CefBrowser> browser, 41 CefRenderHandler::PaintElementType type, 42 const CefRenderHandler::RectList& dirtyRects, 43 const void* buffer, 44 int width, 45 int height) = 0; 46 47 // Used when rendering with shared textures. 48 virtual void OnAcceleratedPaint(CefRefPtr<CefBrowser> browser, 49 CefRenderHandler::PaintElementType type, 50 const CefRenderHandler::RectList& dirtyRects, 51 void* share_handle) = 0; 52 send_begin_frame()53 bool send_begin_frame() const { 54 return settings_.external_begin_frame_enabled; 55 } hwnd()56 HWND hwnd() const { return hwnd_; } 57 58 protected: 59 // Called to trigger the BeginFrame timer. 60 void Invalidate(); 61 62 // Called by the BeginFrame timer. 63 virtual void Render() = 0; 64 65 private: 66 void TriggerBeginFrame(uint64_t last_time_us, float delay_us); 67 68 // The below members are only accessed on the UI thread. 69 const OsrRendererSettings settings_; 70 const HWND hwnd_; 71 bool begin_frame_pending_; 72 CefRefPtr<CefBrowser> browser_; 73 74 // Must be the last member. 75 base::WeakPtrFactory<OsrRenderHandlerWin> weak_factory_; 76 77 DISALLOW_COPY_AND_ASSIGN(OsrRenderHandlerWin); 78 }; 79 80 } // namespace client 81 82 #endif // CEF_TESTS_CEFCLIENT_BROWSER_OSR_RENDER_HANDLER_WIN_H_ 83