| 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> |
| 9 #include <dcomp.h> |
| 10 #include <windows.h> |
| 11 |
| 8 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/win/scoped_comptr.h" |
| 14 #include "gpu/gpu_export.h" |
| 9 #include "gpu/ipc/service/child_window_win.h" | 15 #include "gpu/ipc/service/child_window_win.h" |
| 10 #include "gpu/ipc/service/image_transport_surface_delegate.h" | 16 #include "gpu/ipc/service/image_transport_surface_delegate.h" |
| 11 #include "ui/gl/gl_image.h" | 17 #include "ui/gl/gl_image.h" |
| 12 #include "ui/gl/gl_surface_egl.h" | 18 #include "ui/gl/gl_surface_egl.h" |
| 13 | 19 |
| 14 #include <windows.h> | |
| 15 | |
| 16 namespace gpu { | 20 namespace gpu { |
| 17 | 21 |
| 18 class DirectCompositionSurfaceWin : public gl::GLSurfaceEGL { | 22 class GPU_EXPORT DirectCompositionSurfaceWin : public gl::GLSurfaceEGL { |
| 19 public: | 23 public: |
| 20 DirectCompositionSurfaceWin( | 24 DirectCompositionSurfaceWin( |
| 21 base::WeakPtr<ImageTransportSurfaceDelegate> delegate, | 25 base::WeakPtr<ImageTransportSurfaceDelegate> delegate, |
| 22 HWND parent_window); | 26 HWND parent_window); |
| 23 | 27 |
| 24 bool InitializeNativeWindow(); | 28 bool InitializeNativeWindow(); |
| 25 | 29 |
| 26 // GLSurfaceEGL implementation. | 30 // GLSurfaceEGL implementation. |
| 27 using GLSurfaceEGL::Initialize; | 31 using GLSurfaceEGL::Initialize; |
| 28 bool Initialize(gl::GLSurfaceFormat format) override; | 32 bool Initialize(gl::GLSurfaceFormat format) override; |
| 29 void Destroy() override; | 33 void Destroy() override; |
| 30 gfx::Size GetSize() override; | 34 gfx::Size GetSize() override; |
| 31 bool IsOffscreen() override; | 35 bool IsOffscreen() override; |
| 32 void* GetHandle() override; | 36 void* GetHandle() override; |
| 33 bool Resize(const gfx::Size& size, | 37 bool Resize(const gfx::Size& size, |
| 34 float scale_factor, | 38 float scale_factor, |
| 35 bool has_alpha) override; | 39 bool has_alpha) override; |
| 36 gfx::SwapResult SwapBuffers() override; | 40 gfx::SwapResult SwapBuffers() override; |
| 37 gfx::SwapResult PostSubBuffer(int x, int y, int width, int height) override; | 41 gfx::SwapResult PostSubBuffer(int x, int y, int width, int height) override; |
| 38 gfx::VSyncProvider* GetVSyncProvider() override; | 42 gfx::VSyncProvider* GetVSyncProvider() override; |
| 39 bool ScheduleOverlayPlane(int z_order, | 43 bool ScheduleOverlayPlane(int z_order, |
| 40 gfx::OverlayTransform transform, | 44 gfx::OverlayTransform transform, |
| 41 gl::GLImage* image, | 45 gl::GLImage* image, |
| 42 const gfx::Rect& bounds_rect, | 46 const gfx::Rect& bounds_rect, |
| 43 const gfx::RectF& crop_rect) override; | 47 const gfx::RectF& crop_rect) override; |
| 48 bool FlipsVertically() const override; |
| 44 bool SupportsPostSubBuffer() override; | 49 bool SupportsPostSubBuffer() override; |
| 50 bool OnMakeCurrent(gl::GLContext* context) override; |
| 51 bool SupportsSetDrawRectangle() const override; |
| 52 bool SetDrawRectangle(const gfx::Rect& rect) override; |
| 45 | 53 |
| 46 bool Initialize(std::unique_ptr<gfx::VSyncProvider> vsync_provider); | 54 bool Initialize(std::unique_ptr<gfx::VSyncProvider> vsync_provider); |
| 47 | 55 |
| 48 protected: | 56 protected: |
| 49 ~DirectCompositionSurfaceWin() override; | 57 ~DirectCompositionSurfaceWin() override; |
| 50 | 58 |
| 51 private: | 59 private: |
| 52 struct Overlay { | 60 struct Overlay { |
| 53 Overlay(int z_order, | 61 Overlay(int z_order, |
| 54 gfx::OverlayTransform transform, | 62 gfx::OverlayTransform transform, |
| 55 scoped_refptr<gl::GLImage> image, | 63 scoped_refptr<gl::GLImage> image, |
| 56 gfx::Rect bounds_rect, | 64 gfx::Rect bounds_rect, |
| 57 gfx::RectF crop_rect); | 65 gfx::RectF crop_rect); |
| 58 Overlay(const Overlay& overlay); | 66 Overlay(const Overlay& overlay); |
| 59 | 67 |
| 60 ~Overlay(); | 68 ~Overlay(); |
| 61 | 69 |
| 62 int z_order; | 70 int z_order; |
| 63 gfx::OverlayTransform transform; | 71 gfx::OverlayTransform transform; |
| 64 scoped_refptr<gl::GLImage> image; | 72 scoped_refptr<gl::GLImage> image; |
| 65 gfx::Rect bounds_rect; | 73 gfx::Rect bounds_rect; |
| 66 gfx::RectF crop_rect; | 74 gfx::RectF crop_rect; |
| 67 }; | 75 }; |
| 68 | 76 |
| 69 bool CommitAndClearPendingOverlays(); | 77 bool CommitAndClearPendingOverlays(); |
| 78 void InitializeSurface(); |
| 79 void ReleaseDrawTexture(); |
| 70 | 80 |
| 71 ChildWindowWin child_window_; | 81 ChildWindowWin child_window_; |
| 72 | 82 |
| 73 HWND window_; | 83 HWND window_ = nullptr; |
| 74 EGLSurface surface_; | 84 // This is a placeholder surface used when not rendering to the |
| 75 gfx::Size size_; | 85 // DirectComposition surface. |
| 76 bool first_swap_; | 86 EGLSurface default_surface_ = 0; |
| 87 |
| 88 // This is the real surface representing the backbuffer. It may be null |
| 89 // outside of a BeginDraw/EndDraw pair. |
| 90 EGLSurface real_surface_ = 0; |
| 91 gfx::Size size_ = gfx::Size(1, 1); |
| 92 bool first_swap_ = true; |
| 77 std::unique_ptr<gfx::VSyncProvider> vsync_provider_; | 93 std::unique_ptr<gfx::VSyncProvider> vsync_provider_; |
| 78 std::vector<Overlay> pending_overlays_; | 94 std::vector<Overlay> pending_overlays_; |
| 79 | 95 |
| 96 base::win::ScopedComPtr<ID3D11Device> d3d11_device_; |
| 97 base::win::ScopedComPtr<IDCompositionDevice2> dcomp_device_; |
| 98 base::win::ScopedComPtr<IDCompositionTarget> dcomp_target_; |
| 99 base::win::ScopedComPtr<IDCompositionVisual2> visual_; |
| 100 base::win::ScopedComPtr<IDCompositionSurface> dcomp_surface_; |
| 101 base::win::ScopedComPtr<ID3D11Texture2D> draw_texture_; |
| 102 |
| 103 // Keep track of whether the texture has been rendered to, as the first draw |
| 104 // to it must overwrite the entire thing. |
| 105 bool has_been_rendered_to_ = false; |
| 106 |
| 80 DISALLOW_COPY_AND_ASSIGN(DirectCompositionSurfaceWin); | 107 DISALLOW_COPY_AND_ASSIGN(DirectCompositionSurfaceWin); |
| 81 }; | 108 }; |
| 82 | 109 |
| 83 } // namespace gpu | 110 } // namespace gpu |
| 84 | 111 |
| 85 #endif // GPU_IPC_SERVICE_DIRECT_COMPOSITION_SURFACE_WIN_H_ | 112 #endif // GPU_IPC_SERVICE_DIRECT_COMPOSITION_SURFACE_WIN_H_ |
| OLD | NEW |