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

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: address comments 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.
jamesr 2013/05/03 19:46:51 What's RenderWidgetImpl?
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. 40 did_swap_buffer_(false) {
25 } 41 }
26 42
27 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { 43 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() {
28 DCHECK(CalledOnValidThread()); 44 DCHECK(CalledOnValidThread());
29 if (compositor_client_) 45 if (compositor_client_)
30 compositor_client_->DidDestroyCompositor(this); 46 compositor_client_->DidDestroyCompositor(this);
31 } 47 }
32 48
33 bool SynchronousCompositorOutputSurface::BindToClient( 49 bool SynchronousCompositorOutputSurface::BindToClient(
34 cc::OutputSurfaceClient* surface_client) { 50 cc::OutputSurfaceClient* surface_client) {
35 DCHECK(CalledOnValidThread()); 51 DCHECK(CalledOnValidThread());
36 if (!cc::OutputSurface::BindToClient(surface_client)) 52 if (!cc::OutputSurface::BindToClient(surface_client))
37 return false; 53 return false;
38 GetContentClient()->renderer()->DidCreateSynchronousCompositor(routing_id_, 54 GetContentClient()->renderer()->DidCreateSynchronousCompositor(routing_id_,
39 this); 55 this);
40 return true; 56 return true;
41 } 57 }
42 58
59 void SynchronousCompositorOutputSurface::Reshape(gfx::Size size) {
60 // Intentional no-op.
61 }
62
43 void SynchronousCompositorOutputSurface::SendFrameToParentCompositor( 63 void SynchronousCompositorOutputSurface::SendFrameToParentCompositor(
44 cc::CompositorFrame* frame) { 64 cc::CompositorFrame* frame) {
45 // Intentional no-op: see http://crbug.com/237006 65 // Intentional no-op: see http://crbug.com/237006
46 } 66 }
47 67
68 void SynchronousCompositorOutputSurface::EnableVSyncNotification(
69 bool enable_vsync) {
70 DCHECK(CalledOnValidThread());
71 vsync_enabled_ = enable_vsync;
72 UpdateCompositorClientSettings();
73 }
74
75 void SynchronousCompositorOutputSurface::SwapBuffers(
76 const cc::LatencyInfo& info) {
77 context3d()->finish();
78 did_swap_buffer_ = true;
79 }
80
48 void SynchronousCompositorOutputSurface::SetClient( 81 void SynchronousCompositorOutputSurface::SetClient(
49 SynchronousCompositorClient* compositor_client) { 82 SynchronousCompositorClient* compositor_client) {
50 DCHECK(CalledOnValidThread()); 83 DCHECK(CalledOnValidThread());
51 compositor_client_ = compositor_client; 84 compositor_client_ = compositor_client;
85 UpdateCompositorClientSettings();
52 } 86 }
53 87
54 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { 88 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) {
55 DCHECK(CalledOnValidThread()); 89 DCHECK(CalledOnValidThread());
56 NOTIMPLEMENTED(); // TODO(joth): call through to OutputSurfaceClient 90 NOTIMPLEMENTED(); // TODO(joth): call through to OutputSurfaceClient
57 return false; 91 return false;
58 } 92 }
59 93
94 bool SynchronousCompositorOutputSurface::DemandDrawHw(gfx::Rect damage_rect) {
95 DCHECK(CalledOnValidThread());
96 DCHECK(client_);
97
98 did_swap_buffer_ = false;
99 client_->SetNeedsRedrawRect(damage_rect);
100 if (vsync_enabled_)
101 client_->DidVSync(base::TimeTicks::Now());
102
103 // This is used to make sure that the GLContextVirtual used by the compositor
104 // restores its state.
105 static scoped_ptr<WebKit::WebGraphicsContext3D> background_context =
106 CreateWebGraphicsContext3D();
107 background_context->makeContextCurrent();
108
109 return did_swap_buffer_;
110 }
111
112 void SynchronousCompositorOutputSurface::UpdateCompositorClientSettings() {
113 if (compositor_client_) {
114 compositor_client_->SetContinuousInvalidate(vsync_enabled_);
115 }
116 }
117
60 // Not using base::NonThreadSafe as we want to enforce a more exacting threading 118 // Not using base::NonThreadSafe as we want to enforce a more exacting threading
61 // requirement: SynchronousCompositorOutputSurface() must only be used by 119 // requirement: SynchronousCompositorOutputSurface() must only be used by
62 // embedders that supply their own compositor loop via 120 // embedders that supply their own compositor loop via
63 // OverrideCompositorMessageLoop(). 121 // OverrideCompositorMessageLoop().
64 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 122 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
65 return base::MessageLoop::current() && (base::MessageLoop::current() == 123 return base::MessageLoop::current() && (base::MessageLoop::current() ==
66 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); 124 GetContentClient()->renderer()->OverrideCompositorMessageLoop());
67 } 125 }
68 126
69 } // namespace content 127 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/android/synchronous_compositor_output_surface.h ('k') | content/renderer/render_widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698