diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-26 13:18:59 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-26 13:18:59 +0000 |
commit | 2364ee7117c948b080f7c31e68487975a5fda408 (patch) | |
tree | 0f6b3de9210ef2b475284f2ed2baab20c7cd002b | |
parent | e0be0099cd7ca92687a2c7a3b79b737c5eedee6d (diff) | |
download | chromium_src-2364ee7117c948b080f7c31e68487975a5fda408.zip chromium_src-2364ee7117c948b080f7c31e68487975a5fda408.tar.gz chromium_src-2364ee7117c948b080f7c31e68487975a5fda408.tar.bz2 |
Revert 196713 "cc: Async readback."
Oops, wrong version landed!
> cc: Async readback.
>
> Provide a path to get a readback of a layer's subtree via an
> asynchronous mechanism.
>
> This path is used for all the cc pixel tests, to show that it
> works. Also by some unit tests:
>
> LayerTreeHostTestAsyncReadback.GLRenderer_RunSingleThread
> LayerTreeHostTestAsyncReadback.GLRenderer_RunMultiThread
> LayerTreeHostTestAsyncReadback.SoftwareRenderer_RunSingleThread
> LayerTreeHostTestAsyncReadback.SoftwareRenderer_RunMultiThread
> LayerTreeHostTestAsyncReadbackLayerDestroyed.RunSingleThread
> LayerTreeHostTestAsyncReadbackLayerDestroyed.RunMultiThread
>
> BUG=179896
>
> Review URL: https://chromiumcodereview.appspot.com/14060015
TBR=danakj@chromium.org
Review URL: https://codereview.chromium.org/14512003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196715 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | cc/layers/layer.cc | 38 | ||||
-rw-r--r-- | cc/layers/layer.h | 15 | ||||
-rw-r--r-- | cc/layers/layer_impl.cc | 30 | ||||
-rw-r--r-- | cc/layers/layer_impl.h | 11 | ||||
-rw-r--r-- | cc/output/direct_renderer.cc | 13 | ||||
-rw-r--r-- | cc/output/direct_renderer.h | 2 | ||||
-rw-r--r-- | cc/output/gl_renderer.cc | 13 | ||||
-rw-r--r-- | cc/output/gl_renderer.h | 2 | ||||
-rw-r--r-- | cc/output/gl_renderer_pixeltest.cc | 56 | ||||
-rw-r--r-- | cc/output/software_renderer.cc | 9 | ||||
-rw-r--r-- | cc/output/software_renderer.h | 2 | ||||
-rw-r--r-- | cc/quads/render_pass.cc | 6 | ||||
-rw-r--r-- | cc/quads/render_pass.h | 10 | ||||
-rw-r--r-- | cc/quads/render_pass_unittest.cc | 5 | ||||
-rw-r--r-- | cc/resources/resource_provider.cc | 5 | ||||
-rw-r--r-- | cc/test/layer_tree_pixel_test.cc | 24 | ||||
-rw-r--r-- | cc/test/layer_tree_pixel_test.h | 4 | ||||
-rw-r--r-- | cc/test/pixel_test.cc | 38 | ||||
-rw-r--r-- | cc/test/pixel_test.h | 8 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_common.cc | 4 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl.cc | 15 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_unittest.cc | 193 |
22 files changed, 72 insertions, 431 deletions
diff --git a/cc/layers/layer.cc b/cc/layers/layer.cc index 6584e71..43a0335 100644 --- a/cc/layers/layer.cc +++ b/cc/layers/layer.cc @@ -10,7 +10,6 @@ #include "cc/animation/animation.h" #include "cc/animation/animation_events.h" #include "cc/animation/layer_animation_controller.h" -#include "cc/base/thread.h" #include "cc/layers/layer_impl.h" #include "cc/trees/layer_tree_host.h" #include "cc/trees/layer_tree_impl.h" @@ -70,9 +69,6 @@ Layer::~Layer() { // way for us to be destroyed while we still have a parent. DCHECK(!parent()); - for (size_t i = 0; i < request_copy_callbacks_.size(); ++i) - request_copy_callbacks_[i].Run(scoped_ptr<SkBitmap>()); - layer_animation_controller_->RemoveValueObserver(this); // Remove the parent reference from all children and dependents. @@ -305,14 +301,6 @@ void Layer::SetChildren(const LayerList& children) { AddChild(children[i]); } -void Layer::RequestCopyAsBitmap(RequestCopyAsBitmapCallback callback) { - DCHECK(IsPropertyChangeAllowed()); - if (callback.is_null()) - return; - request_copy_callbacks_.push_back(callback); - SetNeedsCommit(); -} - void Layer::SetAnchorPoint(gfx::PointF anchor_point) { DCHECK(IsPropertyChangeAllowed()); if (anchor_point_ == anchor_point) @@ -622,21 +610,6 @@ void Layer::SetPositionConstraint(const LayerPositionConstraint& constraint) { SetNeedsCommit(); } -static void RunCopyCallbackOnMainThread( - const Layer::RequestCopyAsBitmapCallback& callback, - scoped_ptr<SkBitmap> bitmap) { - callback.Run(bitmap.Pass()); -} - -static void PostCopyCallbackToMainThread( - Thread* main_thread, - const Layer::RequestCopyAsBitmapCallback& callback, - scoped_ptr<SkBitmap> bitmap) { - main_thread->PostTask(base::Bind(&RunCopyCallbackOnMainThread, - callback, - base::Passed(&bitmap))); -} - void Layer::PushPropertiesTo(LayerImpl* layer) { layer->SetAnchorPoint(anchor_point_); layer->SetAnchorPointZ(anchor_point_z_); @@ -678,17 +651,6 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { layer->SetScrollOffset(scroll_offset_); layer->SetMaxScrollOffset(max_scroll_offset_); - // Wrap the request_copy_callbacks_ in a PostTask to the main thread. - std::vector<RequestCopyAsBitmapCallback> main_thread_request_copy_callbacks; - for (size_t i = 0; i < request_copy_callbacks_.size(); ++i) { - main_thread_request_copy_callbacks.push_back( - base::Bind(&PostCopyCallbackToMainThread, - layer_tree_host()->proxy()->MainThread(), - request_copy_callbacks_[i])); - } - request_copy_callbacks_.clear(); - layer->PassRequestCopyCallbacks(&main_thread_request_copy_callbacks); - // If the main thread commits multiple times before the impl thread actually // draws, then damage tracking will become incorrect if we simply clobber the // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. diff --git a/cc/layers/layer.h b/cc/layers/layer.h index a35d7a5..8411964 100644 --- a/cc/layers/layer.h +++ b/cc/layers/layer.h @@ -8,7 +8,6 @@ #include <string> #include <vector> -#include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/observer_list.h" #include "cc/animation/layer_animation_controller.h" @@ -77,18 +76,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, const LayerList& children() const { return children_; } Layer* child_at(size_t index) { return children_[index].get(); } - typedef base::Callback<void(scoped_ptr<SkBitmap>)> - RequestCopyAsBitmapCallback; - - // This requests the layer and its subtree be rendered into an SkBitmap and - // call the given callback when the SkBitmap has been produced. If the copy - // is unable to be produced (the layer is destroyed first), then the callback - // is called with a NULL bitmap. - void RequestCopyAsBitmap(RequestCopyAsBitmapCallback callback); - bool HasRequestCopyCallback() const { - return !request_copy_callbacks_.empty(); - } - void SetAnchorPoint(gfx::PointF anchor_point); gfx::PointF anchor_point() const { return anchor_point_; } @@ -493,8 +480,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, gfx::Transform impl_transform_; - std::vector<RequestCopyAsBitmapCallback> request_copy_callbacks_; - WebKit::WebLayerScrollClient* layer_scroll_client_; DrawProperties<Layer, RenderSurface> draw_properties_; diff --git a/cc/layers/layer_impl.cc b/cc/layers/layer_impl.cc index f7aecf1..aec8cd2 100644 --- a/cc/layers/layer_impl.cc +++ b/cc/layers/layer_impl.cc @@ -69,10 +69,6 @@ LayerImpl::~LayerImpl() { #ifndef NDEBUG DCHECK(!between_will_draw_and_did_draw_); #endif - - for (size_t i = 0; i < request_copy_callbacks_.size(); ++i) - request_copy_callbacks_[i].Run(scoped_ptr<SkBitmap>()); - layer_tree_impl_->UnregisterLayer(this); layer_animation_controller_->RemoveValueObserver(this); } @@ -106,30 +102,6 @@ void LayerImpl::ClearChildList() { layer_tree_impl()->set_needs_update_draw_properties(); } -void LayerImpl::PassRequestCopyCallbacks( - std::vector<RenderPass::RequestCopyAsBitmapCallback>* callbacks) { - if (callbacks->empty()) - return; - - request_copy_callbacks_.insert(request_copy_callbacks_.end(), - callbacks->begin(), - callbacks->end()); - callbacks->clear(); - - NoteLayerPropertyChangedForSubtree(); -} - -void LayerImpl::TakeRequestCopyCallbacks( - std::vector<RenderPass::RequestCopyAsBitmapCallback>* callbacks) { - if (request_copy_callbacks_.empty()) - return; - - callbacks->insert(callbacks->end(), - request_copy_callbacks_.begin(), - request_copy_callbacks_.end()); - request_copy_callbacks_.clear(); -} - void LayerImpl::CreateRenderSurface() { DCHECK(!draw_properties_.render_surface); draw_properties_.render_surface = @@ -379,8 +351,6 @@ void LayerImpl::PushPropertiesTo(LayerImpl* layer) { layer->SetScrollOffset(scroll_offset_); layer->SetMaxScrollOffset(max_scroll_offset_); - layer->PassRequestCopyCallbacks(&request_copy_callbacks_); - // If the main thread commits multiple times before the impl thread actually // draws, then damage tracking will become incorrect if we simply clobber the // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. diff --git a/cc/layers/layer_impl.h b/cc/layers/layer_impl.h index 2333e1d..19aa727 100644 --- a/cc/layers/layer_impl.h +++ b/cc/layers/layer_impl.h @@ -6,7 +6,6 @@ #define CC_LAYERS_LAYER_IMPL_H_ #include <string> -#include <vector> #include "base/logging.h" #include "base/memory/scoped_ptr.h" @@ -76,14 +75,6 @@ class CC_EXPORT LayerImpl : LayerAnimationValueObserver { // Warning: This does not preserve tree structure invariants. void ClearChildList(); - void PassRequestCopyCallbacks( - std::vector<RenderPass::RequestCopyAsBitmapCallback>* callbacks); - void TakeRequestCopyCallbacks( - std::vector<RenderPass::RequestCopyAsBitmapCallback>* callbacks); - bool HasRequestCopyCallback() const { - return !request_copy_callbacks_.empty(); - } - void SetMaskLayer(scoped_ptr<LayerImpl> mask_layer); LayerImpl* mask_layer() { return mask_layer_.get(); } const LayerImpl* mask_layer() const { return mask_layer_.get(); } @@ -538,8 +529,6 @@ class CC_EXPORT LayerImpl : LayerAnimationValueObserver { ScrollbarLayerImpl* horizontal_scrollbar_layer_; ScrollbarLayerImpl* vertical_scrollbar_layer_; - std::vector<RenderPass::RequestCopyAsBitmapCallback> request_copy_callbacks_; - // Group of properties that need to be computed based on the layer tree // hierarchy before layers can be drawn. DrawProperties<LayerImpl, RenderSurfaceImpl> draw_properties_; diff --git a/cc/output/direct_renderer.cc b/cc/output/direct_renderer.cc index 7d0083f..ae8ff9b 100644 --- a/cc/output/direct_renderer.cc +++ b/cc/output/direct_renderer.cc @@ -8,7 +8,6 @@ #include <vector> #include "base/debug/trace_event.h" -#include "base/hash_tables.h" #include "base/metrics/histogram.h" #include "cc/base/math_util.h" #include "cc/quads/draw_quad.h" @@ -193,19 +192,9 @@ void DirectRenderer::DrawFrame(RenderPassList* render_passes_in_draw_order) { root_render_pass->damage_rect : root_render_pass->output_rect; frame.root_damage_rect.Intersect(gfx::Rect(ViewportSize())); - std::vector<base::Closure> copy_callbacks; - BeginDrawingFrame(&frame); - for (size_t i = 0; i < render_passes_in_draw_order->size(); ++i) { + for (size_t i = 0; i < render_passes_in_draw_order->size(); ++i) DrawRenderPass(&frame, render_passes_in_draw_order->at(i)); - - const RenderPass* pass = frame.current_render_pass; - for (size_t i = 0; i < pass->copy_callbacks.size(); ++i) { - scoped_ptr<SkBitmap> bitmap(new SkBitmap); - CopyCurrentRenderPassToBitmap(&frame, bitmap.get()); - pass->copy_callbacks[i].Run(bitmap.Pass()); - } - } FinishDrawingFrame(&frame); render_passes_in_draw_order->clear(); diff --git a/cc/output/direct_renderer.h b/cc/output/direct_renderer.h index 4153750..bb3095a 100644 --- a/cc/output/direct_renderer.h +++ b/cc/output/direct_renderer.h @@ -109,8 +109,6 @@ class CC_EXPORT DirectRenderer : public Renderer { virtual bool FlippedFramebuffer() const = 0; virtual void EnsureScissorTestEnabled() = 0; virtual void EnsureScissorTestDisabled() = 0; - virtual void CopyCurrentRenderPassToBitmap(DrawingFrame* frame, - SkBitmap* bitmap) = 0; ScopedPtrHashMap<RenderPass::Id, CachedResource> render_pass_textures_; ResourceProvider* resource_provider_; diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc index 4a0c7ba..19b215b 100644 --- a/cc/output/gl_renderer.cc +++ b/cc/output/gl_renderer.cc @@ -1776,19 +1776,6 @@ void GLRenderer::EnsureScissorTestDisabled() { is_scissor_enabled_ = false; } -void GLRenderer::CopyCurrentRenderPassToBitmap(DrawingFrame* frame, - SkBitmap* bitmap) { - gfx::Size render_pass_size = frame->current_render_pass->output_rect.size(); - bitmap->setConfig(SkBitmap::kARGB_8888_Config, - render_pass_size.width(), - render_pass_size.height()); - if (bitmap->allocPixels()) { - bitmap->lockPixels(); - GetFramebufferPixels(bitmap->getPixels(), gfx::Rect(render_pass_size)); - bitmap->unlockPixels(); - } -} - void GLRenderer::ToGLMatrix(float* gl_matrix, const gfx::Transform& transform) { transform.matrix().asColMajorf(gl_matrix); } diff --git a/cc/output/gl_renderer.h b/cc/output/gl_renderer.h index b05d02b..091d94e 100644 --- a/cc/output/gl_renderer.h +++ b/cc/output/gl_renderer.h @@ -103,8 +103,6 @@ class CC_EXPORT GLRenderer virtual bool FlippedFramebuffer() const OVERRIDE; virtual void EnsureScissorTestEnabled() OVERRIDE; virtual void EnsureScissorTestDisabled() OVERRIDE; - virtual void CopyCurrentRenderPassToBitmap(DrawingFrame* frame, - SkBitmap* bitmap) OVERRIDE; virtual void FinishDrawingQuadList() OVERRIDE; private: diff --git a/cc/output/gl_renderer_pixeltest.cc b/cc/output/gl_renderer_pixeltest.cc index 965b5cc..8da1b24 100644 --- a/cc/output/gl_renderer_pixeltest.cc +++ b/cc/output/gl_renderer_pixeltest.cc @@ -92,13 +92,14 @@ TEST_F(GLRendererPixelTest, SimpleGreenRect) { RenderPassList pass_list; pass_list.push_back(pass.Pass()); - EXPECT_TRUE(RunPixelTest( - &pass_list, + renderer_->DrawFrame(&pass_list); + + EXPECT_TRUE(PixelsMatchReference( base::FilePath(FILE_PATH_LITERAL("green.png")), ExactPixelComparator(true))); } -TEST_F(GLRendererPixelTest, FastPassColorFilterAlpha) { +TEST_F(GLRendererPixelTest, fastPassColorFilterAlpha) { gfx::Rect viewport_rect(device_viewport_size_); RenderPass::Id root_pass_id(1, 1); @@ -167,8 +168,7 @@ TEST_F(GLRendererPixelTest, FastPassColorFilterAlpha) { skia::RefPtr<SkImageFilter> filter = skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter.get(), NULL)); - scoped_ptr<RenderPassDrawQuad> render_pass_quad = - RenderPassDrawQuad::Create(); + scoped_ptr<RenderPassDrawQuad> render_pass_quad = RenderPassDrawQuad::Create(); render_pass_quad->SetNew(pass_shared_state.get(), pass_rect, child_pass_id, @@ -186,13 +186,16 @@ TEST_F(GLRendererPixelTest, FastPassColorFilterAlpha) { pass_list.push_back(child_pass.Pass()); pass_list.push_back(root_pass.Pass()); - EXPECT_TRUE(RunPixelTest( - &pass_list, + renderer_->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75)); + renderer_->DecideRenderPassAllocationsForFrame(pass_list); + renderer_->DrawFrame(&pass_list); + + EXPECT_TRUE(PixelsMatchReference( base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")), ExactPixelComparator(false))); } -TEST_F(GLRendererPixelTest, FastPassColorFilterAlphaTranslation) { +TEST_F(GLRendererPixelTest, fastPassColorFilterAlphaTranslation) { gfx::Rect viewport_rect(device_viewport_size_); RenderPass::Id root_pass_id(1, 1); @@ -283,8 +286,11 @@ TEST_F(GLRendererPixelTest, FastPassColorFilterAlphaTranslation) { pass_list.push_back(child_pass.Pass()); pass_list.push_back(root_pass.Pass()); - EXPECT_TRUE(RunPixelTest( - &pass_list, + renderer_->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75)); + renderer_->DecideRenderPassAllocationsForFrame(pass_list); + renderer_->DrawFrame(&pass_list); + + EXPECT_TRUE(PixelsMatchReference( base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha_translate.png")), ExactPixelComparator(false))); } @@ -336,16 +342,17 @@ TEST_F(GLRendererPixelTest, RenderPassChangesSize) { pass_list.push_back(root_pass.Pass()); renderer_->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75)); + renderer_->DecideRenderPassAllocationsForFrame(pass_list); + renderer_->DrawFrame(&pass_list); - EXPECT_TRUE(RunPixelTest( - &pass_list, + EXPECT_TRUE(PixelsMatchReference( base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")), ExactPixelComparator(true))); } class GLRendererPixelTestWithBackgroundFilter : public GLRendererPixelTest { protected: - void SetUpRenderPassList() { + void DrawFrame() { gfx::Rect device_viewport_rect(device_viewport_size_); RenderPass::Id root_id(1, 1); @@ -445,11 +452,14 @@ class GLRendererPixelTestWithBackgroundFilter : public GLRendererPixelTest { root_pass->quad_list.push_back(background_quad.PassAs<DrawQuad>()); root_pass->shared_quad_state_list.push_back(shared_state.Pass()); - pass_list_.push_back(filter_pass.Pass()); - pass_list_.push_back(root_pass.Pass()); + RenderPassList pass_list; + pass_list.push_back(filter_pass.Pass()); + pass_list.push_back(root_pass.Pass()); + + renderer_->DecideRenderPassAllocationsForFrame(pass_list); + renderer_->DrawFrame(&pass_list); } - RenderPassList pass_list_; WebKit::WebFilterOperations background_filters_; gfx::Transform filter_pass_to_target_transform_; gfx::Rect filter_pass_content_rect_; @@ -462,9 +472,8 @@ TEST_F(GLRendererPixelTestWithBackgroundFilter, InvertFilter) { filter_pass_content_rect_ = gfx::Rect(device_viewport_size_); filter_pass_content_rect_.Inset(12, 14, 16, 18); - SetUpRenderPassList(); - EXPECT_TRUE(RunPixelTest( - &pass_list_, + DrawFrame(); + EXPECT_TRUE(PixelsMatchReference( base::FilePath(FILE_PATH_LITERAL("background_filter.png")), ExactPixelComparator(true))); } @@ -473,7 +482,9 @@ TEST_F(GLRendererPixelTest, AntiAliasing) { gfx::Rect rect(0, 0, 200, 200); RenderPass::Id id(1, 1); - scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); + gfx::Transform transform_to_root; + scoped_ptr<RenderPass> pass = + CreateTestRenderPass(id, rect, transform_to_root); gfx::Transform red_content_to_target_transform; red_content_to_target_transform.Rotate(10); @@ -507,8 +518,9 @@ TEST_F(GLRendererPixelTest, AntiAliasing) { RenderPassList pass_list; pass_list.push_back(pass.Pass()); - EXPECT_TRUE(RunPixelTest( - &pass_list, + renderer_->DrawFrame(&pass_list); + + EXPECT_TRUE(PixelsMatchReference( base::FilePath(FILE_PATH_LITERAL("anti_aliasing.png")), ExactPixelComparator(true))); } diff --git a/cc/output/software_renderer.cc b/cc/output/software_renderer.cc index 69c3b7e..fec4f3e 100644 --- a/cc/output/software_renderer.cc +++ b/cc/output/software_renderer.cc @@ -407,15 +407,6 @@ void SoftwareRenderer::DrawUnsupportedQuad(const DrawingFrame* frame, current_paint_); } -void SoftwareRenderer::CopyCurrentRenderPassToBitmap(DrawingFrame* frame, - SkBitmap* bitmap) { - gfx::Size render_pass_size = frame->current_render_pass->output_rect.size(); - bitmap->setConfig(SkBitmap::kARGB_8888_Config, - render_pass_size.width(), - render_pass_size.height()); - current_canvas_->readPixels(bitmap, 0, 0); -} - void SoftwareRenderer::GetFramebufferPixels(void* pixels, gfx::Rect rect) { TRACE_EVENT0("cc", "SoftwareRenderer::GetFramebufferPixels"); SkBitmap subset_bitmap; diff --git a/cc/output/software_renderer.h b/cc/output/software_renderer.h index 90e6ed2..159044f 100644 --- a/cc/output/software_renderer.h +++ b/cc/output/software_renderer.h @@ -58,8 +58,6 @@ class CC_EXPORT SoftwareRenderer : public DirectRenderer { virtual bool FlippedFramebuffer() const OVERRIDE; virtual void EnsureScissorTestEnabled() OVERRIDE; virtual void EnsureScissorTestDisabled() OVERRIDE; - virtual void CopyCurrentRenderPassToBitmap(DrawingFrame* frame, - SkBitmap* bitmap) OVERRIDE; private: SoftwareRenderer( diff --git a/cc/quads/render_pass.cc b/cc/quads/render_pass.cc index 48990cd..ef681df 100644 --- a/cc/quads/render_pass.cc +++ b/cc/quads/render_pass.cc @@ -16,9 +16,11 @@ scoped_ptr<RenderPass> RenderPass::Create() { RenderPass::RenderPass() : id(Id(-1, -1)), has_transparent_background(true), - has_occlusion_from_outside_target_surface(false) {} + has_occlusion_from_outside_target_surface(false) { +} -RenderPass::~RenderPass() {} +RenderPass::~RenderPass() { +} scoped_ptr<RenderPass> RenderPass::Copy(Id new_id) const { DCHECK(new_id != id); diff --git a/cc/quads/render_pass.h b/cc/quads/render_pass.h index 1fb011a..bfd0d83 100644 --- a/cc/quads/render_pass.h +++ b/cc/quads/render_pass.h @@ -9,8 +9,6 @@ #include <vector> #include "base/basictypes.h" -#include "base/callback.h" -#include "base/hash_tables.h" #include "cc/base/cc_export.h" #include "cc/base/hash_pair.h" #include "cc/base/scoped_ptr_hash_map.h" @@ -99,14 +97,6 @@ class CC_EXPORT RenderPass { // complete, since they are occluded. bool has_occlusion_from_outside_target_surface; - // If non-empty, the renderer should produce a copy of the render pass' - // contents as a bitmap, and give a copy of the bitmap to each callback in - // this list. This property should not be serialized between compositors, as - // it only makes sense in the root compositor. - typedef base::Callback<void(scoped_ptr<SkBitmap>)> - RequestCopyAsBitmapCallback; - std::vector<RequestCopyAsBitmapCallback> copy_callbacks; - QuadList quad_list; SharedQuadStateList shared_quad_state_list; diff --git a/cc/quads/render_pass_unittest.cc b/cc/quads/render_pass_unittest.cc index 9ab0123..f2271b5 100644 --- a/cc/quads/render_pass_unittest.cc +++ b/cc/quads/render_pass_unittest.cc @@ -29,7 +29,6 @@ struct RenderPassSize { gfx::RectF damage_rect; bool has_transparent_background; bool has_occlusion_from_outside_target_surface; - std::vector<RenderPass::RequestCopyAsBitmapCallback> copy_callbacks; }; TEST(RenderPassTest, CopyShouldBeIdenticalExceptIdAndQuads) { @@ -48,7 +47,6 @@ TEST(RenderPassTest, CopyShouldBeIdenticalExceptIdAndQuads) { transform_to_root, has_transparent_background, has_occlusion_from_outside_target_surface); - pass->copy_callbacks.push_back(RenderPass::RequestCopyAsBitmapCallback()); // Stick a quad in the pass, this should not get copied. scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create(); @@ -74,9 +72,6 @@ TEST(RenderPassTest, CopyShouldBeIdenticalExceptIdAndQuads) { copy->has_occlusion_from_outside_target_surface); EXPECT_EQ(0u, copy->quad_list.size()); - // The copy callback should not be copied/duplicated. - EXPECT_EQ(0u, copy->copy_callbacks.size()); - EXPECT_EQ(sizeof(RenderPassSize), sizeof(RenderPass)); } diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc index 1b72257..7c55a3c 100644 --- a/cc/resources/resource_provider.cc +++ b/cc/resources/resource_provider.cc @@ -456,10 +456,7 @@ const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { ResourceMap::iterator it = resources_.find(id); CHECK(it != resources_.end()); Resource* resource = &it->second; - DCHECK(!resource->locked_for_write || - resource->set_pixels_completion_forced) << - "locked for write: " << resource->locked_for_write << - " pixels completion forced: " << resource->set_pixels_completion_forced; + DCHECK(!resource->locked_for_write || resource->set_pixels_completion_forced); DCHECK(!resource->exported); // Uninitialized! Call SetPixels or LockForWrite first. DCHECK(resource->allocated); diff --git a/cc/test/layer_tree_pixel_test.cc b/cc/test/layer_tree_pixel_test.cc index 1dfc551..34a0f8d 100644 --- a/cc/test/layer_tree_pixel_test.cc +++ b/cc/test/layer_tree_pixel_test.cc @@ -47,25 +47,35 @@ LayerTreePixelTest::OffscreenContextProviderForCompositorThread() { return provider; } -void LayerTreePixelTest::ReadbackResult(scoped_ptr<SkBitmap> bitmap) { - ASSERT_TRUE(bitmap); +void LayerTreePixelTest::SwapBuffersOnThread(LayerTreeHostImpl* host_impl, + bool result) { + EXPECT_TRUE(result); + + gfx::Rect device_viewport_rect( + host_impl->active_tree()->device_viewport_size()); + + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, + device_viewport_rect.width(), + device_viewport_rect.height()); + bitmap.allocPixels(); + unsigned char* pixels = static_cast<unsigned char*>(bitmap.getPixels()); + host_impl->Readback(pixels, device_viewport_rect); base::FilePath test_data_dir; EXPECT_TRUE(PathService::Get(cc::DIR_TEST_DATA, &test_data_dir)); // To rebaseline: - // EXPECT_TRUE(WritePNGFile(*bitmap, test_data_dir.Append(ref_file_), true)); + // EXPECT_TRUE(WritePNGFile(bitmap, test_data_dir.Append(ref_file_), true)); - EXPECT_TRUE(MatchesPNGFile(*bitmap, + EXPECT_TRUE(MatchesPNGFile(bitmap, test_data_dir.Append(ref_file_), *pixel_comparator_)); + EndTest(); } void LayerTreePixelTest::BeginTest() { - layer_tree_host()->root_layer()->RequestCopyAsBitmap( - base::Bind(&LayerTreePixelTest::ReadbackResult, - base::Unretained(this))); PostSetNeedsCommitToMainThread(); } diff --git a/cc/test/layer_tree_pixel_test.h b/cc/test/layer_tree_pixel_test.h index 4700ebd..ceddfab 100644 --- a/cc/test/layer_tree_pixel_test.h +++ b/cc/test/layer_tree_pixel_test.h @@ -25,8 +25,8 @@ class LayerTreePixelTest : public LayerTreeTest { OffscreenContextProviderForMainThread() OVERRIDE; virtual scoped_refptr<cc::ContextProvider> OffscreenContextProviderForCompositorThread() OVERRIDE; - - void ReadbackResult(scoped_ptr<SkBitmap> bitmap); + virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, + bool result) OVERRIDE; virtual void BeginTest() OVERRIDE; virtual void SetupTree() OVERRIDE; diff --git a/cc/test/pixel_test.cc b/cc/test/pixel_test.cc index 5976ae3..8563440 100644 --- a/cc/test/pixel_test.cc +++ b/cc/test/pixel_test.cc @@ -77,40 +77,26 @@ void PixelTest::SetUp() { resource_provider_->set_offscreen_context_provider(offscreen_contexts); } -bool PixelTest::RunPixelTest(RenderPassList* pass_list, - const base::FilePath& ref_file, - const PixelComparator& comparator) { - pass_list->back()->copy_callbacks.push_back( - base::Bind(&PixelTest::ReadbackResult, base::Unretained(this))); - - renderer_->DecideRenderPassAllocationsForFrame(*pass_list); - renderer_->DrawFrame(pass_list); - - // TODO(danakj): When the glReadPixels is async, wait for it to finish. - - return PixelsMatchReference(ref_file, comparator); -} - -void PixelTest::ReadbackResult(scoped_ptr<SkBitmap> bitmap) { - result_bitmap_ = bitmap.Pass(); -} - bool PixelTest::PixelsMatchReference(const base::FilePath& ref_file, const PixelComparator& comparator) { + gfx::Rect device_viewport_rect(device_viewport_size_); + + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, + device_viewport_rect.width(), + device_viewport_rect.height()); + bitmap.allocPixels(); + unsigned char* pixels = static_cast<unsigned char*>(bitmap.getPixels()); + renderer_->GetFramebufferPixels(pixels, device_viewport_rect); + base::FilePath test_data_dir; if (!PathService::Get(cc::DIR_TEST_DATA, &test_data_dir)) return false; - // If this is false, we didn't set up a readback on a render pass. - if (!result_bitmap_) - return false; - // To rebaseline: - // return WritePNGFile(*result_bitmap_, test_data_dir.Append(ref_file), true); + // return WritePNGFile(bitmap, test_data_dir.Append(ref_file)); - return MatchesPNGFile(*result_bitmap_, - test_data_dir.Append(ref_file), - comparator); + return MatchesPNGFile(bitmap, test_data_dir.Append(ref_file), comparator); } } // namespace cc diff --git a/cc/test/pixel_test.h b/cc/test/pixel_test.h index b3d8338..e915961 100644 --- a/cc/test/pixel_test.h +++ b/cc/test/pixel_test.h @@ -3,7 +3,6 @@ // found in the LICENSE file. #include "base/file_util.h" -#include "cc/quads/render_pass.h" #include "cc/test/pixel_comparator.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/size.h" @@ -23,12 +22,6 @@ class PixelTest : public testing::Test { virtual void SetUp() OVERRIDE; - bool RunPixelTest(RenderPassList* pass_list, - const base::FilePath& ref_file, - const PixelComparator& comparator); - - void ReadbackResult(scoped_ptr<SkBitmap> bitmap); - bool PixelsMatchReference(const base::FilePath& ref_file, const PixelComparator& comparator); @@ -38,7 +31,6 @@ class PixelTest : public testing::Test { class PixelTestRendererClient; scoped_ptr<PixelTestRendererClient> fake_client_; scoped_ptr<GLRenderer> renderer_; - scoped_ptr<SkBitmap> result_bitmap_; }; } // namespace cc diff --git a/cc/trees/layer_tree_host_common.cc b/cc/trees/layer_tree_host_common.cc index 64e768d..6bed0fe 100644 --- a/cc/trees/layer_tree_host_common.cc +++ b/cc/trees/layer_tree_host_common.cc @@ -296,10 +296,6 @@ static bool SubtreeShouldRenderToSeparateSurface( if (layer->force_render_surface()) return true; - // If we'll make a copy of the layer's contents. - if (layer->HasRequestCopyCallback()) - return true; - // If the layer uses a mask. if (layer->mask_layer()) return true; diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index d05f610..eddea9a 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -577,9 +577,6 @@ bool LayerTreeHostImpl::CalculateRenderPasses(FrameData* frame) { // due to an impl-animation, we drop the frame to avoid flashing due to the // texture suddenly appearing in the future. bool draw_frame = true; - // When we have a copy request for a layer, we need to draw no matter - // what, as the layer may disappear after this frame. - bool have_copy_request = false; int layers_drawn = 0; @@ -598,12 +595,7 @@ bool LayerTreeHostImpl::CalculateRenderPasses(FrameData* frame) { AppendQuadsData append_quads_data(target_render_pass->id); - if (it.represents_target_render_surface()) { - if (it->HasRequestCopyCallback()) { - have_copy_request = true; - it->TakeRequestCopyCallbacks(&target_render_pass->copy_callbacks); - } - } else if (it.represents_contributing_render_surface()) { + if (it.represents_contributing_render_surface()) { RenderPass::Id contributing_render_pass_id = it->render_surface()->RenderPassId(); RenderPass* contributing_render_pass = @@ -679,9 +671,6 @@ bool LayerTreeHostImpl::CalculateRenderPasses(FrameData* frame) { occlusion_tracker.LeaveLayer(it); } - if (have_copy_request) - draw_frame = true; - rendering_stats_instrumentation_->AddLayersDrawn(layers_drawn); #ifndef NDEBUG @@ -704,8 +693,6 @@ bool LayerTreeHostImpl::CalculateRenderPasses(FrameData* frame) { if (draw_frame) occlusion_tracker.overdraw_metrics()->RecordMetrics(this); - else - DCHECK(!have_copy_request); RemoveRenderPasses(CullRenderPassesWithNoQuads(), frame); renderer_->DecideRenderPassAllocationsForFrame(frame->render_passes); diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc index f32d0d8..ae7f1a0 100644 --- a/cc/trees/layer_tree_host_unittest.cc +++ b/cc/trees/layer_tree_host_unittest.cc @@ -2559,198 +2559,5 @@ class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest { SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestIOSurfaceDrawing); -class LayerTreeHostTestAsyncReadback : public LayerTreeHostTest { - protected: - virtual void SetupTree() OVERRIDE { - root = FakeContentLayer::Create(&client_); - root->SetBounds(gfx::Size(20, 20)); - - child = FakeContentLayer::Create(&client_); - child->SetBounds(gfx::Size(10, 10)); - root->AddChild(child); - - layer_tree_host()->SetRootLayer(root); - LayerTreeHostTest::SetupTree(); - } - - virtual void BeginTest() OVERRIDE { - PostSetNeedsCommitToMainThread(); - } - - virtual void DidCommitAndDrawFrame() { - int frame = layer_tree_host()->commit_number(); - switch (frame) { - case 1: - child->RequestCopyAsBitmap(base::Bind( - &LayerTreeHostTestAsyncReadback::BitmapCallback, - base::Unretained(this))); - EXPECT_EQ(0u, callbacks_.size()); - break; - case 2: - // Flush the message loops and make sure the callbacks run. - layer_tree_host()->SetNeedsCommit(); - break; - case 3: - ASSERT_EQ(1u, callbacks_.size()); - EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[0].ToString()); - - child->RequestCopyAsBitmap(base::Bind( - &LayerTreeHostTestAsyncReadback::BitmapCallback, - base::Unretained(this))); - root->RequestCopyAsBitmap(base::Bind( - &LayerTreeHostTestAsyncReadback::BitmapCallback, - base::Unretained(this))); - child->RequestCopyAsBitmap(base::Bind( - &LayerTreeHostTestAsyncReadback::BitmapCallback, - base::Unretained(this))); - EXPECT_EQ(1u, callbacks_.size()); - break; - case 4: - // Flush the message loops and make sure the callbacks run. - layer_tree_host()->SetNeedsCommit(); - break; - case 5: - ASSERT_EQ(4u, callbacks_.size()); - // The child was copied to a bitmap and passed back twice. - EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[1].ToString()); - EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[2].ToString()); - // The root was copied to a bitmap and passed back also. - EXPECT_EQ(gfx::Size(20, 20).ToString(), callbacks_[3].ToString()); - EndTest(); - break; - } - } - - void BitmapCallback(scoped_ptr<SkBitmap> bitmap) { - EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); - EXPECT_TRUE(bitmap); - callbacks_.push_back(gfx::Size(bitmap->width(), bitmap->height())); - } - - virtual void AfterTest() {} - - virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE { - if (use_gl_renderer_) - return FakeOutputSurface::Create3d().PassAs<OutputSurface>(); - return FakeOutputSurface::CreateSoftware( - make_scoped_ptr(new SoftwareOutputDevice)).PassAs<OutputSurface>(); - } - - bool use_gl_renderer_; - std::vector<gfx::Size> callbacks_; - FakeContentLayerClient client_; - scoped_refptr<FakeContentLayer> root; - scoped_refptr<FakeContentLayer> child; -}; - -TEST_F(LayerTreeHostTestAsyncReadback, GLRenderer_RunSingleThread) { - use_gl_renderer_ = true; - RunTest(false); -} - -TEST_F(LayerTreeHostTestAsyncReadback, GLRenderer_RunMultiThread) { - use_gl_renderer_ = true; - RunTest(true); -} - -TEST_F(LayerTreeHostTestAsyncReadback, SoftwareRenderer_RunSingleThread) { - use_gl_renderer_ = false; - RunTest(false); -} - -TEST_F(LayerTreeHostTestAsyncReadback, SoftwareRenderer_RunMultiThread) { - use_gl_renderer_ = false; - RunTest(true); -} - -class LayerTreeHostTestAsyncReadbackLayerDestroyed : public LayerTreeHostTest { - protected: - virtual void SetupTree() OVERRIDE { - root_ = FakeContentLayer::Create(&client_); - root_->SetBounds(gfx::Size(20, 20)); - - main_destroyed_ = FakeContentLayer::Create(&client_); - main_destroyed_->SetBounds(gfx::Size(15, 15)); - root_->AddChild(main_destroyed_); - - impl_destroyed_ = FakeContentLayer::Create(&client_); - impl_destroyed_->SetBounds(gfx::Size(10, 10)); - root_->AddChild(impl_destroyed_); - - layer_tree_host()->SetRootLayer(root_); - LayerTreeHostTest::SetupTree(); - } - - virtual void BeginTest() OVERRIDE { - callback_count_ = 0; - PostSetNeedsCommitToMainThread(); - } - - virtual void DidCommit() { - int frame = layer_tree_host()->commit_number(); - switch (frame) { - case 1: - main_destroyed_->RequestCopyAsBitmap(base::Bind( - &LayerTreeHostTestAsyncReadbackLayerDestroyed::BitmapCallback, - base::Unretained(this))); - impl_destroyed_->RequestCopyAsBitmap(base::Bind( - &LayerTreeHostTestAsyncReadbackLayerDestroyed::BitmapCallback, - base::Unretained(this))); - EXPECT_EQ(0, callback_count_); - - // Destroy the main thread layer right away. - main_destroyed_->RemoveFromParent(); - main_destroyed_ = NULL; - - // Should callback with a NULL bitmap. - EXPECT_EQ(1, callback_count_); - - // Prevent drawing so we can't make a copy of the impl_destroyed layer. - layer_tree_host()->SetViewportSize(gfx::Size()); - break; - case 2: - // Flush the message loops and make sure the callbacks run. - layer_tree_host()->SetNeedsCommit(); - break; - case 3: - // No drawing means no readback yet. - EXPECT_EQ(1, callback_count_); - - // Destroy the impl thread layer. - impl_destroyed_->RemoveFromParent(); - impl_destroyed_ = NULL; - - // No callback yet because it's on the impl side. - EXPECT_EQ(1, callback_count_); - break; - case 4: - // Flush the message loops and make sure the callbacks run. - layer_tree_host()->SetNeedsCommit(); - break; - case 5: - // We should get another callback with a NULL bitmap. - EXPECT_EQ(2, callback_count_); - EndTest(); - break; - } - } - - void BitmapCallback(scoped_ptr<SkBitmap> bitmap) { - EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); - EXPECT_FALSE(bitmap); - ++callback_count_; - } - - virtual void AfterTest() {} - - int callback_count_; - FakeContentLayerClient client_; - scoped_refptr<FakeContentLayer> root_; - scoped_refptr<FakeContentLayer> main_destroyed_; - scoped_refptr<FakeContentLayer> impl_destroyed_; -}; - -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestAsyncReadbackLayerDestroyed); - } // namespace } // namespace cc |