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

Side by Side Diff: content/renderer/android/synchronous_compositor_output_surface.cc

Issue 14888002: Android WebView Merged-Thread Hardware Draw (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/renderer/android/synchronous_compositor_output_surface.h" 5 #include "content/renderer/android/synchronous_compositor_output_surface.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/time.h"
8 #include "cc/output/output_surface_client.h" 9 #include "cc/output/output_surface_client.h"
9 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
10 #include "content/public/renderer/android/synchronous_compositor_client.h" 10 #include "content/public/renderer/android/synchronous_compositor_client.h"
11 #include "content/public/renderer/content_renderer_client.h" 11 #include "content/public/renderer/content_renderer_client.h"
12 #include "skia/ext/refptr.h" 12 #include "skia/ext/refptr.h"
13 #include "third_party/skia/include/core/SkCanvas.h" 13 #include "third_party/skia/include/core/SkCanvas.h"
14 #include "third_party/skia/include/core/SkPicture.h" 14 #include "third_party/skia/include/core/SkPicture.h"
15 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
16
17 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
15 18
16 namespace content { 19 namespace content {
20 namespace {
21
22 // TODO(boliu): RenderWidgetImpl should create in process contexts as well.
joth 2013/05/03 01:26:26 should it?
boliu 2013/05/03 05:25:50 Oops, should have said RenderThreadImpl, which cre
23 scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D() {
24 WebKit::WebGraphicsContext3D::Attributes attributes;
25 attributes.antialias = false;
26 attributes.shareResources = true;
27 attributes.noAutomaticFlushes = true;
28
29 return scoped_ptr<WebKit::WebGraphicsContext3D>(
30 WebGraphicsContext3DInProcessCommandBufferImpl
31 ::CreateViewContext(attributes, NULL));
32 }
33 } // namespace
17 34
18 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( 35 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface(
19 int32 routing_id, 36 int32 routing_id)
20 WebGraphicsContext3DCommandBufferImpl* context) 37 : cc::OutputSurface(CreateWebGraphicsContext3D()),
21 : cc::OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>(context)),
22 compositor_client_(NULL), 38 compositor_client_(NULL),
23 routing_id_(routing_id) { 39 routing_id_(routing_id) {
24 // WARNING: may be called on any thread.
25 } 40 }
26 41
27 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { 42 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() {
28 DCHECK(CalledOnValidThread()); 43 DCHECK(CalledOnValidThread());
29 if (compositor_client_) 44 if (compositor_client_)
30 compositor_client_->DidDestroyCompositor(this); 45 compositor_client_->DidDestroyCompositor(this);
31 } 46 }
32 47
33 bool SynchronousCompositorOutputSurface::BindToClient( 48 bool SynchronousCompositorOutputSurface::BindToClient(
34 cc::OutputSurfaceClient* surface_client) { 49 cc::OutputSurfaceClient* surface_client) {
35 DCHECK(CalledOnValidThread()); 50 DCHECK(CalledOnValidThread());
36 if (!cc::OutputSurface::BindToClient(surface_client)) 51 if (!cc::OutputSurface::BindToClient(surface_client))
37 return false; 52 return false;
38 GetContentClient()->renderer()->DidCreateSynchronousCompositor(routing_id_, 53 GetContentClient()->renderer()->DidCreateSynchronousCompositor(routing_id_,
39 this); 54 this);
40 return true; 55 return true;
41 } 56 }
42 57
58 void SynchronousCompositorOutputSurface::Reshape(gfx::Size size) {
59 // Intentional no-op.
60 }
61
43 void SynchronousCompositorOutputSurface::SendFrameToParentCompositor( 62 void SynchronousCompositorOutputSurface::SendFrameToParentCompositor(
44 cc::CompositorFrame* frame) { 63 cc::CompositorFrame* frame) {
45 // Intentional no-op: see http://crbug.com/237006 64 // Intentional no-op: see http://crbug.com/237006
46 } 65 }
47 66
67 void SynchronousCompositorOutputSurface::EnableVSyncNotification(
68 bool enable_vsync) {
69 DCHECK(CalledOnValidThread());
70 vsync_enabled_ = enable_vsync;
71 UpdateCompositorClientSettings();
72 }
73
74 void SynchronousCompositorOutputSurface::SwapBuffers(
75 const cc::LatencyInfo& info) {
76 context3d()->finish();
77 }
78
48 void SynchronousCompositorOutputSurface::SetClient( 79 void SynchronousCompositorOutputSurface::SetClient(
49 SynchronousCompositorClient* compositor_client) { 80 SynchronousCompositorClient* compositor_client) {
50 DCHECK(CalledOnValidThread()); 81 DCHECK(CalledOnValidThread());
51 compositor_client_ = compositor_client; 82 compositor_client_ = compositor_client;
83 UpdateCompositorClientSettings();
52 } 84 }
53 85
54 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { 86 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) {
55 DCHECK(CalledOnValidThread()); 87 DCHECK(CalledOnValidThread());
56 NOTIMPLEMENTED(); // TODO(joth): call through to OutputSurfaceClient 88 NOTIMPLEMENTED(); // TODO(joth): call through to OutputSurfaceClient
57 return false; 89 return false;
58 } 90 }
59 91
92 void SynchronousCompositorOutputSurface::DemandDrawHw(gfx::Rect damage_rect) {
93 DCHECK(CalledOnValidThread());
94 DCHECK(client_);
95
96 client_->SetNeedsRedrawRect(damage_rect);
97 if (vsync_enabled_)
98 client_->DidVSync(base::TimeTicks::Now());
99
100 // This is used to make sure that the GLContextVirtual used by the compositor
101 // restores its state.
102 static scoped_ptr<WebKit::WebGraphicsContext3D> background_context =
103 CreateWebGraphicsContext3D();
104 background_context->makeContextCurrent();
105 }
106
107 void SynchronousCompositorOutputSurface::UpdateCompositorClientSettings() {
108 if (compositor_client_) {
109 compositor_client_->SetContinuousInvalidate(vsync_enabled_);
joth 2013/05/03 01:26:26 makes me sad that the 'vsync_enabled_ state is dup
110 }
111 }
112
60 // Not using base::NonThreadSafe as we want to enforce a more exacting threading 113 // Not using base::NonThreadSafe as we want to enforce a more exacting threading
61 // requirement: SynchronousCompositorOutputSurface() must only be used by 114 // requirement: SynchronousCompositorOutputSurface() must only be used by
62 // embedders that supply their own compositor loop via 115 // embedders that supply their own compositor loop via
63 // OverrideCompositorMessageLoop(). 116 // OverrideCompositorMessageLoop().
64 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 117 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
65 return base::MessageLoop::current() && (base::MessageLoop::current() == 118 return base::MessageLoop::current() && (base::MessageLoop::current() ==
66 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); 119 GetContentClient()->renderer()->OverrideCompositorMessageLoop());
67 } 120 }
68 121
69 } // namespace content 122 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698