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

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

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

Powered by Google App Engine
This is Rietveld 408576698