| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 CC_OUTPUT_OUTPUT_SURFACE_H_ | 5 #ifndef CC_OUTPUT_OUTPUT_SURFACE_H_ |
| 6 #define CC_OUTPUT_OUTPUT_SURFACE_H_ | 6 #define CC_OUTPUT_OUTPUT_SURFACE_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 // Represents the output surface for a compositor. The compositor owns | 42 // Represents the output surface for a compositor. The compositor owns |
| 43 // and manages its destruction. Its lifetime is: | 43 // and manages its destruction. Its lifetime is: |
| 44 // 1. Created on the main thread by the LayerTreeHost through its client. | 44 // 1. Created on the main thread by the LayerTreeHost through its client. |
| 45 // 2. Passed to the compositor thread and bound to a client via BindToClient. | 45 // 2. Passed to the compositor thread and bound to a client via BindToClient. |
| 46 // From here on, it will only be used on the compositor thread. | 46 // From here on, it will only be used on the compositor thread. |
| 47 // 3. If the 3D context is lost, then the compositor will delete the output | 47 // 3. If the 3D context is lost, then the compositor will delete the output |
| 48 // surface (on the compositor thread) and go back to step 1. | 48 // surface (on the compositor thread) and go back to step 1. |
| 49 class CC_EXPORT OutputSurface : public base::trace_event::MemoryDumpProvider { | 49 class CC_EXPORT OutputSurface : public base::trace_event::MemoryDumpProvider { |
| 50 public: | 50 public: |
| 51 // Constructor for GL-based and/or software compositing. | 51 struct Capabilities { |
| 52 explicit OutputSurface(scoped_refptr<ContextProvider> context_provider, | 52 Capabilities() = default; |
| 53 scoped_refptr<ContextProvider> worker_context_provider, | |
| 54 std::unique_ptr<SoftwareOutputDevice> software_device); | |
| 55 | 53 |
| 54 int max_frames_pending = 1; |
| 55 // Whether this output surface renders to the default OpenGL zero |
| 56 // framebuffer or to an offscreen framebuffer. |
| 57 bool uses_default_gl_framebuffer = true; |
| 58 // Whether this OutputSurface is flipped or not. |
| 59 bool flipped_output_surface = false; |
| 60 }; |
| 61 |
| 62 // Constructor for GL-based compositing. |
| 63 explicit OutputSurface(scoped_refptr<ContextProvider> context_provider); |
| 64 // Constructor for software compositing. |
| 65 explicit OutputSurface(std::unique_ptr<SoftwareOutputDevice> software_device); |
| 56 // Constructor for Vulkan-based compositing. | 66 // Constructor for Vulkan-based compositing. |
| 57 explicit OutputSurface( | 67 explicit OutputSurface( |
| 58 scoped_refptr<VulkanContextProvider> vulkan_context_provider); | 68 scoped_refptr<VulkanContextProvider> vulkan_context_provider); |
| 59 | 69 |
| 60 ~OutputSurface() override; | 70 ~OutputSurface() override; |
| 61 | 71 |
| 62 struct Capabilities { | 72 // Called by the compositor on the compositor thread. This is a place where |
| 63 Capabilities() | 73 // thread-specific data for the output surface can be initialized, since from |
| 64 : delegated_rendering(false), | 74 // this point to when DetachFromClient() is called the output surface will |
| 65 max_frames_pending(1), | 75 // only be used on the compositor thread. |
| 66 adjust_deadline_for_parent(true), | 76 // The caller should call DetachFromClient() on the same thread before |
| 67 uses_default_gl_framebuffer(true), | 77 // destroying the OutputSurface, even if this fails. And BindToClient should |
| 68 flipped_output_surface(false), | 78 // not be called twice for a given OutputSurface. |
| 69 can_force_reclaim_resources(false), | 79 virtual bool BindToClient(OutputSurfaceClient* client); |
| 70 delegated_sync_points_required(true) {} | |
| 71 bool delegated_rendering; | |
| 72 int max_frames_pending; | |
| 73 // This doesn't handle the <webview> case, but once BeginFrame is | |
| 74 // supported natively, we shouldn't need adjust_deadline_for_parent. | |
| 75 bool adjust_deadline_for_parent; | |
| 76 // Whether this output surface renders to the default OpenGL zero | |
| 77 // framebuffer or to an offscreen framebuffer. | |
| 78 bool uses_default_gl_framebuffer; | |
| 79 // Whether this OutputSurface is flipped or not. | |
| 80 bool flipped_output_surface; | |
| 81 // Whether ForceReclaimResources can be called to reclaim all resources | |
| 82 // from the OutputSurface. | |
| 83 bool can_force_reclaim_resources; | |
| 84 // True if sync points for resources are needed when swapping delegated | |
| 85 // frames. | |
| 86 bool delegated_sync_points_required; | |
| 87 }; | |
| 88 | 80 |
| 89 // ============== DISPLAY COMPOSITOR ONLY ======================= | 81 // Called by the compositor on the compositor thread. This is a place where |
| 82 // thread-specific data for the output surface can be uninitialized. |
| 83 virtual void DetachFromClient(); |
| 84 |
| 85 bool HasClient() { return !!client_; } |
| 86 |
| 87 const Capabilities& capabilities() const { return capabilities_; } |
| 88 |
| 89 // Obtain the 3d context or the software device associated with this output |
| 90 // surface. Either of these may return a null pointer, but not both. |
| 91 // In the event of a lost context, the entire output surface should be |
| 92 // recreated. |
| 93 ContextProvider* context_provider() const { return context_provider_.get(); } |
| 94 VulkanContextProvider* vulkan_context_provider() const { |
| 95 return vulkan_context_provider_.get(); |
| 96 } |
| 97 SoftwareOutputDevice* software_device() const { |
| 98 return software_device_.get(); |
| 99 } |
| 90 | 100 |
| 91 virtual void EnsureBackbuffer(); | 101 virtual void EnsureBackbuffer(); |
| 92 virtual void DiscardBackbuffer(); | 102 virtual void DiscardBackbuffer(); |
| 93 | 103 |
| 94 const gfx::ColorSpace& device_color_space() const { | 104 const gfx::ColorSpace& device_color_space() const { |
| 95 return device_color_space_; | 105 return device_color_space_; |
| 96 } | 106 } |
| 97 | 107 |
| 98 // Called by subclasses after receiving a response from the gpu process to a | 108 // Called by subclasses after receiving a response from the gpu process to a |
| 99 // query about whether a given set of textures is still in use by the OS | 109 // query about whether a given set of textures is still in use by the OS |
| (...skipping 12 matching lines...) Expand all Loading... |
| 112 | 122 |
| 113 // If this returns true, then the surface will not attempt to draw. | 123 // If this returns true, then the surface will not attempt to draw. |
| 114 virtual bool SurfaceIsSuspendForRecycle() const; | 124 virtual bool SurfaceIsSuspendForRecycle() const; |
| 115 | 125 |
| 116 virtual void Reshape(const gfx::Size& size, | 126 virtual void Reshape(const gfx::Size& size, |
| 117 float scale_factor, | 127 float scale_factor, |
| 118 const gfx::ColorSpace& color_space, | 128 const gfx::ColorSpace& color_space, |
| 119 bool alpha); | 129 bool alpha); |
| 120 gfx::Size SurfaceSize() const { return surface_size_; } | 130 gfx::Size SurfaceSize() const { return surface_size_; } |
| 121 | 131 |
| 132 virtual void BindFramebuffer(); |
| 133 |
| 122 virtual bool HasExternalStencilTest() const; | 134 virtual bool HasExternalStencilTest() const; |
| 123 virtual void ApplyExternalStencil(); | 135 virtual void ApplyExternalStencil(); |
| 124 | 136 |
| 125 // ============== LAYER TREE COMPOSITOR ONLY =================== | |
| 126 | |
| 127 // If supported, this causes a ReclaimResources for all resources that are | |
| 128 // currently in use. | |
| 129 virtual void ForceReclaimResources() {} | |
| 130 | |
| 131 virtual void BindFramebuffer(); | |
| 132 // Gives the GL internal format that should be used for calling CopyTexImage2D | 137 // Gives the GL internal format that should be used for calling CopyTexImage2D |
| 133 // when the framebuffer is bound via BindFramebuffer(). | 138 // when the framebuffer is bound via BindFramebuffer(). |
| 134 virtual uint32_t GetFramebufferCopyTextureFormat() = 0; | 139 virtual uint32_t GetFramebufferCopyTextureFormat() = 0; |
| 135 | 140 |
| 136 // Support for a pull-model where draws are requested by the output surface. | |
| 137 // | |
| 138 // OutputSurface::Invalidate is called by the compositor to notify that | |
| 139 // there's new content. | |
| 140 virtual void Invalidate() {} | |
| 141 | |
| 142 // ============== BOTH TYPES OF COMPOSITOR ====================== | |
| 143 | |
| 144 // Called by the compositor on the compositor thread. This is a place where | |
| 145 // thread-specific data for the output surface can be initialized, since from | |
| 146 // this point to when DetachFromClient() is called the output surface will | |
| 147 // only be used on the compositor thread. | |
| 148 // The caller should call DetachFromClient() on the same thread before | |
| 149 // destroying the OutputSurface, even if this fails. And BindToClient should | |
| 150 // not be called twice for a given OutputSurface. | |
| 151 virtual bool BindToClient(OutputSurfaceClient* client); | |
| 152 | |
| 153 // Called by the compositor on the compositor thread. This is a place where | |
| 154 // thread-specific data for the output surface can be uninitialized. | |
| 155 virtual void DetachFromClient(); | |
| 156 | |
| 157 bool HasClient() { return !!client_; } | |
| 158 | |
| 159 const Capabilities& capabilities() const { return capabilities_; } | |
| 160 | |
| 161 // Obtain the 3d context or the software device associated with this output | |
| 162 // surface. Either of these may return a null pointer, but not both. | |
| 163 // In the event of a lost context, the entire output surface should be | |
| 164 // recreated. | |
| 165 ContextProvider* context_provider() const { return context_provider_.get(); } | |
| 166 ContextProvider* worker_context_provider() const { | |
| 167 return worker_context_provider_.get(); | |
| 168 } | |
| 169 VulkanContextProvider* vulkan_context_provider() const { | |
| 170 return vulkan_context_provider_.get(); | |
| 171 } | |
| 172 SoftwareOutputDevice* software_device() const { | |
| 173 return software_device_.get(); | |
| 174 } | |
| 175 | |
| 176 // The implementation may destroy or steal the contents of the CompositorFrame | 141 // The implementation may destroy or steal the contents of the CompositorFrame |
| 177 // passed in (though it will not take ownership of the CompositorFrame | 142 // passed in (though it will not take ownership of the CompositorFrame |
| 178 // itself). For successful swaps, the implementation must call | 143 // itself). For successful swaps, the implementation must call |
| 179 // DidSwapBuffersComplete() (via OnSwapBuffersComplete()) eventually. | 144 // DidSwapBuffersComplete() (via OnSwapBuffersComplete()) eventually. |
| 180 virtual void SwapBuffers(CompositorFrame frame) = 0; | 145 virtual void SwapBuffers(CompositorFrame frame) = 0; |
| 181 virtual void OnSwapBuffersComplete(); | 146 virtual void OnSwapBuffersComplete(); |
| 182 | 147 |
| 183 // base::trace_event::MemoryDumpProvider implementation. | 148 // base::trace_event::MemoryDumpProvider implementation. |
| 184 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 149 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
| 185 base::trace_event::ProcessMemoryDump* pmd) override; | 150 base::trace_event::ProcessMemoryDump* pmd) override; |
| 186 | 151 |
| 187 protected: | 152 protected: |
| 188 // This is used by both display and delegating implementations. | |
| 189 void PostSwapBuffersComplete(); | 153 void PostSwapBuffersComplete(); |
| 190 | 154 |
| 191 // This is how LayerTreeHostImpl hears about context loss when the Display | 155 // Used internally for the context provider to inform the client about loss, |
| 192 // is the one listening for context loss. Also used internally for the | 156 // and can be overridden to change behaviour instead of informing the client. |
| 193 // context provider to inform the LayerTreeHostImpl or Display about loss. | |
| 194 // It would become display-compositor-only when LayerTreeHostImpl receives | |
| 195 // its contexts independently from the "OutputSurface". | |
| 196 virtual void DidLoseOutputSurface(); | 157 virtual void DidLoseOutputSurface(); |
| 197 | 158 |
| 198 OutputSurfaceClient* client_ = nullptr; | 159 OutputSurfaceClient* client_ = nullptr; |
| 199 | 160 |
| 200 struct OutputSurface::Capabilities capabilities_; | 161 struct OutputSurface::Capabilities capabilities_; |
| 201 scoped_refptr<ContextProvider> context_provider_; | 162 scoped_refptr<ContextProvider> context_provider_; |
| 202 scoped_refptr<ContextProvider> worker_context_provider_; | |
| 203 scoped_refptr<VulkanContextProvider> vulkan_context_provider_; | 163 scoped_refptr<VulkanContextProvider> vulkan_context_provider_; |
| 204 std::unique_ptr<SoftwareOutputDevice> software_device_; | 164 std::unique_ptr<SoftwareOutputDevice> software_device_; |
| 205 gfx::Size surface_size_; | 165 gfx::Size surface_size_; |
| 206 float device_scale_factor_ = -1; | 166 float device_scale_factor_ = -1; |
| 207 gfx::ColorSpace device_color_space_; | 167 gfx::ColorSpace device_color_space_; |
| 208 bool has_alpha_ = true; | 168 bool has_alpha_ = true; |
| 209 gfx::ColorSpace color_space_; | 169 gfx::ColorSpace color_space_; |
| 210 base::ThreadChecker client_thread_checker_; | 170 base::ThreadChecker client_thread_checker_; |
| 211 | 171 |
| 212 private: | 172 private: |
| 213 void DetachFromClientInternal(); | 173 void DetachFromClientInternal(); |
| 214 | 174 |
| 215 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; | 175 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; |
| 216 | 176 |
| 217 DISALLOW_COPY_AND_ASSIGN(OutputSurface); | 177 DISALLOW_COPY_AND_ASSIGN(OutputSurface); |
| 218 }; | 178 }; |
| 219 | 179 |
| 220 } // namespace cc | 180 } // namespace cc |
| 221 | 181 |
| 222 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ | 182 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ |
| OLD | NEW |