Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/renderer/android/synchronous_compositor_impl.h" | |
| 6 | |
| 7 #include "base/message_loop.h" | |
| 8 #include "cc/input/input_handler.h" | |
| 9 #include "content/public/renderer/android/synchronous_compositor_client.h" | |
| 10 #include "content/public/renderer/content_renderer_client.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 SynchronousCompositorImpl::SynchronousCompositorImpl(int32 routing_id) | |
| 15 : routing_id_(routing_id), compositor_client_(NULL) {} | |
| 16 | |
| 17 SynchronousCompositorImpl::~SynchronousCompositorImpl() { | |
| 18 } | |
| 19 | |
| 20 scoped_ptr<cc::OutputSurface> | |
| 21 SynchronousCompositorImpl::CreateOutputSurface() { | |
| 22 scoped_ptr<SynchronousCompositorOutputSurface> output_surface( | |
| 23 new SynchronousCompositorOutputSurface(this)); | |
| 24 output_surface_ = output_surface.get(); | |
| 25 return output_surface.PassAs<cc::OutputSurface>(); | |
| 26 } | |
| 27 | |
| 28 void SynchronousCompositorImpl::didCreateInputHandler( | |
| 29 base::WeakPtr<cc::InputHandler> input_handler) { | |
| 30 // TODO(mkosiba): Seems contrived (also, current version has race, | |
| 31 // would need to ref-count SynchronousCompositorImpl). | |
| 32 // Need to find a better way for the SynchronousCompositorImpl to 'get' an | |
| 33 // input handler and to be notified of when the InputHandler is destroyed. | |
| 34 GetContentClient()->renderer()->OverrideCompositorMessageLoop()->PostTask( | |
|
jamesr
2013/05/22 01:28:13
this looks needlessly indirect. you're in the con
mkosiba (inactive)
2013/05/22 17:26:17
Done.
| |
| 35 FROM_HERE, | |
| 36 base::Bind(&SynchronousCompositorImpl::didCreateInputHandlerOnImplThread, | |
| 37 base::Unretained(this) | |
| 38 input_handler)); | |
| 39 } | |
| 40 | |
| 41 void SynchronousCompositorImpl::didCreateInputHandlerOnImplThread( | |
| 42 base::WeakPtr<cc::InputHandler> input_handler) { | |
| 43 if (input_handler.get()) { | |
| 44 input_handler->SetRootLayerScrollOffsetDelegate( | |
| 45 GetSynchronousCompositor()); | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 bool SynchronousCompositorImpl::IsHwReady() { | |
| 50 DCHECK(CalledOnValidThread()); | |
| 51 DCHECK(output_surface_); | |
| 52 | |
| 53 if (!output_surface_) | |
| 54 return false; | |
| 55 return output_surface_->IsHwReady(); | |
| 56 } | |
| 57 | |
| 58 void SynchronousCompositorImpl::SetClient( | |
| 59 SynchronousCompositorClient* compositor_client) { | |
| 60 DCHECK(CalledOnValidThread()); | |
| 61 compositor_client_ = compositor_client; | |
| 62 } | |
| 63 | |
| 64 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { | |
| 65 DCHECK(CalledOnValidThread()); | |
| 66 DCHECK(output_surface_); | |
| 67 | |
| 68 if (!output_surface_) | |
| 69 return false; | |
| 70 | |
| 71 return output_surface_->DemandDrawSw(canvas); | |
| 72 } | |
| 73 | |
| 74 bool SynchronousCompositorImpl::DemandDrawHw( | |
| 75 gfx::Size view_size, | |
| 76 const gfx::Transform& transform, | |
| 77 gfx::Rect damage_area) { | |
| 78 DCHECK(CalledOnValidThread()); | |
| 79 DCHECK(output_surface_); | |
| 80 | |
| 81 if (!output_surface_) | |
| 82 return false; | |
| 83 return output_surface_->DemandDrawHw(view_size, transform, damage_area); | |
| 84 } | |
| 85 | |
| 86 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { | |
| 87 DCHECK(CalledOnValidThread()); | |
| 88 compositor_client_->SetContinuousInvalidate(enable); | |
| 89 } | |
| 90 | |
| 91 void SynchronousCompositorImpl::DidCreateSynchronousCompositor() { | |
| 92 DCHECK(CalledOnValidThread()); | |
| 93 GetContentClient()->renderer()->DidCreateSynchronousCompositor(routing_id_, | |
| 94 this); | |
| 95 } | |
| 96 | |
| 97 void SynchronousCompositorImpl::DidDestroyCompositor() { | |
| 98 DCHECK(CalledOnValidThread()); | |
| 99 output_surface_ = NULL; | |
| 100 } | |
| 101 | |
| 102 void SynchronousCompositorImpl::SetTotalScrollOffset(gfx::Vector2dF new_value) { | |
| 103 DCHECK(CalledOnValidThread()); | |
| 104 compositor_client_->SetTotalRootLayerScrollOffset(new_value); | |
| 105 } | |
| 106 | |
| 107 gfx::Vector2dF SynchronousCompositorImpl::GetTotalScrollOffset() { | |
| 108 DCHECK(CalledOnValidThread()); | |
| 109 return compositor_client_->GetTotalRootLayerScrollOffset(); | |
| 110 } | |
| 111 | |
| 112 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | |
| 113 // requirement: SynchronousCompositorImpl() must only be used by | |
| 114 // embedders that supply their own compositor loop via | |
| 115 // OverrideCompositorMessageLoop(). | |
| 116 bool SynchronousCompositorImpl::CalledOnValidThread() const { | |
| 117 return base::MessageLoop::current() && (base::MessageLoop::current() == | |
| 118 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); | |
| 119 } | |
| 120 | |
| 121 } // namespace content | |
| OLD | NEW |