Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: gpu/ipc/service/direct_composition_surface_win.h

Issue 2749023011: Add DirectComposition overlay support. (Closed)
Patch Set: remove skia usage in unit test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gpu/ipc/service/DEPS ('k') | gpu/ipc/service/direct_composition_surface_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
59 56
57 // This schedules an overlay plane to be displayed on the next SwapBuffers
58 // or PostSubBuffer call. Overlay planes must be scheduled before every swap
59 // to remain in the layer tree. This surface's backbuffer doesn't have to be
60 // scheduled with ScheduleDCLayer, as it's automatically placed in the layer
61 // tree at z-order 0.
62 bool ScheduleDCLayer(const ui::DCRendererLayerParams& params) override;
63
60 bool Initialize(std::unique_ptr<gfx::VSyncProvider> vsync_provider); 64 bool Initialize(std::unique_ptr<gfx::VSyncProvider> vsync_provider);
61 65
66 const base::win::ScopedComPtr<IDCompositionSurface>& dcomp_surface() const {
67 return dcomp_surface_;
68 }
69
62 scoped_refptr<base::TaskRunner> GetWindowTaskRunnerForTesting(); 70 scoped_refptr<base::TaskRunner> GetWindowTaskRunnerForTesting();
63 base::win::ScopedComPtr<IDXGISwapChain1> swap_chain() const { 71 const base::win::ScopedComPtr<IDXGISwapChain1>& swap_chain() const {
64 return swap_chain_; 72 return swap_chain_;
65 } 73 }
66 74
67 protected: 75 protected:
68 ~DirectCompositionSurfaceWin() override; 76 ~DirectCompositionSurfaceWin() override;
69 77
70 private: 78 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(); 79 void ReleaseCurrentSurface();
90 void InitializeSurface(); 80 void InitializeSurface();
91 // Release the texture that's currently being drawn to. If will_discard is 81 // 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 82 // true then the surface should be discarded without swapping any contents
93 // to it. 83 // to it.
94 void ReleaseDrawTexture(bool will_discard); 84 void ReleaseDrawTexture(bool will_discard);
95 85
96 ChildWindowWin child_window_; 86 ChildWindowWin child_window_;
97 87
98 HWND window_ = nullptr; 88 HWND window_ = nullptr;
99 // This is a placeholder surface used when not rendering to the 89 // This is a placeholder surface used when not rendering to the
100 // DirectComposition surface. 90 // DirectComposition surface.
101 EGLSurface default_surface_ = 0; 91 EGLSurface default_surface_ = 0;
102 92
103 // This is the real surface representing the backbuffer. It may be null 93 // This is the real surface representing the backbuffer. It may be null
104 // outside of a BeginDraw/EndDraw pair. 94 // outside of a BeginDraw/EndDraw pair.
105 EGLSurface real_surface_ = 0; 95 EGLSurface real_surface_ = 0;
106 gfx::Size size_ = gfx::Size(1, 1); 96 gfx::Size size_ = gfx::Size(1, 1);
107 bool first_swap_ = true; 97 bool first_swap_ = true;
108 bool enable_dc_layers_ = false; 98 bool enable_dc_layers_ = false;
109 std::unique_ptr<gfx::VSyncProvider> vsync_provider_; 99 std::unique_ptr<gfx::VSyncProvider> vsync_provider_;
110 std::vector<Overlay> pending_overlays_;
111 gfx::Rect swap_rect_; 100 gfx::Rect swap_rect_;
112 101 std::unique_ptr<DCLayerTree> layer_tree_;
113 gfx::Vector2d draw_offset_; 102 gfx::Vector2d draw_offset_;
114 103
115 base::win::ScopedComPtr<ID3D11Device> d3d11_device_; 104 base::win::ScopedComPtr<ID3D11Device> d3d11_device_;
116 base::win::ScopedComPtr<IDCompositionDevice2> dcomp_device_; 105 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_; 106 base::win::ScopedComPtr<IDCompositionSurface> dcomp_surface_;
120 base::win::ScopedComPtr<IDXGISwapChain1> swap_chain_; 107 base::win::ScopedComPtr<IDXGISwapChain1> swap_chain_;
121 base::win::ScopedComPtr<ID3D11Texture2D> draw_texture_; 108 base::win::ScopedComPtr<ID3D11Texture2D> draw_texture_;
122 109
123 // Keep track of whether the texture has been rendered to, as the first draw 110 // Keep track of whether the texture has been rendered to, as the first draw
124 // to it must overwrite the entire thing. 111 // to it must overwrite the entire thing.
125 bool has_been_rendered_to_ = false; 112 bool has_been_rendered_to_ = false;
126 113
127 DISALLOW_COPY_AND_ASSIGN(DirectCompositionSurfaceWin); 114 DISALLOW_COPY_AND_ASSIGN(DirectCompositionSurfaceWin);
128 }; 115 };
129 116
130 } // namespace gpu 117 } // namespace gpu
131 118
132 #endif // GPU_IPC_SERVICE_DIRECT_COMPOSITION_SURFACE_WIN_H_ 119 #endif // GPU_IPC_SERVICE_DIRECT_COMPOSITION_SURFACE_WIN_H_
OLDNEW
« no previous file with comments | « gpu/ipc/service/DEPS ('k') | gpu/ipc/service/direct_composition_surface_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698