• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_D3D11_H_
6 #define CEF_TESTS_CEFCLIENT_BROWSER_OSR_RENDER_HANDLER_WIN_D3D11_H_
7 #pragma once
8 
9 #include "tests/cefclient/browser/osr_d3d11_win.h"
10 #include "tests/cefclient/browser/osr_render_handler_win.h"
11 #include "tests/cefclient/browser/osr_renderer_settings.h"
12 
13 namespace client {
14 
15 class BrowserLayer : public d3d11::Layer {
16  public:
17   explicit BrowserLayer(const std::shared_ptr<d3d11::Device>& device);
18 
19   void render(const std::shared_ptr<d3d11::Context>& ctx) override;
20 
21   void on_paint(void* share_handle);
22 
23   // After calling on_paint() we can query the texture size.
24   std::pair<uint32_t, uint32_t> texture_size() const;
25 
26  private:
27   std::shared_ptr<d3d11::FrameBuffer> frame_buffer_;
28 
29   DISALLOW_COPY_AND_ASSIGN(BrowserLayer);
30 };
31 
32 class PopupLayer : public BrowserLayer {
33  public:
34   explicit PopupLayer(const std::shared_ptr<d3d11::Device>& device);
35 
36   void set_bounds(const CefRect& bounds);
37 
contains(int x,int y)38   bool contains(int x, int y) const { return bounds_.Contains(x, y); }
xoffset()39   int xoffset() const { return original_bounds_.x - bounds_.x; }
yoffset()40   int yoffset() const { return original_bounds_.y - bounds_.y; }
41 
42  private:
43   CefRect original_bounds_;
44   CefRect bounds_;
45 
46   DISALLOW_COPY_AND_ASSIGN(PopupLayer);
47 };
48 
49 class OsrRenderHandlerWinD3D11 : public OsrRenderHandlerWin {
50  public:
51   OsrRenderHandlerWinD3D11(const OsrRendererSettings& settings, HWND hwnd);
52 
53   // Must be called immediately after object creation.
54   // May fail if D3D11 cannot be initialized.
55   bool Initialize(CefRefPtr<CefBrowser> browser, int width, int height);
56 
57   void SetSpin(float spinX, float spinY) override;
58   void IncrementSpin(float spinDX, float spinDY) override;
59   bool IsOverPopupWidget(int x, int y) const override;
60   int GetPopupXOffset() const override;
61   int GetPopupYOffset() const override;
62   void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) override;
63   void OnPopupSize(CefRefPtr<CefBrowser> browser, const CefRect& rect) override;
64   void OnPaint(CefRefPtr<CefBrowser> browser,
65                CefRenderHandler::PaintElementType type,
66                const CefRenderHandler::RectList& dirtyRects,
67                const void* buffer,
68                int width,
69                int height) override;
70   void OnAcceleratedPaint(CefRefPtr<CefBrowser> browser,
71                           CefRenderHandler::PaintElementType type,
72                           const CefRenderHandler::RectList& dirtyRects,
73                           void* share_handle) override;
74 
75  private:
76   void Render() override;
77 
78   uint64_t start_time_;
79   std::shared_ptr<d3d11::Device> device_;
80   std::shared_ptr<d3d11::SwapChain> swap_chain_;
81   std::shared_ptr<d3d11::Composition> composition_;
82   std::shared_ptr<BrowserLayer> browser_layer_;
83   std::shared_ptr<PopupLayer> popup_layer_;
84 
85   DISALLOW_COPY_AND_ASSIGN(OsrRenderHandlerWinD3D11);
86 };
87 
88 }  // namespace client
89 
90 #endif  // CEF_TESTS_CEFCLIENT_BROWSER_OSR_RENDER_HANDLER_WIN_D3D11_H_
91