Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/renderer/android/synchronous_compositor_output_surface.h" | 5 #include "content/renderer/android/synchronous_compositor_output_surface.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/time.h" | |
| 8 #include "cc/output/output_surface_client.h" | 9 #include "cc/output/output_surface_client.h" |
| 9 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | |
| 10 #include "content/public/renderer/android/synchronous_compositor_client.h" | 10 #include "content/public/renderer/android/synchronous_compositor_client.h" |
| 11 #include "content/public/renderer/content_renderer_client.h" | 11 #include "content/public/renderer/content_renderer_client.h" |
| 12 #include "skia/ext/refptr.h" | 12 #include "skia/ext/refptr.h" |
| 13 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
| 14 #include "third_party/skia/include/core/SkPicture.h" | 14 #include "third_party/skia/include/core/SkPicture.h" |
| 15 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | |
| 16 | |
| 17 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | |
| 15 | 18 |
| 16 namespace content { | 19 namespace content { |
| 20 namespace { | |
| 21 | |
| 22 // TODO(boliu): RenderThreadImpl should create in process contexts as well. | |
| 23 scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D() { | |
|
boliu
2013/05/07 14:13:03
Here is my plan to support cc hardware init: Move
danakj
2013/05/07 18:55:06
The problem I see here is we only create the offsc
danakj
2013/05/07 18:57:11
Also keep in mind that context creation needs to b
boliu
2013/05/07 19:18:44
This is the exact behavior I'm trying to workaroun
danakj
2013/05/07 19:35:34
This is true, it would only be required for the gp
| |
| 24 WebKit::WebGraphicsContext3D::Attributes attributes; | |
| 25 attributes.antialias = false; | |
| 26 attributes.shareResources = true; | |
| 27 attributes.noAutomaticFlushes = true; | |
| 28 | |
| 29 return scoped_ptr<WebKit::WebGraphicsContext3D>( | |
| 30 WebGraphicsContext3DInProcessCommandBufferImpl | |
| 31 ::CreateViewContext(attributes, NULL)); | |
| 32 } | |
| 33 } // namespace | |
| 17 | 34 |
| 18 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( | 35 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( |
| 19 int32 routing_id, | 36 int32 routing_id) |
| 20 WebGraphicsContext3DCommandBufferImpl* context) | 37 : cc::OutputSurface(CreateWebGraphicsContext3D()), |
| 21 : cc::OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>(context)), | |
| 22 compositor_client_(NULL), | 38 compositor_client_(NULL), |
| 23 routing_id_(routing_id) { | 39 routing_id_(routing_id), |
| 24 // WARNING: may be called on any thread. | 40 did_swap_buffer_(false) { |
| 25 } | 41 } |
| 26 | 42 |
| 27 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { | 43 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { |
| 28 DCHECK(CalledOnValidThread()); | 44 DCHECK(CalledOnValidThread()); |
| 29 if (compositor_client_) | 45 if (compositor_client_) |
| 30 compositor_client_->DidDestroyCompositor(this); | 46 compositor_client_->DidDestroyCompositor(this); |
| 31 } | 47 } |
| 32 | 48 |
| 33 bool SynchronousCompositorOutputSurface::BindToClient( | 49 bool SynchronousCompositorOutputSurface::BindToClient( |
| 34 cc::OutputSurfaceClient* surface_client) { | 50 cc::OutputSurfaceClient* surface_client) { |
| 35 DCHECK(CalledOnValidThread()); | 51 DCHECK(CalledOnValidThread()); |
| 36 if (!cc::OutputSurface::BindToClient(surface_client)) | 52 if (!cc::OutputSurface::BindToClient(surface_client)) |
| 37 return false; | 53 return false; |
| 38 GetContentClient()->renderer()->DidCreateSynchronousCompositor(routing_id_, | 54 GetContentClient()->renderer()->DidCreateSynchronousCompositor(routing_id_, |
| 39 this); | 55 this); |
| 40 return true; | 56 return true; |
| 41 } | 57 } |
| 42 | 58 |
| 59 void SynchronousCompositorOutputSurface::Reshape(gfx::Size size) { | |
| 60 // Intentional no-op. | |
| 61 } | |
| 62 | |
| 43 void SynchronousCompositorOutputSurface::SendFrameToParentCompositor( | 63 void SynchronousCompositorOutputSurface::SendFrameToParentCompositor( |
| 44 cc::CompositorFrame* frame) { | 64 cc::CompositorFrame* frame) { |
| 45 // Intentional no-op: see http://crbug.com/237006 | 65 // Intentional no-op: see http://crbug.com/237006 |
| 46 } | 66 } |
| 47 | 67 |
| 68 void SynchronousCompositorOutputSurface::EnableVSyncNotification( | |
| 69 bool enable_vsync) { | |
| 70 DCHECK(CalledOnValidThread()); | |
| 71 vsync_enabled_ = enable_vsync; | |
| 72 UpdateCompositorClientSettings(); | |
| 73 } | |
| 74 | |
| 75 void SynchronousCompositorOutputSurface::SwapBuffers( | |
| 76 const cc::LatencyInfo& info) { | |
| 77 context3d()->finish(); | |
| 78 did_swap_buffer_ = true; | |
| 79 } | |
| 80 | |
| 48 void SynchronousCompositorOutputSurface::SetClient( | 81 void SynchronousCompositorOutputSurface::SetClient( |
| 49 SynchronousCompositorClient* compositor_client) { | 82 SynchronousCompositorClient* compositor_client) { |
| 50 DCHECK(CalledOnValidThread()); | 83 DCHECK(CalledOnValidThread()); |
| 51 compositor_client_ = compositor_client; | 84 compositor_client_ = compositor_client; |
| 85 UpdateCompositorClientSettings(); | |
| 52 } | 86 } |
| 53 | 87 |
| 54 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 88 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
| 55 DCHECK(CalledOnValidThread()); | 89 DCHECK(CalledOnValidThread()); |
| 56 NOTIMPLEMENTED(); // TODO(joth): call through to OutputSurfaceClient | 90 NOTIMPLEMENTED(); // TODO(joth): call through to OutputSurfaceClient |
| 57 return false; | 91 return false; |
| 58 } | 92 } |
| 59 | 93 |
| 94 bool SynchronousCompositorOutputSurface::DemandDrawHw(gfx::Rect damage_rect) { | |
| 95 DCHECK(CalledOnValidThread()); | |
| 96 DCHECK(client_); | |
| 97 | |
| 98 did_swap_buffer_ = false; | |
| 99 client_->SetNeedsRedrawRect(damage_rect); | |
| 100 if (vsync_enabled_) | |
| 101 client_->DidVSync(base::TimeTicks::Now()); | |
|
jamesr
2013/05/07 18:06:41
can we get an actual frame timestamp from the syst
boliu
2013/05/07 19:18:44
I'm not sure. Also a bit confused about what this
| |
| 102 | |
| 103 return did_swap_buffer_; | |
| 104 } | |
| 105 | |
| 106 void SynchronousCompositorOutputSurface::UpdateCompositorClientSettings() { | |
| 107 if (compositor_client_) { | |
| 108 compositor_client_->SetContinuousInvalidate(vsync_enabled_); | |
| 109 } | |
| 110 } | |
| 111 | |
| 60 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 112 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 61 // requirement: SynchronousCompositorOutputSurface() must only be used by | 113 // requirement: SynchronousCompositorOutputSurface() must only be used by |
| 62 // embedders that supply their own compositor loop via | 114 // embedders that supply their own compositor loop via |
| 63 // OverrideCompositorMessageLoop(). | 115 // OverrideCompositorMessageLoop(). |
| 64 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 116 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 65 return base::MessageLoop::current() && (base::MessageLoop::current() == | 117 return base::MessageLoop::current() && (base::MessageLoop::current() == |
| 66 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); | 118 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); |
| 67 } | 119 } |
| 68 | 120 |
| 69 } // namespace content | 121 } // namespace content |
| OLD | NEW |