Chromium Code Reviews| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 // Whether this OutputSurface is flipped or not. | 79 // Whether this OutputSurface is flipped or not. |
| 80 bool flipped_output_surface; | 80 bool flipped_output_surface; |
| 81 // Whether ForceReclaimResources can be called to reclaim all resources | 81 // Whether ForceReclaimResources can be called to reclaim all resources |
| 82 // from the OutputSurface. | 82 // from the OutputSurface. |
| 83 bool can_force_reclaim_resources; | 83 bool can_force_reclaim_resources; |
| 84 // True if sync points for resources are needed when swapping delegated | 84 // True if sync points for resources are needed when swapping delegated |
| 85 // frames. | 85 // frames. |
| 86 bool delegated_sync_points_required; | 86 bool delegated_sync_points_required; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 const Capabilities& capabilities() const { | 89 // ============== DISPLAY COMPOSITOR ONLY ======================= |
| 90 return capabilities_; | |
| 91 } | |
| 92 | |
| 93 virtual bool HasExternalStencilTest() const; | |
| 94 virtual void ApplyExternalStencil(); | |
| 95 | |
| 96 // Obtain the 3d context or the software device associated with this output | |
| 97 // surface. Either of these may return a null pointer, but not both. | |
| 98 // In the event of a lost context, the entire output surface should be | |
| 99 // recreated. | |
| 100 ContextProvider* context_provider() const { return context_provider_.get(); } | |
| 101 ContextProvider* worker_context_provider() const { | |
| 102 return worker_context_provider_.get(); | |
| 103 } | |
| 104 VulkanContextProvider* vulkan_context_provider() const { | |
| 105 return vulkan_context_provider_.get(); | |
| 106 } | |
| 107 SoftwareOutputDevice* software_device() const { | |
| 108 return software_device_.get(); | |
| 109 } | |
| 110 | |
| 111 // Called by the compositor on the compositor thread. This is a place where | |
| 112 // thread-specific data for the output surface can be initialized, since from | |
| 113 // this point to when DetachFromClient() is called the output surface will | |
| 114 // only be used on the compositor thread. | |
| 115 // The caller should call DetachFromClient() on the same thread before | |
| 116 // destroying the OutputSurface, even if this fails. And BindToClient should | |
| 117 // not be called twice for a given OutputSurface. | |
| 118 virtual bool BindToClient(OutputSurfaceClient* client); | |
| 119 | |
| 120 // Called by the compositor on the compositor thread. This is a place where | |
| 121 // thread-specific data for the output surface can be uninitialized. | |
| 122 virtual void DetachFromClient(); | |
| 123 | 90 |
| 124 virtual void EnsureBackbuffer(); | 91 virtual void EnsureBackbuffer(); |
| 125 virtual void DiscardBackbuffer(); | 92 virtual void DiscardBackbuffer(); |
| 126 | 93 |
| 127 virtual void Reshape(const gfx::Size& size, | |
| 128 float scale_factor, | |
| 129 const gfx::ColorSpace& color_space, | |
| 130 bool alpha); | |
| 131 gfx::Size SurfaceSize() const { return surface_size_; } | |
| 132 float device_scale_factor() const { return device_scale_factor_; } | |
| 133 const gfx::ColorSpace& device_color_space() const { | 94 const gfx::ColorSpace& device_color_space() const { |
| 134 return device_color_space_; | 95 return device_color_space_; |
| 135 } | 96 } |
| 136 | 97 |
| 137 // If supported, this causes a ReclaimResources for all resources that are | |
| 138 // currently in use. | |
| 139 virtual void ForceReclaimResources() {} | |
| 140 | |
| 141 virtual void BindFramebuffer(); | |
| 142 // Gives the GL internal format that should be used for calling CopyTexImage2D | |
| 143 // when the framebuffer is bound via BindFramebuffer(). | |
| 144 virtual uint32_t GetFramebufferCopyTextureFormat() = 0; | |
| 145 | |
| 146 // The implementation may destroy or steal the contents of the CompositorFrame | |
| 147 // passed in (though it will not take ownership of the CompositorFrame | |
| 148 // itself). For successful swaps, the implementation must call | |
| 149 // DidSwapBuffersComplete() (via OnSwapBuffersComplete()) eventually. | |
| 150 virtual void SwapBuffers(CompositorFrame frame) = 0; | |
| 151 virtual void OnSwapBuffersComplete(); | |
| 152 | |
| 153 // Called by subclasses after receiving a response from the gpu process to a | 98 // Called by subclasses after receiving a response from the gpu process to a |
| 154 // query about whether a given set of textures is still in use by the OS | 99 // query about whether a given set of textures is still in use by the OS |
| 155 // compositor. | 100 // compositor. |
| 156 void DidReceiveTextureInUseResponses( | 101 void DidReceiveTextureInUseResponses( |
| 157 const gpu::TextureInUseResponses& responses); | 102 const gpu::TextureInUseResponses& responses); |
| 158 | 103 |
| 159 bool HasClient() { return !!client_; } | |
| 160 | |
| 161 // Get the class capable of informing cc of hardware overlay capability. | 104 // Get the class capable of informing cc of hardware overlay capability. |
| 162 virtual OverlayCandidateValidator* GetOverlayCandidateValidator() const; | 105 virtual OverlayCandidateValidator* GetOverlayCandidateValidator() const; |
| 163 | 106 |
| 164 // Returns true if a main image overlay plane should be scheduled. | 107 // Returns true if a main image overlay plane should be scheduled. |
| 165 virtual bool IsDisplayedAsOverlayPlane() const; | 108 virtual bool IsDisplayedAsOverlayPlane() const; |
| 166 | 109 |
| 167 // Get the texture for the main image's overlay. | 110 // Get the texture for the main image's overlay. |
| 168 virtual unsigned GetOverlayTextureId() const; | 111 virtual unsigned GetOverlayTextureId() const; |
| 169 | 112 |
| 170 virtual void DidLoseOutputSurface(); | 113 // If this returns true, then the surface will not attempt to draw. |
| 114 virtual bool SurfaceIsSuspendForRecycle() const; | |
| 115 | |
| 116 virtual void Reshape(const gfx::Size& size, | |
| 117 float scale_factor, | |
| 118 const gfx::ColorSpace& color_space, | |
| 119 bool alpha); | |
| 120 gfx::Size SurfaceSize() const { return surface_size_; } | |
| 121 | |
| 122 virtual void ApplyExternalStencil(); | |
| 123 virtual bool HasExternalStencilTest() const; | |
| 124 | |
| 125 // ============== CONTENT COLLATOR ONLY ========================= | |
|
enne (OOO)
2016/09/12 18:25:20
Maybe just call this ContentFrameSink only? I know
| |
| 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 | |
| 133 // when the framebuffer is bound via BindFramebuffer(). | |
| 134 virtual uint32_t GetFramebufferCopyTextureFormat() = 0; | |
| 171 | 135 |
| 172 // Support for a pull-model where draws are requested by the output surface. | 136 // Support for a pull-model where draws are requested by the output surface. |
| 173 // | 137 // |
| 174 // OutputSurface::Invalidate is called by the compositor to notify that | 138 // OutputSurface::Invalidate is called by the compositor to notify that |
| 175 // there's new content. | 139 // there's new content. |
| 176 virtual void Invalidate() {} | 140 virtual void Invalidate() {} |
| 177 | 141 |
| 178 // If this returns true, then the surface will not attempt to draw. | 142 // ============== BOTH TYPES OF COMPOSITOR ====================== |
| 179 virtual bool SurfaceIsSuspendForRecycle() const; | 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 | |
| 177 // passed in (though it will not take ownership of the CompositorFrame | |
| 178 // itself). For successful swaps, the implementation must call | |
| 179 // DidSwapBuffersComplete() (via OnSwapBuffersComplete()) eventually. | |
| 180 virtual void SwapBuffers(CompositorFrame frame) = 0; | |
| 181 virtual void OnSwapBuffersComplete(); | |
| 182 | |
| 183 // This is how LayerTreeHostImpl hears about context loss when the Display | |
| 184 // is the one listening for context loss. Also used internally for the | |
| 185 // context provider to inform the LayerTreeHostImpl or Display about loss. | |
| 186 // It would become display-compositor-only when LayerTreeHostImpl receives | |
| 187 // its contexts independently from the "OutputSurface". | |
| 188 // TODO(danakj): Be private. Subclasses should just call the client directly. | |
| 189 virtual void DidLoseOutputSurface(); | |
| 180 | 190 |
| 181 // base::trace_event::MemoryDumpProvider implementation. | 191 // base::trace_event::MemoryDumpProvider implementation. |
| 182 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 192 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
| 183 base::trace_event::ProcessMemoryDump* pmd) override; | 193 base::trace_event::ProcessMemoryDump* pmd) override; |
| 184 | 194 |
| 185 protected: | 195 protected: |
| 196 // ============== DISPLAY COMPOSITOR ONLY ======================= | |
| 197 | |
| 198 // Used by WebView for the display compositor only. | |
| 199 // TODO(danakj): This should go away, store the state in the subclass that | |
| 200 // uses this. | |
| 201 void SetExternalStencilTest(bool enabled); | |
| 202 | |
| 203 // ============== BOTH TYPES OF COMPOSITOR ====================== | |
| 204 | |
| 205 // This is used by both display and delegating implementations. | |
| 186 void PostSwapBuffersComplete(); | 206 void PostSwapBuffersComplete(); |
| 207 // TODO(danakj): Delete this. Subclasses should just call the client directly. | |
| 208 void SetNeedsRedrawRect(const gfx::Rect& damage_rect); | |
| 209 // TODO(danakj): Delete this. Subclasses should just call the client directly. | |
| 210 void ReclaimResources(const ReturnedResourceArray& resources); | |
| 187 | 211 |
| 188 OutputSurfaceClient* client_ = nullptr; | 212 OutputSurfaceClient* client_ = nullptr; |
| 189 | 213 |
| 190 struct OutputSurface::Capabilities capabilities_; | 214 struct OutputSurface::Capabilities capabilities_; |
| 191 scoped_refptr<ContextProvider> context_provider_; | 215 scoped_refptr<ContextProvider> context_provider_; |
| 192 scoped_refptr<ContextProvider> worker_context_provider_; | 216 scoped_refptr<ContextProvider> worker_context_provider_; |
| 193 scoped_refptr<VulkanContextProvider> vulkan_context_provider_; | 217 scoped_refptr<VulkanContextProvider> vulkan_context_provider_; |
| 194 std::unique_ptr<SoftwareOutputDevice> software_device_; | 218 std::unique_ptr<SoftwareOutputDevice> software_device_; |
| 195 gfx::Size surface_size_; | 219 gfx::Size surface_size_; |
| 196 float device_scale_factor_ = -1; | 220 float device_scale_factor_ = -1; |
| 197 gfx::ColorSpace device_color_space_; | 221 gfx::ColorSpace device_color_space_; |
| 198 bool has_alpha_ = true; | 222 bool has_alpha_ = true; |
| 199 gfx::ColorSpace color_space_; | 223 gfx::ColorSpace color_space_; |
| 200 base::ThreadChecker client_thread_checker_; | 224 base::ThreadChecker client_thread_checker_; |
| 201 | 225 |
| 202 void SetNeedsRedrawRect(const gfx::Rect& damage_rect); | 226 private: |
| 203 void ReclaimResources(const ReturnedResourceArray& resources); | |
| 204 void SetExternalStencilTest(bool enabled); | |
| 205 void DetachFromClientInternal(); | 227 void DetachFromClientInternal(); |
| 206 | 228 |
| 207 private: | |
| 208 bool external_stencil_test_enabled_ = false; | 229 bool external_stencil_test_enabled_ = false; |
| 209 | |
| 210 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; | 230 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; |
| 211 | 231 |
| 212 DISALLOW_COPY_AND_ASSIGN(OutputSurface); | 232 DISALLOW_COPY_AND_ASSIGN(OutputSurface); |
| 213 }; | 233 }; |
| 214 | 234 |
| 215 } // namespace cc | 235 } // namespace cc |
| 216 | 236 |
| 217 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ | 237 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ |
| OLD | NEW |