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

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: 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 "cc/input/input_handler.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/public/renderer/android/synchronous_compositor_client.h"
14 #include "content/public/renderer/content_renderer_client.h"
15
16 namespace content {
17
18 namespace {
19
20
21 int GetInProcessRendererId() {
22 content::RenderProcessHost::iterator it =
23 content::RenderProcessHost::AllHostsIterator();
24 if (it.IsAtEnd()) {
25 // There should always be one RPH in single process more.
26 NOTREACHED();
27 return 0;
28 }
29
30 int id = it.GetCurrentValue()->GetID();
31 it.Advance();
32 DCHECK(it.IsAtEnd()); // Not multiprocess compatible.
33 return id;
34 }
35
36 class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory {
37 public:
38 // SynchronousCompositorFactory
39 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurfaceForRenderView(
40 int view_id) {
41 scoped_ptr<SynchronousCompositorOutputSurface> output_surface(
42 new SynchronousCompositorOutputSurface(view_id));
43 return output_surface.PassAs<cc::OutputSurface>();
44 }
45 };
46
47 base::LazyInstance<SynchronousCompositorFactoryImpl> g_factory =
48 LAZY_INSTANCE_INITIALIZER;
49
50 } // namespace
51
52 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SynchronousCompositorImpl);
53
54 void SynchronousCompositorImpl::InitFactory() {
55 SynchronousCompositorFactory::SetInstance(g_factory.GetPointer());
56 }
57
58 // static
59 void SynchronousCompositorImpl::DidBindOutputSurface(
60 int routing_id,
61 SynchronousCompositorOutputSurface* output_surface) {
62 RenderViewHost* rvh = RenderViewHost::FromID(GetInProcessRendererId(),
63 routing_id);
64 if (!rvh)
65 return;
66 WebContents* contents = WebContents::FromRenderViewHost(rvh);
67 if (!contents)
68 return;
69 SynchronousCompositorImpl::FromContents(contents)->
70 DidBindOutputSurface(output_surface);
71 }
72
73 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents)
74 : compositor_client_(NULL),
75 output_surface_(NULL),
76 contents_(contents) {
77 }
78
79 SynchronousCompositorImpl::~SynchronousCompositorImpl() {
80 if (output_surface_)
81 output_surface_->SetDelegate(NULL);
82 }
83
84 bool SynchronousCompositorImpl::IsHwReady() {
85 DCHECK(CalledOnValidThread());
86 DCHECK(output_surface_);
87
88 return output_surface_->IsHwReady();
89 }
90
91 void SynchronousCompositorImpl::SetClient(
92 SynchronousCompositorClient* compositor_client) {
93 DCHECK(CalledOnValidThread());
94 compositor_client_ = compositor_client;
95 }
96
97 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) {
98 DCHECK(CalledOnValidThread());
99 DCHECK(output_surface_);
100
101 return output_surface_->DemandDrawSw(canvas);
102 }
103
104 bool SynchronousCompositorImpl::DemandDrawHw(
105 gfx::Size view_size,
106 const gfx::Transform& transform,
107 gfx::Rect damage_area) {
108 DCHECK(CalledOnValidThread());
109 DCHECK(output_surface_);
110
111 return output_surface_->DemandDrawHw(view_size, transform, damage_area);
112 }
113
114 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) {
115 DCHECK(CalledOnValidThread());
116 if (compositor_client_)
117 compositor_client_->SetContinuousInvalidate(enable);
118 }
119
120 void SynchronousCompositorImpl::DidCreateSynchronousOutputSurface(
121 SynchronousCompositorOutputSurface* output_surface);
122 DCHECK(CalledOnValidThread());
123 output_surface_ = output_surface;
124 output_surface->SetDelegate(this);
125 // TODO(joth): Migrate this up-call off of the Renderer Client.
126 GetContentClient()->renderer()->DidCreateSynchronousCompositor(
127 contents_->GetRenderViewHost()->GetRoutingID(), this)l
128 }
129
130 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface() {
131 DCHECK(CalledOnValidThread());
132 output_surface_ = NULL;
133 if (compositor_client_)
134 compositor_client_->DidDestroyCompositor(this);
135 }
136
137 // Not using base::NonThreadSafe as we want to enforce a more exacting threading
138 // requirement: SynchronousCompositorImpl() must only be used on the UI thread.
139 bool SynchronousCompositorImpl::CalledOnValidThread() const {
140 return BrowserThread::CurrentlyOn(BrowserThread::UI);
141 }
142
143 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698