diff options
-rw-r--r-- | cc/output/delegating_renderer.cc | 28 | ||||
-rw-r--r-- | cc/output/delegating_renderer.h | 5 | ||||
-rw-r--r-- | cc/output/direct_renderer.cc | 2 | ||||
-rw-r--r-- | cc/output/direct_renderer.h | 1 | ||||
-rw-r--r-- | cc/output/renderer.h | 2 | ||||
-rw-r--r-- | cc/trees/single_thread_proxy.cc | 9 | ||||
-rw-r--r-- | cc/trees/single_thread_proxy.h | 2 | ||||
-rw-r--r-- | cc/trees/thread_proxy.cc | 14 |
8 files changed, 43 insertions, 20 deletions
diff --git a/cc/output/delegating_renderer.cc b/cc/output/delegating_renderer.cc index 2ee755a..c06536e 100644 --- a/cc/output/delegating_renderer.cc +++ b/cc/output/delegating_renderer.cc @@ -11,7 +11,6 @@ #include "base/debug/trace_event.h" #include "base/string_util.h" #include "base/strings/string_split.h" -#include "cc/output/compositor_frame.h" #include "cc/output/compositor_frame_ack.h" #include "cc/quads/checkerboard_draw_quad.h" #include "cc/quads/debug_border_draw_quad.h" @@ -123,6 +122,8 @@ const RendererCapabilities& DelegatingRenderer::Capabilities() const { return capabilities_; } +bool DelegatingRenderer::CanReadPixels() const { return false; } + static ResourceProvider::ResourceId AppendToArray( ResourceProvider::ResourceIdArray* array, ResourceProvider::ResourceId id) { @@ -133,20 +134,16 @@ static ResourceProvider::ResourceId AppendToArray( void DelegatingRenderer::DrawFrame( RenderPassList* render_passes_in_draw_order) { TRACE_EVENT0("cc", "DelegatingRenderer::DrawFrame"); - render_passes_for_swap_buffers_.swap(*render_passes_in_draw_order); - render_passes_in_draw_order->clear(); -} -void DelegatingRenderer::SwapBuffers(const LatencyInfo& latency_info) { - TRACE_EVENT0("cc", "DelegatingRenderer::SwapBuffers"); + DCHECK(!frame_for_swap_buffers_.delegated_frame_data); - CompositorFrame out_frame; - out_frame.metadata = client_->MakeCompositorFrameMetadata(); + frame_for_swap_buffers_.metadata = client_->MakeCompositorFrameMetadata(); - out_frame.delegated_frame_data = make_scoped_ptr(new DelegatedFrameData); - DelegatedFrameData& out_data = *out_frame.delegated_frame_data; + frame_for_swap_buffers_.delegated_frame_data = + make_scoped_ptr(new DelegatedFrameData); + DelegatedFrameData& out_data = *frame_for_swap_buffers_.delegated_frame_data; // Move the render passes and resources into the |out_frame|. - out_data.render_pass_list.swap(render_passes_for_swap_buffers_); + out_data.render_pass_list.swap(*render_passes_in_draw_order); // Collect all resource ids in the render passes into a ResourceIdArray. ResourceProvider::ResourceIdArray resources; @@ -158,12 +155,17 @@ void DelegatingRenderer::SwapBuffers(const LatencyInfo& latency_info) { render_pass->quad_list[j]->IterateResources(append_to_array); } resource_provider_->PrepareSendToParent(resources, &out_data.resource_list); +} + +void DelegatingRenderer::SwapBuffers(const LatencyInfo& latency_info) { + TRACE_EVENT0("cc", "DelegatingRenderer::SwapBuffers"); - output_surface_->SendFrameToParentCompositor(&out_frame); + output_surface_->SendFrameToParentCompositor(&frame_for_swap_buffers_); + DCHECK(!frame_for_swap_buffers_.delegated_frame_data); } void DelegatingRenderer::GetFramebufferPixels(void* pixels, gfx::Rect rect) { - NOTIMPLEMENTED(); + NOTREACHED(); } void DelegatingRenderer::ReceiveCompositorFrameAck( diff --git a/cc/output/delegating_renderer.h b/cc/output/delegating_renderer.h index 813be91..6e659c0 100644 --- a/cc/output/delegating_renderer.h +++ b/cc/output/delegating_renderer.h @@ -7,6 +7,7 @@ #include "base/memory/scoped_ptr.h" #include "cc/base/cc_export.h" +#include "cc/output/compositor_frame.h" #include "cc/output/renderer.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h" @@ -25,6 +26,8 @@ class CC_EXPORT DelegatingRenderer : public Renderer { virtual const RendererCapabilities& Capabilities() const OVERRIDE; + virtual bool CanReadPixels() const OVERRIDE; + virtual void DrawFrame(RenderPassList* render_passes_in_draw_order) OVERRIDE; virtual void Finish() OVERRIDE {} @@ -52,8 +55,8 @@ class CC_EXPORT DelegatingRenderer : public Renderer { OutputSurface* output_surface_; ResourceProvider* resource_provider_; RendererCapabilities capabilities_; + CompositorFrame frame_for_swap_buffers_; bool visible_; - RenderPassList render_passes_for_swap_buffers_; DISALLOW_COPY_AND_ASSIGN(DelegatingRenderer); }; diff --git a/cc/output/direct_renderer.cc b/cc/output/direct_renderer.cc index 5c5d056..429ac22 100644 --- a/cc/output/direct_renderer.cc +++ b/cc/output/direct_renderer.cc @@ -126,6 +126,8 @@ DirectRenderer::DirectRenderer(RendererClient* client, DirectRenderer::~DirectRenderer() {} +bool DirectRenderer::CanReadPixels() const { return true; } + void DirectRenderer::SetEnlargePassTextureAmountForTesting( gfx::Vector2d amount) { enlarge_pass_texture_amount_ = amount; diff --git a/cc/output/direct_renderer.h b/cc/output/direct_renderer.h index 3833231..7c37551 100644 --- a/cc/output/direct_renderer.h +++ b/cc/output/direct_renderer.h @@ -25,6 +25,7 @@ class CC_EXPORT DirectRenderer : public Renderer { ResourceProvider* resource_provider() const { return resource_provider_; } + virtual bool CanReadPixels() const OVERRIDE; virtual void DecideRenderPassAllocationsForFrame( const RenderPassList& render_passes_in_draw_order) OVERRIDE; virtual bool HaveCachedResourcesForRenderPassId(RenderPass::Id id) const diff --git a/cc/output/renderer.h b/cc/output/renderer.h index 047a3de..b1b9f48 100644 --- a/cc/output/renderer.h +++ b/cc/output/renderer.h @@ -50,6 +50,8 @@ class CC_EXPORT Renderer { virtual void ViewportChanged() {} virtual void ReceiveCompositorFrameAck(const CompositorFrameAck& ack) {} + virtual bool CanReadPixels() const = 0; + virtual void DecideRenderPassAllocationsForFrame( const RenderPassList& render_passes_in_draw_order) {} virtual bool HaveCachedResourcesForRenderPassId(RenderPass::Id id) const; diff --git a/cc/trees/single_thread_proxy.cc b/cc/trees/single_thread_proxy.cc index a124c6d..dc408c7 100644 --- a/cc/trees/single_thread_proxy.cc +++ b/cc/trees/single_thread_proxy.cc @@ -60,6 +60,7 @@ bool SingleThreadProxy::CompositeAndReadback(void* pixels, gfx::Rect rect) { LayerTreeHostImpl::FrameData frame; if (!CommitAndComposite(base::TimeTicks::Now(), device_viewport_damage_rect, + true, // for_readback &frame)) return false; @@ -337,6 +338,7 @@ void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { LayerTreeHostImpl::FrameData frame; if (CommitAndComposite(frame_begin_time, device_viewport_damage_rect, + false, // for_readback &frame)) { layer_tree_host_impl_->SwapBuffers(frame); DidSwapFrame(); @@ -370,6 +372,7 @@ void SingleThreadProxy::ForceSerializeOnSwapBuffers() { bool SingleThreadProxy::CommitAndComposite( base::TimeTicks frame_begin_time, gfx::Rect device_viewport_damage_rect, + bool for_readback, LayerTreeHostImpl::FrameData* frame) { DCHECK(Proxy::IsMainThread()); @@ -399,6 +402,7 @@ bool SingleThreadProxy::CommitAndComposite( bool result = DoComposite(offscreen_context_provider, frame_begin_time, device_viewport_damage_rect, + for_readback, frame); layer_tree_host_->DidBeginFrame(); return result; @@ -414,6 +418,7 @@ bool SingleThreadProxy::DoComposite( scoped_refptr<cc::ContextProvider> offscreen_context_provider, base::TimeTicks frame_begin_time, gfx::Rect device_viewport_damage_rect, + bool for_readback, LayerTreeHostImpl::FrameData* frame) { DCHECK(!layer_tree_host_->output_surface_lost()); @@ -425,11 +430,13 @@ bool SingleThreadProxy::DoComposite( layer_tree_host_impl_->resource_provider()-> set_offscreen_context_provider(offscreen_context_provider); + bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels(); + // We guard PrepareToDraw() with CanDraw() because it always returns a valid // frame, so can only be used when such a frame is possible. Since // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on // CanDraw() as well. - if (!ShouldComposite()) { + if (!ShouldComposite() || (for_readback && !can_do_readback)) { layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true); return false; } diff --git a/cc/trees/single_thread_proxy.h b/cc/trees/single_thread_proxy.h index 7bd7da2..6a2487b 100644 --- a/cc/trees/single_thread_proxy.h +++ b/cc/trees/single_thread_proxy.h @@ -82,12 +82,14 @@ class SingleThreadProxy : public Proxy, LayerTreeHostImplClient { void OnOutputSurfaceInitializeAttempted(bool success); bool CommitAndComposite(base::TimeTicks frame_begin_time, gfx::Rect device_viewport_damage_rect, + bool for_readback, LayerTreeHostImpl::FrameData* frame); void DoCommit(scoped_ptr<ResourceUpdateQueue> queue); bool DoComposite( scoped_refptr<cc::ContextProvider> offscreen_context_provider, base::TimeTicks frame_begin_time, gfx::Rect device_viewport_damage_rect, + bool for_readback, LayerTreeHostImpl::FrameData* frame); void DidSwapFrame(); diff --git a/cc/trees/thread_proxy.cc b/cc/trees/thread_proxy.cc index 06446a2..6ec17c8 100644 --- a/cc/trees/thread_proxy.cc +++ b/cc/trees/thread_proxy.cc @@ -915,16 +915,20 @@ ThreadProxy::ScheduledActionDrawAndSwapInternal(bool forced_draw) { // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on // CanDraw() as well. - // If it is a forced draw, make sure we do a draw and swap. - gfx::Rect readback_rect; - if (readback_request_on_impl_thread_) - readback_rect = readback_request_on_impl_thread_->rect; + bool drawing_for_readback = !!readback_request_on_impl_thread_; + bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels(); LayerTreeHostImpl::FrameData frame; bool draw_frame = false; bool start_ready_animations = true; - if (layer_tree_host_impl_->CanDraw()) { + if (layer_tree_host_impl_->CanDraw() && + (!drawing_for_readback || can_do_readback)) { + // If it is for a readback, make sure we draw the portion being read back. + gfx::Rect readback_rect; + if (drawing_for_readback) + readback_rect = readback_request_on_impl_thread_->rect; + // Do not start animations if we skip drawing the frame to avoid // checkerboarding. if (layer_tree_host_impl_->PrepareToDraw(&frame, readback_rect) || |