Chromium Code Reviews| 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_SURFACE_WIN_H_ |
| 6 #define GPU_IPC_SERVICE_DIRECT_COMPOSITION_SURFACE_WIN_H_ | 6 #define GPU_IPC_SERVICE_DIRECT_COMPOSITION_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" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/win/scoped_comptr.h" | 13 #include "base/win/scoped_comptr.h" |
| 14 #include "gpu/gpu_export.h" | 14 #include "gpu/gpu_export.h" |
| 15 #include "gpu/ipc/service/child_window_win.h" | 15 #include "gpu/ipc/service/child_window_win.h" |
| 16 #include "gpu/ipc/service/image_transport_surface_delegate.h" | 16 #include "gpu/ipc/service/image_transport_surface_delegate.h" |
| 17 #include "ui/gl/gl_image.h" | 17 #include "ui/gl/gl_image.h" |
| 18 #include "ui/gl/gl_surface_egl.h" | 18 #include "ui/gl/gl_surface_egl.h" |
| 19 | 19 |
| 20 namespace gpu { | 20 namespace gpu { |
| 21 | 21 |
| 22 class DCLayerTree; | |
| 23 | |
| 22 class GPU_EXPORT DirectCompositionSurfaceWin : public gl::GLSurfaceEGL { | 24 class GPU_EXPORT DirectCompositionSurfaceWin : public gl::GLSurfaceEGL { |
| 23 public: | 25 public: |
| 24 DirectCompositionSurfaceWin( | 26 DirectCompositionSurfaceWin( |
| 25 base::WeakPtr<ImageTransportSurfaceDelegate> delegate, | 27 base::WeakPtr<ImageTransportSurfaceDelegate> delegate, |
| 26 HWND parent_window); | 28 HWND parent_window); |
| 27 | 29 |
| 28 // Returns true if there's an output on the current adapter that can | 30 // Returns true if there's an output on the current adapter that can |
| 29 // use overlays. | 31 // use overlays. |
| 30 static bool AreOverlaysSupported(); | 32 static bool AreOverlaysSupported(); |
| 31 | 33 |
| 32 bool InitializeNativeWindow(); | 34 bool InitializeNativeWindow(); |
| 33 | 35 |
| 34 // GLSurfaceEGL implementation. | 36 // GLSurfaceEGL implementation. |
| 35 using GLSurfaceEGL::Initialize; | 37 using GLSurfaceEGL::Initialize; |
| 36 bool Initialize(gl::GLSurfaceFormat format) override; | 38 bool Initialize(gl::GLSurfaceFormat format) override; |
| 37 void Destroy() override; | 39 void Destroy() override; |
| 38 gfx::Size GetSize() override; | 40 gfx::Size GetSize() override; |
| 39 bool IsOffscreen() override; | 41 bool IsOffscreen() override; |
| 40 void* GetHandle() override; | 42 void* GetHandle() override; |
| 41 bool Resize(const gfx::Size& size, | 43 bool Resize(const gfx::Size& size, |
| 42 float scale_factor, | 44 float scale_factor, |
| 43 bool has_alpha) override; | 45 bool has_alpha) override; |
| 44 gfx::SwapResult SwapBuffers() override; | 46 gfx::SwapResult SwapBuffers() override; |
| 45 gfx::SwapResult PostSubBuffer(int x, int y, int width, int height) override; | 47 gfx::SwapResult PostSubBuffer(int x, int y, int width, int height) override; |
| 46 gfx::VSyncProvider* GetVSyncProvider() override; | 48 gfx::VSyncProvider* GetVSyncProvider() override; |
| 47 bool ScheduleOverlayPlane(int z_order, | |
| 48 gfx::OverlayTransform transform, | |
| 49 gl::GLImage* image, | |
| 50 const gfx::Rect& bounds_rect, | |
| 51 const gfx::RectF& crop_rect) override; | |
| 52 bool SetEnableDCLayers(bool enable) override; | 49 bool SetEnableDCLayers(bool enable) override; |
| 53 bool FlipsVertically() const override; | 50 bool FlipsVertically() const override; |
| 54 bool SupportsPostSubBuffer() override; | 51 bool SupportsPostSubBuffer() override; |
| 55 bool OnMakeCurrent(gl::GLContext* context) override; | 52 bool OnMakeCurrent(gl::GLContext* context) override; |
| 56 bool SupportsDCLayers() const override; | 53 bool SupportsDCLayers() const override; |
| 57 bool SetDrawRectangle(const gfx::Rect& rect) override; | 54 bool SetDrawRectangle(const gfx::Rect& rect) override; |
| 58 gfx::Vector2d GetDrawOffset() const override; | 55 gfx::Vector2d GetDrawOffset() const override; |
| 56 bool ScheduleDCLayer(const ui::DCRendererLayerParams& params) override; | |
| 59 | 57 |
| 60 bool Initialize(std::unique_ptr<gfx::VSyncProvider> vsync_provider); | 58 bool Initialize(std::unique_ptr<gfx::VSyncProvider> vsync_provider); |
| 61 | 59 |
| 60 base::win::ScopedComPtr<IDCompositionSurface> dcomp_surface() { | |
|
sunnyps
2017/03/28 00:42:24
nit: const?
| |
| 61 return dcomp_surface_; | |
| 62 } | |
| 63 | |
| 62 scoped_refptr<base::TaskRunner> GetWindowTaskRunnerForTesting(); | 64 scoped_refptr<base::TaskRunner> GetWindowTaskRunnerForTesting(); |
| 63 base::win::ScopedComPtr<IDXGISwapChain1> swap_chain() const { | 65 base::win::ScopedComPtr<IDXGISwapChain1> swap_chain() const { |
| 64 return swap_chain_; | 66 return swap_chain_; |
| 65 } | 67 } |
| 66 | 68 |
| 67 protected: | 69 protected: |
| 68 ~DirectCompositionSurfaceWin() override; | 70 ~DirectCompositionSurfaceWin() override; |
| 69 | 71 |
| 70 private: | 72 private: |
| 71 struct Overlay { | |
| 72 Overlay(int z_order, | |
| 73 gfx::OverlayTransform transform, | |
| 74 scoped_refptr<gl::GLImage> image, | |
| 75 gfx::Rect bounds_rect, | |
| 76 gfx::RectF crop_rect); | |
| 77 Overlay(const Overlay& overlay); | |
| 78 | |
| 79 ~Overlay(); | |
| 80 | |
| 81 int z_order; | |
| 82 gfx::OverlayTransform transform; | |
| 83 scoped_refptr<gl::GLImage> image; | |
| 84 gfx::Rect bounds_rect; | |
| 85 gfx::RectF crop_rect; | |
| 86 }; | |
| 87 | |
| 88 bool CommitAndClearPendingOverlays(); | |
| 89 void ReleaseCurrentSurface(); | 73 void ReleaseCurrentSurface(); |
| 90 void InitializeSurface(); | 74 void InitializeSurface(); |
| 91 // Release the texture that's currently being drawn to. If will_discard is | 75 // Release the texture that's currently being drawn to. If will_discard is |
| 92 // true then the surface should be discarded without swapping any contents | 76 // true then the surface should be discarded without swapping any contents |
| 93 // to it. | 77 // to it. |
| 94 void ReleaseDrawTexture(bool will_discard); | 78 void ReleaseDrawTexture(bool will_discard); |
| 95 | 79 |
| 96 ChildWindowWin child_window_; | 80 ChildWindowWin child_window_; |
| 97 | 81 |
| 98 HWND window_ = nullptr; | 82 HWND window_ = nullptr; |
| 99 // This is a placeholder surface used when not rendering to the | 83 // This is a placeholder surface used when not rendering to the |
| 100 // DirectComposition surface. | 84 // DirectComposition surface. |
| 101 EGLSurface default_surface_ = 0; | 85 EGLSurface default_surface_ = 0; |
| 102 | 86 |
| 103 // This is the real surface representing the backbuffer. It may be null | 87 // This is the real surface representing the backbuffer. It may be null |
| 104 // outside of a BeginDraw/EndDraw pair. | 88 // outside of a BeginDraw/EndDraw pair. |
| 105 EGLSurface real_surface_ = 0; | 89 EGLSurface real_surface_ = 0; |
| 106 gfx::Size size_ = gfx::Size(1, 1); | 90 gfx::Size size_ = gfx::Size(1, 1); |
| 107 bool first_swap_ = true; | 91 bool first_swap_ = true; |
| 108 bool enable_dc_layers_ = false; | 92 bool enable_dc_layers_ = false; |
| 109 std::unique_ptr<gfx::VSyncProvider> vsync_provider_; | 93 std::unique_ptr<gfx::VSyncProvider> vsync_provider_; |
| 110 std::vector<Overlay> pending_overlays_; | |
| 111 gfx::Rect swap_rect_; | 94 gfx::Rect swap_rect_; |
| 112 | 95 std::unique_ptr<DCLayerTree> layer_tree_; |
| 113 gfx::Vector2d draw_offset_; | 96 gfx::Vector2d draw_offset_; |
| 114 | 97 |
| 115 base::win::ScopedComPtr<ID3D11Device> d3d11_device_; | 98 base::win::ScopedComPtr<ID3D11Device> d3d11_device_; |
| 116 base::win::ScopedComPtr<IDCompositionDevice2> dcomp_device_; | 99 base::win::ScopedComPtr<IDCompositionDevice2> dcomp_device_; |
| 117 base::win::ScopedComPtr<IDCompositionTarget> dcomp_target_; | |
| 118 base::win::ScopedComPtr<IDCompositionVisual2> visual_; | |
| 119 base::win::ScopedComPtr<IDCompositionSurface> dcomp_surface_; | 100 base::win::ScopedComPtr<IDCompositionSurface> dcomp_surface_; |
| 120 base::win::ScopedComPtr<IDXGISwapChain1> swap_chain_; | 101 base::win::ScopedComPtr<IDXGISwapChain1> swap_chain_; |
| 121 base::win::ScopedComPtr<ID3D11Texture2D> draw_texture_; | 102 base::win::ScopedComPtr<ID3D11Texture2D> draw_texture_; |
| 122 | 103 |
| 123 // Keep track of whether the texture has been rendered to, as the first draw | 104 // Keep track of whether the texture has been rendered to, as the first draw |
| 124 // to it must overwrite the entire thing. | 105 // to it must overwrite the entire thing. |
| 125 bool has_been_rendered_to_ = false; | 106 bool has_been_rendered_to_ = false; |
| 126 | 107 |
| 127 DISALLOW_COPY_AND_ASSIGN(DirectCompositionSurfaceWin); | 108 DISALLOW_COPY_AND_ASSIGN(DirectCompositionSurfaceWin); |
| 128 }; | 109 }; |
| 129 | 110 |
| 130 } // namespace gpu | 111 } // namespace gpu |
| 131 | 112 |
| 132 #endif // GPU_IPC_SERVICE_DIRECT_COMPOSITION_SURFACE_WIN_H_ | 113 #endif // GPU_IPC_SERVICE_DIRECT_COMPOSITION_SURFACE_WIN_H_ |
| OLD | NEW |