| OLD | NEW | 
|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef GPU_IPC_SERVICE_DIRECT_COMPOSITION_SURFACE_WIN_H_ | 5 #ifndef GPU_IPC_SERVICE_DIRECT_COMPOSITION_CHILD_SURFACE_WIN_H_ | 
| 6 #define GPU_IPC_SERVICE_DIRECT_COMPOSITION_SURFACE_WIN_H_ | 6 #define GPU_IPC_SERVICE_DIRECT_COMPOSITION_CHILD_SURFACE_WIN_H_ | 
| 7 | 7 | 
| 8 #include <d3d11.h> | 8 #include <d3d11.h> | 
| 9 #include <dcomp.h> | 9 #include <dcomp.h> | 
| 10 #include <windows.h> | 10 #include <windows.h> | 
| 11 | 11 | 
| 12 #include "base/memory/weak_ptr.h" |  | 
| 13 #include "base/win/scoped_comptr.h" | 12 #include "base/win/scoped_comptr.h" | 
| 14 #include "gpu/config/gpu_driver_bug_workarounds.h" |  | 
| 15 #include "gpu/gpu_export.h" | 13 #include "gpu/gpu_export.h" | 
| 16 #include "gpu/ipc/service/child_window_win.h" |  | 
| 17 #include "gpu/ipc/service/image_transport_surface_delegate.h" |  | 
| 18 #include "ui/gl/gl_image.h" |  | 
| 19 #include "ui/gl/gl_surface_egl.h" | 14 #include "ui/gl/gl_surface_egl.h" | 
| 20 | 15 | 
| 21 namespace gpu { | 16 namespace gpu { | 
| 22 | 17 | 
| 23 class DCLayerTree; | 18 class GPU_EXPORT DirectCompositionChildSurfaceWin : public gl::GLSurfaceEGL { | 
| 24 |  | 
| 25 class GPU_EXPORT DirectCompositionSurfaceWin : public gl::GLSurfaceEGL { |  | 
| 26  public: | 19  public: | 
| 27   DirectCompositionSurfaceWin( | 20   DirectCompositionChildSurfaceWin(const gfx::Size& size, | 
| 28       std::unique_ptr<gfx::VSyncProvider> vsync_provider, | 21                                    bool has_alpha, | 
| 29       base::WeakPtr<ImageTransportSurfaceDelegate> delegate, | 22                                    bool enable_dc_layers); | 
| 30       HWND parent_window); |  | 
| 31 |  | 
| 32   // Returns true if there's an output on the current adapter that can |  | 
| 33   // use overlays. |  | 
| 34   static bool AreOverlaysSupported(); |  | 
| 35 |  | 
| 36   bool InitializeNativeWindow(); |  | 
| 37 | 23 | 
| 38   // GLSurfaceEGL implementation. | 24   // GLSurfaceEGL implementation. | 
| 39   using GLSurfaceEGL::Initialize; | 25   using GLSurfaceEGL::Initialize; | 
| 40   bool Initialize(gl::GLSurfaceFormat format) override; | 26   bool Initialize(gl::GLSurfaceFormat format) override; | 
| 41   void Destroy() override; | 27   void Destroy() override; | 
| 42   gfx::Size GetSize() override; | 28   gfx::Size GetSize() override; | 
| 43   bool IsOffscreen() override; | 29   bool IsOffscreen() override; | 
| 44   void* GetHandle() override; | 30   void* GetHandle() override; | 
| 45   bool Resize(const gfx::Size& size, |  | 
| 46               float scale_factor, |  | 
| 47               bool has_alpha) override; |  | 
| 48   gfx::SwapResult SwapBuffers() override; | 31   gfx::SwapResult SwapBuffers() override; | 
| 49   gfx::SwapResult PostSubBuffer(int x, int y, int width, int height) override; |  | 
| 50   gfx::VSyncProvider* GetVSyncProvider() override; |  | 
| 51   bool SetEnableDCLayers(bool enable) override; |  | 
| 52   bool FlipsVertically() const override; | 32   bool FlipsVertically() const override; | 
| 53   bool SupportsPostSubBuffer() override; | 33   bool SupportsPostSubBuffer() override; | 
| 54   bool OnMakeCurrent(gl::GLContext* context) override; | 34   bool OnMakeCurrent(gl::GLContext* context) override; | 
| 55   bool SupportsDCLayers() const override; | 35   bool SupportsDCLayers() const override; | 
| 56   bool SetDrawRectangle(const gfx::Rect& rect) override; | 36   bool SetDrawRectangle(const gfx::Rect& rect) override; | 
| 57   gfx::Vector2d GetDrawOffset() const override; | 37   gfx::Vector2d GetDrawOffset() const override; | 
| 58   void WaitForSnapshotRendering() override; |  | 
| 59 |  | 
| 60   // This schedules an overlay plane to be displayed on the next SwapBuffers |  | 
| 61   // or PostSubBuffer call. Overlay planes must be scheduled before every swap |  | 
| 62   // to remain in the layer tree. This surface's backbuffer doesn't have to be |  | 
| 63   // scheduled with ScheduleDCLayer, as it's automatically placed in the layer |  | 
| 64   // tree at z-order 0. |  | 
| 65   bool ScheduleDCLayer(const ui::DCRendererLayerParams& params) override; |  | 
| 66 | 38 | 
| 67   const base::win::ScopedComPtr<IDCompositionSurface>& dcomp_surface() const { | 39   const base::win::ScopedComPtr<IDCompositionSurface>& dcomp_surface() const { | 
| 68     return dcomp_surface_; | 40     return dcomp_surface_; | 
| 69   } | 41   } | 
| 70 | 42 | 
| 71   scoped_refptr<base::TaskRunner> GetWindowTaskRunnerForTesting(); |  | 
| 72   const base::win::ScopedComPtr<IDXGISwapChain1>& swap_chain() const { | 43   const base::win::ScopedComPtr<IDXGISwapChain1>& swap_chain() const { | 
| 73     return swap_chain_; | 44     return swap_chain_; | 
| 74   } | 45   } | 
| 75 | 46 | 
| 76   base::win::ScopedComPtr<IDXGISwapChain1> GetLayerSwapChainForTesting( |  | 
| 77       size_t index) const; |  | 
| 78 |  | 
| 79   const GpuDriverBugWorkarounds& workarounds() const { return workarounds_; } |  | 
| 80 |  | 
| 81  protected: | 47  protected: | 
| 82   ~DirectCompositionSurfaceWin() override; | 48   ~DirectCompositionChildSurfaceWin() override; | 
| 83 | 49 | 
| 84  private: | 50  private: | 
| 85   void ReleaseCurrentSurface(); | 51   void ReleaseCurrentSurface(); | 
| 86   void InitializeSurface(); | 52   void InitializeSurface(); | 
| 87   // Release the texture that's currently being drawn to. If will_discard is | 53   // Release the texture that's currently being drawn to. If will_discard is | 
| 88   // true then the surface should be discarded without swapping any contents | 54   // true then the surface should be discarded without swapping any contents | 
| 89   // to it. | 55   // to it. | 
| 90   void ReleaseDrawTexture(bool will_discard); | 56   void ReleaseDrawTexture(bool will_discard); | 
| 91 | 57 | 
| 92   ChildWindowWin child_window_; |  | 
| 93 |  | 
| 94   GpuDriverBugWorkarounds workarounds_; |  | 
| 95 |  | 
| 96   HWND window_ = nullptr; |  | 
| 97   // This is a placeholder surface used when not rendering to the | 58   // This is a placeholder surface used when not rendering to the | 
| 98   // DirectComposition surface. | 59   // DirectComposition surface. | 
| 99   EGLSurface default_surface_ = 0; | 60   EGLSurface default_surface_ = 0; | 
| 100 | 61 | 
| 101   // This is the real surface representing the backbuffer. It may be null | 62   // This is the real surface representing the backbuffer. It may be null | 
| 102   // outside of a BeginDraw/EndDraw pair. | 63   // outside of a BeginDraw/EndDraw pair. | 
| 103   EGLSurface real_surface_ = 0; | 64   EGLSurface real_surface_ = 0; | 
| 104   gfx::Size size_ = gfx::Size(1, 1); |  | 
| 105   bool first_swap_ = true; | 65   bool first_swap_ = true; | 
| 106   bool enable_dc_layers_ = false; | 66   const gfx::Size size_; | 
| 107   bool has_alpha_ = true; | 67   const bool has_alpha_; | 
| 108   std::unique_ptr<gfx::VSyncProvider> vsync_provider_; | 68   const bool enable_dc_layers_; | 
| 109   gfx::Rect swap_rect_; | 69   gfx::Rect swap_rect_; | 
| 110   std::unique_ptr<DCLayerTree> layer_tree_; |  | 
| 111   gfx::Vector2d draw_offset_; | 70   gfx::Vector2d draw_offset_; | 
| 112 | 71 | 
| 113   base::win::ScopedComPtr<ID3D11Device> d3d11_device_; | 72   base::win::ScopedComPtr<ID3D11Device> d3d11_device_; | 
| 114   base::win::ScopedComPtr<IDCompositionDevice2> dcomp_device_; | 73   base::win::ScopedComPtr<IDCompositionDevice2> dcomp_device_; | 
| 115   base::win::ScopedComPtr<IDCompositionSurface> dcomp_surface_; | 74   base::win::ScopedComPtr<IDCompositionSurface> dcomp_surface_; | 
| 116   base::win::ScopedComPtr<IDXGISwapChain1> swap_chain_; | 75   base::win::ScopedComPtr<IDXGISwapChain1> swap_chain_; | 
| 117   base::win::ScopedComPtr<ID3D11Texture2D> draw_texture_; | 76   base::win::ScopedComPtr<ID3D11Texture2D> draw_texture_; | 
| 118 | 77 | 
| 119   // Keep track of whether the texture has been rendered to, as the first draw | 78   // Keep track of whether the texture has been rendered to, as the first draw | 
| 120   // to it must overwrite the entire thing. | 79   // to it must overwrite the entire thing. | 
| 121   bool has_been_rendered_to_ = false; | 80   bool has_been_rendered_to_ = false; | 
| 122 | 81 | 
| 123   DISALLOW_COPY_AND_ASSIGN(DirectCompositionSurfaceWin); | 82   DISALLOW_COPY_AND_ASSIGN(DirectCompositionChildSurfaceWin); | 
| 124 }; | 83 }; | 
| 125 | 84 | 
| 126 }  // namespace gpu | 85 }  // namespace gpu | 
| 127 | 86 | 
| 128 #endif  // GPU_IPC_SERVICE_DIRECT_COMPOSITION_SURFACE_WIN_H_ | 87 #endif  // GPU_IPC_SERVICE_DIRECT_COMPOSITION_CHILD_SURFACE_WIN_H_ | 
| OLD | NEW | 
|---|