OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "content/browser/android/in_process/synchronous_compositor_output_surfa
ce.h" | 5 #include "content/browser/android/in_process/synchronous_compositor_output_surfa
ce.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "cc/output/begin_frame_args.h" | 9 #include "cc/output/begin_frame_args.h" |
10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), | 72 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), |
73 routing_id_(routing_id), | 73 routing_id_(routing_id), |
74 needs_begin_frame_(false), | 74 needs_begin_frame_(false), |
75 invoking_composite_(false), | 75 invoking_composite_(false), |
76 current_sw_canvas_(NULL), | 76 current_sw_canvas_(NULL), |
77 memory_policy_(0), | 77 memory_policy_(0), |
78 output_surface_client_(NULL) { | 78 output_surface_client_(NULL) { |
79 capabilities_.deferred_gl_initialization = true; | 79 capabilities_.deferred_gl_initialization = true; |
80 capabilities_.draw_and_swap_full_viewport_every_frame = true; | 80 capabilities_.draw_and_swap_full_viewport_every_frame = true; |
81 capabilities_.adjust_deadline_for_parent = false; | 81 capabilities_.adjust_deadline_for_parent = false; |
82 if (IsDelegatedRendererEnabled()) { | 82 capabilities_.delegated_rendering = true; |
83 capabilities_.delegated_rendering = true; | 83 capabilities_.max_frames_pending = 1; |
84 capabilities_.max_frames_pending = 1; | |
85 } | |
86 // Cannot call out to GetDelegate() here as the output surface is not | 84 // Cannot call out to GetDelegate() here as the output surface is not |
87 // constructed on the correct thread. | 85 // constructed on the correct thread. |
88 | 86 |
89 memory_policy_.priority_cutoff_when_visible = | 87 memory_policy_.priority_cutoff_when_visible = |
90 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | 88 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
91 } | 89 } |
92 | 90 |
93 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { | 91 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { |
94 DCHECK(CalledOnValidThread()); | 92 DCHECK(CalledOnValidThread()); |
95 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 93 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 DCHECK(CalledOnValidThread()); | 130 DCHECK(CalledOnValidThread()); |
133 needs_begin_frame_ = enable; | 131 needs_begin_frame_ = enable; |
134 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 132 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
135 if (delegate && !invoking_composite_) | 133 if (delegate && !invoking_composite_) |
136 delegate->SetContinuousInvalidate(needs_begin_frame_); | 134 delegate->SetContinuousInvalidate(needs_begin_frame_); |
137 } | 135 } |
138 | 136 |
139 void SynchronousCompositorOutputSurface::SwapBuffers( | 137 void SynchronousCompositorOutputSurface::SwapBuffers( |
140 cc::CompositorFrame* frame) { | 138 cc::CompositorFrame* frame) { |
141 DCHECK(CalledOnValidThread()); | 139 DCHECK(CalledOnValidThread()); |
142 if (!ForcedDrawToSoftwareDevice() && !IsDelegatedRendererEnabled()) { | |
143 DCHECK(context_provider_); | |
144 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); | |
145 } | |
146 | 140 |
147 frame_holder_.reset(new cc::CompositorFrame); | 141 frame_holder_.reset(new cc::CompositorFrame); |
148 frame->AssignTo(frame_holder_.get()); | 142 frame->AssignTo(frame_holder_.get()); |
149 | 143 |
150 client_->DidSwapBuffers(); | 144 client_->DidSwapBuffers(); |
151 } | 145 } |
152 | 146 |
153 namespace { | 147 namespace { |
154 void AdjustTransform(gfx::Transform* transform, gfx::Rect viewport) { | 148 void AdjustTransform(gfx::Transform* transform, gfx::Rect viewport) { |
155 // CC's draw origin starts at the viewport. | 149 // CC's draw origin starts at the viewport. |
(...skipping 13 matching lines...) Expand all Loading... |
169 void SynchronousCompositorOutputSurface::ReleaseHwDraw() { | 163 void SynchronousCompositorOutputSurface::ReleaseHwDraw() { |
170 DCHECK(CalledOnValidThread()); | 164 DCHECK(CalledOnValidThread()); |
171 cc::OutputSurface::ReleaseGL(); | 165 cc::OutputSurface::ReleaseGL(); |
172 } | 166 } |
173 | 167 |
174 scoped_ptr<cc::CompositorFrame> | 168 scoped_ptr<cc::CompositorFrame> |
175 SynchronousCompositorOutputSurface::DemandDrawHw( | 169 SynchronousCompositorOutputSurface::DemandDrawHw( |
176 gfx::Size surface_size, | 170 gfx::Size surface_size, |
177 const gfx::Transform& transform, | 171 const gfx::Transform& transform, |
178 gfx::Rect viewport, | 172 gfx::Rect viewport, |
179 gfx::Rect clip, | 173 gfx::Rect clip) { |
180 bool stencil_enabled) { | |
181 DCHECK(CalledOnValidThread()); | 174 DCHECK(CalledOnValidThread()); |
182 DCHECK(HasClient()); | 175 DCHECK(HasClient()); |
183 DCHECK(context_provider_); | 176 DCHECK(context_provider_); |
184 | 177 |
185 surface_size_ = surface_size; | 178 surface_size_ = surface_size; |
186 SetExternalStencilTest(stencil_enabled); | |
187 InvokeComposite(transform, viewport, clip, true); | 179 InvokeComposite(transform, viewport, clip, true); |
188 | 180 |
189 return frame_holder_.Pass(); | 181 return frame_holder_.Pass(); |
190 } | 182 } |
191 | 183 |
192 scoped_ptr<cc::CompositorFrame> | 184 scoped_ptr<cc::CompositorFrame> |
193 SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 185 SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
194 DCHECK(CalledOnValidThread()); | 186 DCHECK(CalledOnValidThread()); |
195 DCHECK(canvas); | 187 DCHECK(canvas); |
196 DCHECK(!current_sw_canvas_); | 188 DCHECK(!current_sw_canvas_); |
197 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); | 189 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); |
198 | 190 |
199 SkIRect canvas_clip; | 191 SkIRect canvas_clip; |
200 canvas->getClipDeviceBounds(&canvas_clip); | 192 canvas->getClipDeviceBounds(&canvas_clip); |
201 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); | 193 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); |
202 | 194 |
203 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 195 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
204 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 196 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
205 | 197 |
206 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), | 198 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), |
207 canvas->getDeviceSize().height()); | 199 canvas->getDeviceSize().height()); |
208 SetExternalStencilTest(false); | |
209 | 200 |
210 InvokeComposite(transform, clip, clip, false); | 201 InvokeComposite(transform, clip, clip, false); |
211 | 202 |
212 return frame_holder_.Pass(); | 203 return frame_holder_.Pass(); |
213 } | 204 } |
214 | 205 |
215 void SynchronousCompositorOutputSurface::InvokeComposite( | 206 void SynchronousCompositorOutputSurface::InvokeComposite( |
216 const gfx::Transform& transform, | 207 const gfx::Transform& transform, |
217 gfx::Rect viewport, | 208 gfx::Rect viewport, |
218 gfx::Rect clip, | 209 gfx::Rect clip, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 260 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
270 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 261 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
271 } | 262 } |
272 | 263 |
273 SynchronousCompositorOutputSurfaceDelegate* | 264 SynchronousCompositorOutputSurfaceDelegate* |
274 SynchronousCompositorOutputSurface::GetDelegate() { | 265 SynchronousCompositorOutputSurface::GetDelegate() { |
275 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 266 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
276 } | 267 } |
277 | 268 |
278 } // namespace content | 269 } // namespace content |
OLD | NEW |