| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CC_OUTPUT_OUTPUT_SURFACE_H_ | |
| 6 #define CC_OUTPUT_OUTPUT_SURFACE_H_ | |
| 7 | |
| 8 #include <deque> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "cc/output/context_provider.h" | |
| 15 #include "cc/output/overlay_candidate_validator.h" | |
| 16 #include "cc/output/software_output_device.h" | |
| 17 | |
| 18 namespace base { class SingleThreadTaskRunner; } | |
| 19 | |
| 20 namespace ui { struct LatencyInfo; } | |
| 21 | |
| 22 namespace gfx { | |
| 23 class Rect; | |
| 24 class Size; | |
| 25 class Transform; | |
| 26 } | |
| 27 | |
| 28 namespace cc { | |
| 29 | |
| 30 class CompositorFrame; | |
| 31 class CompositorFrameAck; | |
| 32 class OutputSurfaceClient; | |
| 33 | |
| 34 // Represents the output surface for a compositor. The compositor owns | |
| 35 // and manages its destruction. Its lifetime is: | |
| 36 // 1. Created on the main thread by the LayerTreeHost through its client. | |
| 37 // 2. Passed to the compositor thread and bound to a client via BindToClient. | |
| 38 // From here on, it will only be used on the compositor thread. | |
| 39 // 3. If the 3D context is lost, then the compositor will delete the output | |
| 40 // surface (on the compositor thread) and go back to step 1. | |
| 41 class OutputSurface { | |
| 42 public: | |
| 43 enum { | |
| 44 DEFAULT_MAX_FRAMES_PENDING = 2 | |
| 45 }; | |
| 46 | |
| 47 OutputSurface(const scoped_refptr<ContextProvider>& context_provider, | |
| 48 const scoped_refptr<ContextProvider>& worker_context_provider, | |
| 49 scoped_ptr<SoftwareOutputDevice> software_device); | |
| 50 OutputSurface(const scoped_refptr<ContextProvider>& context_provider, | |
| 51 const scoped_refptr<ContextProvider>& worker_context_provider); | |
| 52 explicit OutputSurface( | |
| 53 const scoped_refptr<ContextProvider>& context_provider); | |
| 54 | |
| 55 explicit OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device); | |
| 56 | |
| 57 OutputSurface(const scoped_refptr<ContextProvider>& context_provider, | |
| 58 scoped_ptr<SoftwareOutputDevice> software_device); | |
| 59 | |
| 60 virtual ~OutputSurface(); | |
| 61 | |
| 62 struct Capabilities { | |
| 63 Capabilities() | |
| 64 : delegated_rendering(false), | |
| 65 max_frames_pending(0), | |
| 66 deferred_gl_initialization(false), | |
| 67 draw_and_swap_full_viewport_every_frame(false), | |
| 68 adjust_deadline_for_parent(true), | |
| 69 uses_default_gl_framebuffer(true), | |
| 70 flipped_output_surface(false), | |
| 71 can_force_reclaim_resources(false) {} | |
| 72 bool delegated_rendering; | |
| 73 int max_frames_pending; | |
| 74 bool deferred_gl_initialization; | |
| 75 bool draw_and_swap_full_viewport_every_frame; | |
| 76 // This doesn't handle the <webview> case, but once BeginFrame is | |
| 77 // supported natively, we shouldn't need adjust_deadline_for_parent. | |
| 78 bool adjust_deadline_for_parent; | |
| 79 // Whether this output surface renders to the default OpenGL zero | |
| 80 // framebuffer or to an offscreen framebuffer. | |
| 81 bool uses_default_gl_framebuffer; | |
| 82 // Whether this OutputSurface is flipped or not. | |
| 83 bool flipped_output_surface; | |
| 84 // Whether ForceReclaimResources can be called to reclaim all resources | |
| 85 // from the OutputSurface. | |
| 86 bool can_force_reclaim_resources; | |
| 87 }; | |
| 88 | |
| 89 const Capabilities& capabilities() const { | |
| 90 return capabilities_; | |
| 91 } | |
| 92 | |
| 93 virtual bool HasExternalStencilTest() const; | |
| 94 | |
| 95 // Obtain the 3d context or the software device associated with this output | |
| 96 // surface. Either of these may return a null pointer, but not both. | |
| 97 // In the event of a lost context, the entire output surface should be | |
| 98 // recreated. | |
| 99 ContextProvider* context_provider() const { return context_provider_.get(); } | |
| 100 ContextProvider* worker_context_provider() const { | |
| 101 return worker_context_provider_.get(); | |
| 102 } | |
| 103 SoftwareOutputDevice* software_device() const { | |
| 104 return software_device_.get(); | |
| 105 } | |
| 106 | |
| 107 // Called by the compositor on the compositor thread. This is a place where | |
| 108 // thread-specific data for the output surface can be initialized, since from | |
| 109 // this point on the output surface will only be used on the compositor | |
| 110 // thread. | |
| 111 virtual bool BindToClient(OutputSurfaceClient* client); | |
| 112 | |
| 113 // This is called by the compositor on the compositor thread inside ReleaseGL | |
| 114 // in order to release the ContextProvider. Only used with | |
| 115 // deferred_gl_initialization capability. | |
| 116 void ReleaseContextProvider(); | |
| 117 | |
| 118 virtual void EnsureBackbuffer(); | |
| 119 virtual void DiscardBackbuffer(); | |
| 120 | |
| 121 virtual void Reshape(const gfx::Size& size, float scale_factor); | |
| 122 virtual gfx::Size SurfaceSize() const; | |
| 123 | |
| 124 // If supported, this causes a ReclaimResources for all resources that are | |
| 125 // currently in use. | |
| 126 virtual void ForceReclaimResources() {} | |
| 127 | |
| 128 virtual void BindFramebuffer(); | |
| 129 | |
| 130 // The implementation may destroy or steal the contents of the CompositorFrame | |
| 131 // passed in (though it will not take ownership of the CompositorFrame | |
| 132 // itself). For successful swaps, the implementation must call | |
| 133 // OutputSurfaceClient::DidSwapBuffers() and eventually | |
| 134 // DidSwapBuffersComplete(). | |
| 135 virtual void SwapBuffers(CompositorFrame* frame) = 0; | |
| 136 virtual void OnSwapBuffersComplete(); | |
| 137 | |
| 138 // Notifies frame-rate smoothness preference. If true, all non-critical | |
| 139 // processing should be stopped, or lowered in priority. | |
| 140 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {} | |
| 141 | |
| 142 bool HasClient() { return !!client_; } | |
| 143 | |
| 144 // Get the class capable of informing cc of hardware overlay capability. | |
| 145 OverlayCandidateValidator* overlay_candidate_validator() const { | |
| 146 return overlay_candidate_validator_.get(); | |
| 147 } | |
| 148 | |
| 149 void DidLoseOutputSurface(); | |
| 150 | |
| 151 protected: | |
| 152 OutputSurfaceClient* client_; | |
| 153 | |
| 154 // Synchronously initialize context3d and enter hardware mode. | |
| 155 // This can only supported in threaded compositing mode. | |
| 156 bool InitializeAndSetContext3d( | |
| 157 scoped_refptr<ContextProvider> context_provider, | |
| 158 scoped_refptr<ContextProvider> worker_context_provider); | |
| 159 void ReleaseGL(); | |
| 160 | |
| 161 void PostSwapBuffersComplete(); | |
| 162 | |
| 163 struct OutputSurface::Capabilities capabilities_; | |
| 164 scoped_refptr<ContextProvider> context_provider_; | |
| 165 scoped_refptr<ContextProvider> worker_context_provider_; | |
| 166 scoped_ptr<SoftwareOutputDevice> software_device_; | |
| 167 scoped_ptr<OverlayCandidateValidator> overlay_candidate_validator_; | |
| 168 gfx::Size surface_size_; | |
| 169 float device_scale_factor_; | |
| 170 | |
| 171 void CommitVSyncParameters(base::TimeTicks timebase, | |
| 172 base::TimeDelta interval); | |
| 173 | |
| 174 void SetNeedsRedrawRect(const gfx::Rect& damage_rect); | |
| 175 void ReclaimResources(const CompositorFrameAck* ack); | |
| 176 void SetExternalStencilTest(bool enabled); | |
| 177 void SetExternalDrawConstraints( | |
| 178 const gfx::Transform& transform, | |
| 179 const gfx::Rect& viewport, | |
| 180 const gfx::Rect& clip, | |
| 181 const gfx::Rect& viewport_rect_for_tile_priority, | |
| 182 const gfx::Transform& transform_for_tile_priority, | |
| 183 bool resourceless_software_draw); | |
| 184 | |
| 185 private: | |
| 186 void SetUpContext3d(); | |
| 187 void ResetContext3d(); | |
| 188 | |
| 189 bool external_stencil_test_enabled_; | |
| 190 | |
| 191 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; | |
| 192 | |
| 193 DISALLOW_COPY_AND_ASSIGN(OutputSurface); | |
| 194 }; | |
| 195 | |
| 196 } // namespace cc | |
| 197 | |
| 198 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ | |
| OLD | NEW |