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

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

Issue 15851006: Move synchronous compositor into content/browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mkosiba comments1 Created 7 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/android/in_process/synchronous_compositor_impl.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/message_loop.h"
9 #include "content/public/browser/android/synchronous_compositor_client.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/renderer/android/synchronous_compositor_factory.h"
14
15 namespace content {
16
17 namespace {
18
19 int GetInProcessRendererId() {
20 content::RenderProcessHost::iterator it =
21 content::RenderProcessHost::AllHostsIterator();
22 if (it.IsAtEnd()) {
23 // There should always be one RPH in single process mode.
24 NOTREACHED();
25 return 0;
26 }
27
28 int id = it.GetCurrentValue()->GetID();
29 it.Advance();
30 DCHECK(it.IsAtEnd()); // Not multiprocess compatible.
31 return id;
32 }
33
34 class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory {
35 public:
36 // SynchronousCompositorFactory
37 virtual scoped_refptr<base::MessageLoopProxy>
38 GetCompositorMessageLoop() OVERRIDE {
39 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
40 }
41
42 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(
43 int routing_id) OVERRIDE {
44 scoped_ptr<SynchronousCompositorOutputSurface> output_surface(
45 new SynchronousCompositorOutputSurface(routing_id));
46 return output_surface.PassAs<cc::OutputSurface>();
47 }
48 };
49
50 base::LazyInstance<SynchronousCompositorFactoryImpl>::Leaky g_factory =
51 LAZY_INSTANCE_INITIALIZER;
52
53 } // namespace
54
55 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SynchronousCompositorImpl);
56
57 // static
58 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID(
59 int routing_id) {
60 RenderViewHost* rvh = RenderViewHost::FromID(GetInProcessRendererId(),
61 routing_id);
62 if (!rvh)
63 return NULL;
64 WebContents* contents = WebContents::FromRenderViewHost(rvh);
65 if (!contents)
66 return NULL;
67 return FromWebContents(contents);
68 }
69
70 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents)
71 : compositor_client_(NULL),
72 output_surface_(NULL),
73 contents_(contents) {
74 }
75
76 SynchronousCompositorImpl::~SynchronousCompositorImpl() {
77 if (compositor_client_)
78 compositor_client_->DidDestroyCompositor(this);
79 }
80
81 bool SynchronousCompositorImpl::IsHwReady() {
82 DCHECK(CalledOnValidThread());
83 DCHECK(output_surface_);
84
85 return output_surface_->IsHwReady();
86 }
87
88 void SynchronousCompositorImpl::SetClient(
89 SynchronousCompositorClient* compositor_client) {
90 DCHECK(CalledOnValidThread());
91 compositor_client_ = compositor_client;
92 }
93
94 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) {
95 DCHECK(CalledOnValidThread());
96 DCHECK(output_surface_);
97
98 return output_surface_->DemandDrawSw(canvas);
99 }
100
101 bool SynchronousCompositorImpl::DemandDrawHw(
102 gfx::Size view_size,
103 const gfx::Transform& transform,
104 gfx::Rect damage_area) {
105 DCHECK(CalledOnValidThread());
106 DCHECK(output_surface_);
107
108 return output_surface_->DemandDrawHw(view_size, transform, damage_area);
109 }
110
111 void SynchronousCompositorImpl::DidBindOutputSurface(
112 SynchronousCompositorOutputSurface* output_surface) {
113 DCHECK(CalledOnValidThread());
114 output_surface_ = output_surface;
115 if (compositor_client_)
116 compositor_client_->DidInitializeCompositor(this);
117 }
118
119 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface(
120 SynchronousCompositorOutputSurface* output_surface) {
121 DCHECK(CalledOnValidThread());
122 // Allow for transient hand-over when two output surfaces may refer to
123 // a single delegate.
124 if (output_surface_ == output_surface) {
125 output_surface_ = NULL;
126 if (compositor_client_)
127 compositor_client_->DidDestroyCompositor(this);
128 compositor_client_ = NULL;
129 }
130 }
131
132 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) {
133 DCHECK(CalledOnValidThread());
134 if (compositor_client_)
135 compositor_client_->SetContinuousInvalidate(enable);
136 }
137
138 // Not using base::NonThreadSafe as we want to enforce a more exacting threading
139 // requirement: SynchronousCompositorImpl() must only be used on the UI thread.
140 bool SynchronousCompositorImpl::CalledOnValidThread() const {
141 return BrowserThread::CurrentlyOn(BrowserThread::UI);
142 }
143
144 // static
145 void SynchronousCompositor::Init() {
146 SynchronousCompositorFactory::SetInstance(g_factory.Pointer());
147 }
148
149 // static
150 SynchronousCompositor* SynchronousCompositor::GetOrCreateForWebContents(
151 WebContents* contents) {
152 SynchronousCompositorImpl::CreateForWebContents(contents);
153 return SynchronousCompositorImpl::FromWebContents(contents);
154 }
155
156 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698