Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/browser/android/in_process/synchronous_compositor_impl.h" | 5 #include "content/browser/android/in_process/synchronous_compositor_impl.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "cc/input/layer_scroll_offset_delegate.h" | |
| 9 #include "content/public/browser/android/synchronous_compositor_client.h" | 10 #include "content/public/browser/android/synchronous_compositor_client.h" |
| 10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
| 12 #include "content/public/browser/render_view_host.h" | 13 #include "content/public/browser/render_view_host.h" |
| 13 #include "content/renderer/android/synchronous_compositor_factory.h" | 14 #include "content/renderer/android/synchronous_compositor_factory.h" |
| 15 #include "content/renderer/gpu/input_handler_manager.h" | |
| 16 #include "content/renderer/render_thread_impl.h" | |
| 14 | 17 |
| 15 namespace content { | 18 namespace content { |
| 16 | 19 |
| 17 namespace { | 20 namespace { |
| 18 | 21 |
| 19 int GetInProcessRendererId() { | 22 int GetInProcessRendererId() { |
| 20 content::RenderProcessHost::iterator it = | 23 content::RenderProcessHost::iterator it = |
| 21 content::RenderProcessHost::AllHostsIterator(); | 24 content::RenderProcessHost::AllHostsIterator(); |
| 22 if (it.IsAtEnd()) { | 25 if (it.IsAtEnd()) { |
| 23 // There should always be one RPH in single process mode. | 26 // There should always be one RPH in single process mode. |
| 24 NOTREACHED(); | 27 NOTREACHED(); |
| 25 return 0; | 28 return 0; |
| 26 } | 29 } |
| 27 | 30 |
| 28 int id = it.GetCurrentValue()->GetID(); | 31 int id = it.GetCurrentValue()->GetID(); |
| 29 it.Advance(); | 32 it.Advance(); |
| 30 DCHECK(it.IsAtEnd()); // Not multiprocess compatible. | 33 DCHECK(it.IsAtEnd()); // Not multiprocess compatible. |
| 31 return id; | 34 return id; |
| 32 } | 35 } |
| 33 | 36 |
| 34 class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { | 37 class SynchronousCompositorFactoryImpl: public SynchronousCompositorFactory { |
|
joth
2013/06/01 02:11:35
undo edit
mkosiba (inactive)
2013/06/06 17:55:10
why? was the space in front of the colon intention
joth
2013/06/06 20:19:32
Of course! We always have a space either side of t
| |
| 35 public: | 38 public: |
| 36 SynchronousCompositorFactoryImpl() { | 39 SynchronousCompositorFactoryImpl() { |
| 37 SynchronousCompositorFactory::SetInstance(this); | 40 SynchronousCompositorFactory::SetInstance(this); |
| 38 } | 41 } |
| 39 | 42 |
| 40 // SynchronousCompositorFactory | 43 // SynchronousCompositorFactory |
| 41 virtual scoped_refptr<base::MessageLoopProxy> | 44 virtual scoped_refptr<base::MessageLoopProxy> |
| 42 GetCompositorMessageLoop() OVERRIDE { | 45 GetCompositorMessageLoop() OVERRIDE { |
| 43 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); | 46 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
| 44 } | 47 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 68 WebContents* contents = WebContents::FromRenderViewHost(rvh); | 71 WebContents* contents = WebContents::FromRenderViewHost(rvh); |
| 69 if (!contents) | 72 if (!contents) |
| 70 return NULL; | 73 return NULL; |
| 71 return FromWebContents(contents); | 74 return FromWebContents(contents); |
| 72 } | 75 } |
| 73 | 76 |
| 74 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) | 77 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) |
| 75 : compositor_client_(NULL), | 78 : compositor_client_(NULL), |
| 76 output_surface_(NULL), | 79 output_surface_(NULL), |
| 77 contents_(contents) { | 80 contents_(contents) { |
| 81 DCHECK(RenderThread::Get()->GetMessageLoop() == base::MessageLoop::current()); | |
|
joth
2013/06/01 02:11:35
I can't work out why this would be. There's only o
mkosiba (inactive)
2013/06/06 17:55:10
I think you misunderstood me about which main thre
joth
2013/06/06 20:19:32
Opps! sorry for confusion.
(I've learnt the new me
| |
| 82 | |
| 83 input_handler_manager_ = RenderThreadImpl::current()->input_handler_manager(); | |
| 84 // TODO(mkosiba): DCHECK(input_handler_manager_); after Jared's patches land. | |
| 78 } | 85 } |
| 79 | 86 |
| 80 SynchronousCompositorImpl::~SynchronousCompositorImpl() { | 87 SynchronousCompositorImpl::~SynchronousCompositorImpl() { |
| 81 if (compositor_client_) | 88 if (compositor_client_) |
| 82 compositor_client_->DidDestroyCompositor(this); | 89 compositor_client_->DidDestroyCompositor(this); |
| 83 } | 90 } |
| 84 | 91 |
| 85 bool SynchronousCompositorImpl::IsHwReady() { | 92 bool SynchronousCompositorImpl::IsHwReady() { |
| 86 DCHECK(CalledOnValidThread()); | 93 DCHECK(CalledOnValidThread()); |
| 87 DCHECK(output_surface_); | 94 DCHECK(output_surface_); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 111 | 118 |
| 112 return output_surface_->DemandDrawHw(view_size, transform, damage_area); | 119 return output_surface_->DemandDrawHw(view_size, transform, damage_area); |
| 113 } | 120 } |
| 114 | 121 |
| 115 void SynchronousCompositorImpl::DidBindOutputSurface( | 122 void SynchronousCompositorImpl::DidBindOutputSurface( |
| 116 SynchronousCompositorOutputSurface* output_surface) { | 123 SynchronousCompositorOutputSurface* output_surface) { |
| 117 DCHECK(CalledOnValidThread()); | 124 DCHECK(CalledOnValidThread()); |
| 118 output_surface_ = output_surface; | 125 output_surface_ = output_surface; |
| 119 if (compositor_client_) | 126 if (compositor_client_) |
| 120 compositor_client_->DidInitializeCompositor(this); | 127 compositor_client_->DidInitializeCompositor(this); |
| 128 | |
| 129 if (input_handler_manager_) | |
| 130 input_handler_manager_->SetRootLayerScrollDelegate(routing_id_, this); | |
| 121 } | 131 } |
| 122 | 132 |
| 123 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface( | 133 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface( |
| 124 SynchronousCompositorOutputSurface* output_surface) { | 134 SynchronousCompositorOutputSurface* output_surface) { |
| 125 DCHECK(CalledOnValidThread()); | 135 DCHECK(CalledOnValidThread()); |
| 136 | |
| 137 if (input_handler_manager_) | |
| 138 input_handler_manager_->SetRootLayerScrollDelegate(routing_id_, NULL); | |
| 139 | |
| 126 // Allow for transient hand-over when two output surfaces may refer to | 140 // Allow for transient hand-over when two output surfaces may refer to |
| 127 // a single delegate. | 141 // a single delegate. |
| 128 if (output_surface_ == output_surface) { | 142 if (output_surface_ == output_surface) { |
| 129 output_surface_ = NULL; | 143 output_surface_ = NULL; |
| 130 if (compositor_client_) | 144 if (compositor_client_) |
| 131 compositor_client_->DidDestroyCompositor(this); | 145 compositor_client_->DidDestroyCompositor(this); |
| 132 compositor_client_ = NULL; | 146 compositor_client_ = NULL; |
| 133 } | 147 } |
| 134 } | 148 } |
| 135 | 149 |
| 136 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { | 150 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { |
| 137 DCHECK(CalledOnValidThread()); | 151 DCHECK(CalledOnValidThread()); |
| 138 if (compositor_client_) | 152 if (compositor_client_) |
| 139 compositor_client_->SetContinuousInvalidate(enable); | 153 compositor_client_->SetContinuousInvalidate(enable); |
| 140 } | 154 } |
| 141 | 155 |
| 156 void SynchronousCompositorImpl::SetTotalScrollOffset(gfx::Vector2dF new_value) { | |
| 157 DCHECK(CalledOnValidThread()); | |
| 158 if (compositor_client_) | |
| 159 compositor_client_->SetTotalRootLayerScrollOffset(new_value); | |
| 160 } | |
| 161 | |
| 162 gfx::Vector2dF SynchronousCompositorImpl::GetTotalScrollOffset() { | |
| 163 DCHECK(CalledOnValidThread()); | |
| 164 if (compositor_client_) | |
| 165 return compositor_client_->GetTotalRootLayerScrollOffset(); | |
| 166 else | |
| 167 return gfx::Vector2dF(); | |
| 168 } | |
| 169 | |
| 142 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 170 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 143 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. | 171 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. |
| 144 bool SynchronousCompositorImpl::CalledOnValidThread() const { | 172 bool SynchronousCompositorImpl::CalledOnValidThread() const { |
| 145 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 173 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 146 } | 174 } |
| 147 | 175 |
| 148 // static | 176 // static |
| 149 void SynchronousCompositor::SetClientForWebContents( | 177 void SynchronousCompositor::SetClientForWebContents( |
| 150 WebContents* contents, | 178 WebContents* contents, |
| 151 SynchronousCompositorClient* client) { | 179 SynchronousCompositorClient* client) { |
| 152 DCHECK(contents); | 180 DCHECK(contents); |
| 153 if (client) { | 181 if (client) { |
| 154 g_factory.Get(); // Ensure it's initialized. | 182 g_factory.Get(); // Ensure it's initialized. |
| 155 SynchronousCompositorImpl::CreateForWebContents(contents); | 183 SynchronousCompositorImpl::CreateForWebContents(contents); |
| 156 } | 184 } |
| 157 if (SynchronousCompositorImpl* instance = | 185 if (SynchronousCompositorImpl* instance = |
| 158 SynchronousCompositorImpl::FromWebContents(contents)) { | 186 SynchronousCompositorImpl::FromWebContents(contents)) { |
| 159 instance->SetClient(client); | 187 instance->SetClient(client); |
| 160 } | 188 } |
| 161 } | 189 } |
| 162 | 190 |
| 163 } // namespace content | 191 } // namespace content |
| OLD | NEW |