summaryrefslogtreecommitdiffstats
path: root/cc/trees/layer_tree_host_impl_unittest.cc
diff options
context:
space:
mode:
authorboliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-02 23:47:59 +0000
committerboliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-02 23:47:59 +0000
commitffbb221c8dc7acd0dbe202d569c3d4b9a62fafb0 (patch)
tree4ba55c15fbd05cb32da487e4647610f9cf2c96ad /cc/trees/layer_tree_host_impl_unittest.cc
parentff875be5f3f3db4cdc5bbfe4a014580867c7a044 (diff)
downloadchromium_src-ffbb221c8dc7acd0dbe202d569c3d4b9a62fafb0.zip
chromium_src-ffbb221c8dc7acd0dbe202d569c3d4b9a62fafb0.tar.gz
chromium_src-ffbb221c8dc7acd0dbe202d569c3d4b9a62fafb0.tar.bz2
Skip drawing unsupported layers in forced software mode
Only draw PictureLayer, SolidColorLayer, and ScrollbarLayer if using solid color scrollbars. Changes contract of LayerImpl WillDraw/AppendQuads/DidDraw. Now WillDraw returns a bool, and AppendQuads/DidDraw will be skipped if it returns false. BUG=245047 Review URL: https://chromiumcodereview.appspot.com/16211002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203637 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/trees/layer_tree_host_impl_unittest.cc')
-rw-r--r--cc/trees/layer_tree_host_impl_unittest.cc109
1 files changed, 100 insertions, 9 deletions
diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc
index 6976087..b2cc816 100644
--- a/cc/trees/layer_tree_host_impl_unittest.cc
+++ b/cc/trees/layer_tree_host_impl_unittest.cc
@@ -1057,27 +1057,44 @@ class DidDrawCheckLayer : public TiledLayerImpl {
return scoped_ptr<LayerImpl>(new DidDrawCheckLayer(tree_impl, id));
}
- virtual void DidDraw(ResourceProvider* provider) OVERRIDE {
- did_draw_called_ = true;
+ virtual bool WillDraw(DrawMode draw_mode, ResourceProvider* provider)
+ OVERRIDE {
+ will_draw_called_ = true;
+ if (will_draw_returns_false_)
+ return false;
+ return TiledLayerImpl::WillDraw(draw_mode, provider);
}
- virtual void WillDraw(ResourceProvider* provider) OVERRIDE {
- will_draw_called_ = true;
+ virtual void AppendQuads(QuadSink* quad_sink,
+ AppendQuadsData* append_quads_data) OVERRIDE {
+ append_quads_called_ = true;
+ TiledLayerImpl::AppendQuads(quad_sink, append_quads_data);
+ }
+
+ virtual void DidDraw(ResourceProvider* provider) OVERRIDE {
+ did_draw_called_ = true;
+ TiledLayerImpl::DidDraw(provider);
}
- bool did_draw_called() const { return did_draw_called_; }
bool will_draw_called() const { return will_draw_called_; }
+ bool append_quads_called() const { return append_quads_called_; }
+ bool did_draw_called() const { return did_draw_called_; }
+
+ void set_will_draw_returns_false() { will_draw_returns_false_ = true; }
void ClearDidDrawCheck() {
- did_draw_called_ = false;
will_draw_called_ = false;
+ append_quads_called_ = false;
+ did_draw_called_ = false;
}
protected:
DidDrawCheckLayer(LayerTreeImpl* tree_impl, int id)
: TiledLayerImpl(tree_impl, id),
- did_draw_called_(false),
- will_draw_called_(false) {
+ will_draw_returns_false_(false),
+ will_draw_called_(false),
+ append_quads_called_(false),
+ did_draw_called_(false) {
SetAnchorPoint(gfx::PointF());
SetBounds(gfx::Size(10, 10));
SetContentBounds(gfx::Size(10, 10));
@@ -1093,10 +1110,51 @@ class DidDrawCheckLayer : public TiledLayerImpl {
}
private:
- bool did_draw_called_;
+ bool will_draw_returns_false_;
bool will_draw_called_;
+ bool append_quads_called_;
+ bool did_draw_called_;
};
+TEST_F(LayerTreeHostImplTest, WillDrawReturningFalseDoesNotCall) {
+ // The root layer is always drawn, so run this test on a child layer that
+ // will be masked out by the root layer's bounds.
+ host_impl_->active_tree()->SetRootLayer(
+ DidDrawCheckLayer::Create(host_impl_->active_tree(), 1));
+ DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(
+ host_impl_->active_tree()->root_layer());
+
+ root->AddChild(DidDrawCheckLayer::Create(host_impl_->active_tree(), 2));
+ DidDrawCheckLayer* layer =
+ static_cast<DidDrawCheckLayer*>(root->children()[0]);
+
+ {
+ LayerTreeHostImpl::FrameData frame;
+ EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect(10, 10)));
+ host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
+ host_impl_->DidDrawAllLayers(frame);
+
+ EXPECT_TRUE(layer->will_draw_called());
+ EXPECT_TRUE(layer->append_quads_called());
+ EXPECT_TRUE(layer->did_draw_called());
+ }
+
+ {
+ LayerTreeHostImpl::FrameData frame;
+
+ layer->set_will_draw_returns_false();
+ layer->ClearDidDrawCheck();
+
+ EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect(10, 10)));
+ host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
+ host_impl_->DidDrawAllLayers(frame);
+
+ EXPECT_TRUE(layer->will_draw_called());
+ EXPECT_FALSE(layer->append_quads_called());
+ EXPECT_FALSE(layer->did_draw_called());
+ }
+}
+
TEST_F(LayerTreeHostImplTest, DidDrawNotCalledOnHiddenLayer) {
// The root layer is always drawn, so run this test on a child layer that
// will be masked out by the root layer's bounds.
@@ -5749,5 +5807,38 @@ TEST_F(LayerTreeHostImplTest, ForcedDrawToSoftwareDeviceBasicRender) {
EXPECT_TRUE(host_impl_->ActivationStateAsValue());
}
+TEST_F(LayerTreeHostImplTest,
+ ForcedDrawToSoftwareDeviceSkipsUnsupportedLayers) {
+ FakeOutputSurface* output_surface = FakeOutputSurface::CreateDeferredGL(
+ scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice())).release();
+ host_impl_->InitializeRenderer(
+ scoped_ptr<OutputSurface>(output_surface));
+
+ output_surface->set_forced_draw_to_software_device(true);
+ EXPECT_TRUE(output_surface->ForcedDrawToSoftwareDevice());
+
+ // SolidColorLayerImpl will be drawn.
+ scoped_ptr<SolidColorLayerImpl> root_layer =
+ SolidColorLayerImpl::Create(host_impl_->active_tree(), 1);
+
+ // VideoLayerImpl will not be drawn.
+ FakeVideoFrameProvider provider;
+ scoped_ptr<VideoLayerImpl> video_layer =
+ VideoLayerImpl::Create(host_impl_->active_tree(), 2, &provider);
+ video_layer->SetBounds(gfx::Size(10, 10));
+ video_layer->SetContentBounds(gfx::Size(10, 10));
+ video_layer->SetDrawsContent(true);
+ root_layer->AddChild(video_layer.PassAs<LayerImpl>());
+ SetupRootLayerImpl(root_layer.PassAs<LayerImpl>());
+
+ LayerTreeHostImpl::FrameData frame;
+ EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
+ host_impl_->DidDrawAllLayers(frame);
+
+ EXPECT_EQ(1u, frame.will_draw_layers.size());
+ EXPECT_EQ(host_impl_->active_tree()->root_layer(), frame.will_draw_layers[0]);
+}
+
} // namespace
} // namespace cc