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 bool SynchronousCompositorImpl::IsHwReady() { |
| 29 DCHECK(CalledOnValidThread()); |
| 30 DCHECK(output_surface_); |
| 31 |
| 32 return output_surface_->IsHwReady(); |
| 33 } |
| 34 |
| 35 void SynchronousCompositorImpl::SetClient( |
| 36 SynchronousCompositorClient* compositor_client) { |
| 37 DCHECK(CalledOnValidThread()); |
| 38 compositor_client_ = compositor_client; |
| 39 } |
| 40 |
| 41 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { |
| 42 DCHECK(CalledOnValidThread()); |
| 43 DCHECK(output_surface_); |
| 44 |
| 45 return output_surface_->DemandDrawSw(canvas); |
| 46 } |
| 47 |
| 48 bool SynchronousCompositorImpl::DemandDrawHw( |
| 49 gfx::Size view_size, |
| 50 const gfx::Transform& transform, |
| 51 gfx::Rect damage_area) { |
| 52 DCHECK(CalledOnValidThread()); |
| 53 DCHECK(output_surface_); |
| 54 |
| 55 return output_surface_->DemandDrawHw(view_size, transform, damage_area); |
| 56 } |
| 57 |
| 58 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { |
| 59 DCHECK(CalledOnValidThread()); |
| 60 // compositor_client_ can be NULL during WebContents teardown. |
| 61 if (compositor_client_) |
| 62 compositor_client_->SetContinuousInvalidate(enable); |
| 63 } |
| 64 |
| 65 void SynchronousCompositorImpl::DidCreateSynchronousOutputSurface() { |
| 66 DCHECK(CalledOnValidThread()); |
| 67 GetContentClient()->renderer()->DidCreateSynchronousCompositor(routing_id_, |
| 68 this); |
| 69 } |
| 70 |
| 71 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface() { |
| 72 DCHECK(CalledOnValidThread()); |
| 73 output_surface_ = NULL; |
| 74 // compositor_client_ can be NULL during WebContents teardown. |
| 75 if (compositor_client_) |
| 76 compositor_client_->DidDestroyCompositor(this); |
| 77 } |
| 78 |
| 79 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 80 // requirement: SynchronousCompositorImpl() must only be used by |
| 81 // embedders that supply their own compositor loop via |
| 82 // OverrideCompositorMessageLoop(). |
| 83 bool SynchronousCompositorImpl::CalledOnValidThread() const { |
| 84 return base::MessageLoop::current() && (base::MessageLoop::current() == |
| 85 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); |
| 86 } |
| 87 |
| 88 } // namespace content |
OLD | NEW |