Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: content/browser/android/in_process/synchronous_compositor_output_surface.cc

Issue 20185002: ContextProvider in OutputSurface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: contextprovider: don't access Context3d() in OutputSurface contructors, it's not bound yet Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "cc/output/context_provider.h" 11 #include "cc/output/context_provider.h"
12 #include "cc/output/managed_memory_policy.h" 12 #include "cc/output/managed_memory_policy.h"
13 #include "cc/output/output_surface_client.h" 13 #include "cc/output/output_surface_client.h"
14 #include "cc/output/software_output_device.h" 14 #include "cc/output/software_output_device.h"
15 #include "content/browser/android/in_process/synchronous_compositor_impl.h" 15 #include "content/browser/android/in_process/synchronous_compositor_impl.h"
16 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
17 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
18 #include "gpu/command_buffer/client/gl_in_process_context.h" 17 #include "gpu/command_buffer/client/gl_in_process_context.h"
19 #include "third_party/skia/include/core/SkCanvas.h" 18 #include "third_party/skia/include/core/SkCanvas.h"
20 #include "third_party/skia/include/core/SkDevice.h" 19 #include "third_party/skia/include/core/SkDevice.h"
21 #include "ui/gfx/rect_conversions.h" 20 #include "ui/gfx/rect_conversions.h"
22 #include "ui/gfx/skia_util.h" 21 #include "ui/gfx/skia_util.h"
23 #include "ui/gfx/transform.h" 22 #include "ui/gfx/transform.h"
24 #include "ui/gl/gl_surface.h" 23 #include "ui/gl/gl_surface.h"
24 #include "webkit/common/gpu/context_provider_in_process.h"
25 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" 25 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h"
26 26
27
28 namespace content { 27 namespace content {
29 28
30 namespace { 29 namespace {
31 30
32 scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D( 31 scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl>
33 scoped_refptr<gfx::GLSurface> surface) { 32 CreateWebGraphicsContext3D(scoped_refptr<gfx::GLSurface> surface) {
34 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; 33 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
35 if (!gfx::GLSurface::InitializeOneOff()) 34 if (!gfx::GLSurface::InitializeOneOff())
36 return scoped_ptr<WebKit::WebGraphicsContext3D>(); 35 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>();
37 36
38 const char* allowed_extensions = "*"; 37 const char* allowed_extensions = "*";
39 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; 38 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
40 39
41 WebKit::WebGraphicsContext3D::Attributes attributes; 40 WebKit::WebGraphicsContext3D::Attributes attributes;
42 attributes.antialias = false; 41 attributes.antialias = false;
43 attributes.shareResources = true; 42 attributes.shareResources = true;
44 attributes.noAutomaticFlushes = true; 43 attributes.noAutomaticFlushes = true;
45 44
46 gpu::GLInProcessContextAttribs in_process_attribs; 45 gpu::GLInProcessContextAttribs in_process_attribs;
47 WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes( 46 WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes(
48 attributes, &in_process_attribs); 47 attributes, &in_process_attribs);
49 scoped_ptr<gpu::GLInProcessContext> context( 48 scoped_ptr<gpu::GLInProcessContext> context(
50 gpu::GLInProcessContext::CreateWithSurface(surface, 49 gpu::GLInProcessContext::CreateWithSurface(surface,
51 attributes.shareResources, 50 attributes.shareResources,
52 allowed_extensions, 51 allowed_extensions,
53 in_process_attribs, 52 in_process_attribs,
54 gpu_preference)); 53 gpu_preference));
55 54
56 if (!context.get()) 55 if (!context.get())
57 return scoped_ptr<WebKit::WebGraphicsContext3D>(); 56 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>();
58 57
59 return scoped_ptr<WebKit::WebGraphicsContext3D>( 58 return WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext(
60 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( 59 context.Pass(), attributes).Pass();
61 context.Pass(), attributes));
62 } 60 }
63 61
64 void DidActivatePendingTree(int routing_id) { 62 void DidActivatePendingTree(int routing_id) {
65 SynchronousCompositorOutputSurfaceDelegate* delegate = 63 SynchronousCompositorOutputSurfaceDelegate* delegate =
66 SynchronousCompositorImpl::FromRoutingID(routing_id); 64 SynchronousCompositorImpl::FromRoutingID(routing_id);
67 if (delegate) 65 if (delegate)
68 delegate->DidActivatePendingTree(); 66 delegate->DidActivatePendingTree();
69 } 67 }
70 68
71 } // namespace 69 } // namespace
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 cc::OutputSurface::SetNeedsBeginFrame(enable); 167 cc::OutputSurface::SetNeedsBeginFrame(enable);
170 needs_begin_frame_ = enable; 168 needs_begin_frame_ = enable;
171 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); 169 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate();
172 if (delegate) 170 if (delegate)
173 delegate->SetContinuousInvalidate(needs_begin_frame_); 171 delegate->SetContinuousInvalidate(needs_begin_frame_);
174 } 172 }
175 173
176 void SynchronousCompositorOutputSurface::SwapBuffers( 174 void SynchronousCompositorOutputSurface::SwapBuffers(
177 cc::CompositorFrame* frame) { 175 cc::CompositorFrame* frame) {
178 if (!ForcedDrawToSoftwareDevice()) { 176 if (!ForcedDrawToSoftwareDevice()) {
179 DCHECK(context3d()); 177 DCHECK(context_provider_);
180 context3d()->shallowFlushCHROMIUM(); 178 context_provider_->Context3d()->shallowFlushCHROMIUM();
181 } 179 }
182 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); 180 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate();
183 if (delegate) 181 if (delegate)
184 delegate->UpdateFrameMetaData(frame->metadata); 182 delegate->UpdateFrameMetaData(frame->metadata);
185 183
186 did_swap_buffer_ = true; 184 did_swap_buffer_ = true;
187 DidSwapBuffers(); 185 DidSwapBuffers();
188 } 186 }
189 187
190 namespace { 188 namespace {
191 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { 189 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) {
192 // The system-provided transform translates us from the screen origin to the 190 // The system-provided transform translates us from the screen origin to the
193 // origin of the clip rect, but CC's draw origin starts at the clip. 191 // origin of the clip rect, but CC's draw origin starts at the clip.
194 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0); 192 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0);
195 } 193 }
196 } // namespace 194 } // namespace
197 195
198 bool SynchronousCompositorOutputSurface::InitializeHwDraw( 196 bool SynchronousCompositorOutputSurface::InitializeHwDraw(
199 scoped_refptr<gfx::GLSurface> surface, 197 scoped_refptr<gfx::GLSurface> surface,
200 scoped_refptr<cc::ContextProvider> offscreen_context) { 198 scoped_refptr<cc::ContextProvider> offscreen_context_provider) {
201 DCHECK(CalledOnValidThread()); 199 DCHECK(CalledOnValidThread());
202 DCHECK(HasClient()); 200 DCHECK(HasClient());
203 DCHECK(!context3d_); 201 DCHECK(!context_provider_);
204 DCHECK(surface); 202 DCHECK(surface);
205 203
206 return InitializeAndSetContext3D( 204 scoped_refptr<cc::ContextProvider> onscreen_context_provider =
207 CreateWebGraphicsContext3D(surface).Pass(), offscreen_context); 205 webkit::gpu::ContextProviderInProcess::Create(
206 base::Bind(&CreateWebGraphicsContext3D, surface));
207 return InitializeAndSetContext3d(onscreen_context_provider,
208 offscreen_context_provider);
208 } 209 }
209 210
210 void SynchronousCompositorOutputSurface::ReleaseHwDraw() { 211 void SynchronousCompositorOutputSurface::ReleaseHwDraw() {
211 cc::OutputSurface::ReleaseGL(); 212 cc::OutputSurface::ReleaseGL();
212 } 213 }
213 214
214 bool SynchronousCompositorOutputSurface::DemandDrawHw( 215 bool SynchronousCompositorOutputSurface::DemandDrawHw(
215 gfx::Size surface_size, 216 gfx::Size surface_size,
216 const gfx::Transform& transform, 217 const gfx::Transform& transform,
217 gfx::Rect clip, 218 gfx::Rect clip,
218 bool stencil_enabled) { 219 bool stencil_enabled) {
219 DCHECK(CalledOnValidThread()); 220 DCHECK(CalledOnValidThread());
220 DCHECK(HasClient()); 221 DCHECK(HasClient());
221 DCHECK(context3d()); 222 DCHECK(context_provider_);
222 223
223 gfx::Transform adjusted_transform = transform; 224 gfx::Transform adjusted_transform = transform;
224 AdjustTransformForClip(&adjusted_transform, clip); 225 AdjustTransformForClip(&adjusted_transform, clip);
225 surface_size_ = surface_size; 226 surface_size_ = surface_size;
226 SetExternalDrawConstraints(adjusted_transform, clip); 227 SetExternalDrawConstraints(adjusted_transform, clip);
227 SetExternalStencilTest(stencil_enabled); 228 SetExternalStencilTest(stencil_enabled);
228 InvokeComposite(clip.size()); 229 InvokeComposite(clip.size());
229 230
230 return did_swap_buffer_; 231 return did_swap_buffer_;
231 } 232 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 279 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
279 return BrowserThread::CurrentlyOn(BrowserThread::UI); 280 return BrowserThread::CurrentlyOn(BrowserThread::UI);
280 } 281 }
281 282
282 SynchronousCompositorOutputSurfaceDelegate* 283 SynchronousCompositorOutputSurfaceDelegate*
283 SynchronousCompositorOutputSurface::GetDelegate() { 284 SynchronousCompositorOutputSurface::GetDelegate() {
284 return SynchronousCompositorImpl::FromRoutingID(routing_id_); 285 return SynchronousCompositorImpl::FromRoutingID(routing_id_);
285 } 286 }
286 287
287 } // namespace content 288 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698