Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 16211002: Skip drawing unsupported layers in forced software mode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase on r203584 Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 "cc/trees/layer_tree_host_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 EXPECT_EQ(4.f, metadata.max_page_scale_factor); 1050 EXPECT_EQ(4.f, metadata.max_page_scale_factor);
1051 } 1051 }
1052 } 1052 }
1053 1053
1054 class DidDrawCheckLayer : public TiledLayerImpl { 1054 class DidDrawCheckLayer : public TiledLayerImpl {
1055 public: 1055 public:
1056 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { 1056 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) {
1057 return scoped_ptr<LayerImpl>(new DidDrawCheckLayer(tree_impl, id)); 1057 return scoped_ptr<LayerImpl>(new DidDrawCheckLayer(tree_impl, id));
1058 } 1058 }
1059 1059
1060 virtual bool WillDraw(DrawMode draw_mode, ResourceProvider* provider)
1061 OVERRIDE {
1062 will_draw_called_ = true;
1063 if (will_draw_returns_false_)
1064 return false;
1065 return TiledLayerImpl::WillDraw(draw_mode, provider);
1066 }
1067
1068 virtual void AppendQuads(QuadSink* quad_sink,
1069 AppendQuadsData* append_quads_data) OVERRIDE {
1070 append_quads_called_ = true;
1071 TiledLayerImpl::AppendQuads(quad_sink, append_quads_data);
1072 }
1073
1060 virtual void DidDraw(ResourceProvider* provider) OVERRIDE { 1074 virtual void DidDraw(ResourceProvider* provider) OVERRIDE {
1061 did_draw_called_ = true; 1075 did_draw_called_ = true;
1076 TiledLayerImpl::DidDraw(provider);
1062 } 1077 }
1063 1078
1064 virtual void WillDraw(ResourceProvider* provider) OVERRIDE { 1079 bool will_draw_called() const { return will_draw_called_; }
1065 will_draw_called_ = true; 1080 bool append_quads_called() const { return append_quads_called_; }
1066 } 1081 bool did_draw_called() const { return did_draw_called_; }
1067 1082
1068 bool did_draw_called() const { return did_draw_called_; } 1083 void set_will_draw_returns_false() { will_draw_returns_false_ = true; }
1069 bool will_draw_called() const { return will_draw_called_; }
1070 1084
1071 void ClearDidDrawCheck() { 1085 void ClearDidDrawCheck() {
1086 will_draw_called_ = false;
1087 append_quads_called_ = false;
1072 did_draw_called_ = false; 1088 did_draw_called_ = false;
1073 will_draw_called_ = false;
1074 } 1089 }
1075 1090
1076 protected: 1091 protected:
1077 DidDrawCheckLayer(LayerTreeImpl* tree_impl, int id) 1092 DidDrawCheckLayer(LayerTreeImpl* tree_impl, int id)
1078 : TiledLayerImpl(tree_impl, id), 1093 : TiledLayerImpl(tree_impl, id),
1079 did_draw_called_(false), 1094 will_draw_returns_false_(false),
1080 will_draw_called_(false) { 1095 will_draw_called_(false),
1096 append_quads_called_(false),
1097 did_draw_called_(false) {
1081 SetAnchorPoint(gfx::PointF()); 1098 SetAnchorPoint(gfx::PointF());
1082 SetBounds(gfx::Size(10, 10)); 1099 SetBounds(gfx::Size(10, 10));
1083 SetContentBounds(gfx::Size(10, 10)); 1100 SetContentBounds(gfx::Size(10, 10));
1084 SetDrawsContent(true); 1101 SetDrawsContent(true);
1085 set_skips_draw(false); 1102 set_skips_draw(false);
1086 draw_properties().visible_content_rect = gfx::Rect(0, 0, 10, 10); 1103 draw_properties().visible_content_rect = gfx::Rect(0, 0, 10, 10);
1087 1104
1088 scoped_ptr<LayerTilingData> tiler = 1105 scoped_ptr<LayerTilingData> tiler =
1089 LayerTilingData::Create(gfx::Size(100, 100), 1106 LayerTilingData::Create(gfx::Size(100, 100),
1090 LayerTilingData::HAS_BORDER_TEXELS); 1107 LayerTilingData::HAS_BORDER_TEXELS);
1091 tiler->SetBounds(content_bounds()); 1108 tiler->SetBounds(content_bounds());
1092 SetTilingData(*tiler.get()); 1109 SetTilingData(*tiler.get());
1093 } 1110 }
1094 1111
1095 private: 1112 private:
1113 bool will_draw_returns_false_;
1114 bool will_draw_called_;
1115 bool append_quads_called_;
1096 bool did_draw_called_; 1116 bool did_draw_called_;
1097 bool will_draw_called_;
1098 }; 1117 };
1099 1118
1119 TEST_F(LayerTreeHostImplTest, WillDrawReturningFalseDoesNotCall) {
1120 // The root layer is always drawn, so run this test on a child layer that
1121 // will be masked out by the root layer's bounds.
1122 host_impl_->active_tree()->SetRootLayer(
1123 DidDrawCheckLayer::Create(host_impl_->active_tree(), 1));
1124 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(
1125 host_impl_->active_tree()->root_layer());
1126
1127 root->AddChild(DidDrawCheckLayer::Create(host_impl_->active_tree(), 2));
1128 DidDrawCheckLayer* layer =
1129 static_cast<DidDrawCheckLayer*>(root->children()[0]);
1130
1131 {
1132 LayerTreeHostImpl::FrameData frame;
1133 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect(10, 10)));
1134 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1135 host_impl_->DidDrawAllLayers(frame);
1136
1137 EXPECT_TRUE(layer->will_draw_called());
1138 EXPECT_TRUE(layer->append_quads_called());
1139 EXPECT_TRUE(layer->did_draw_called());
1140 }
1141
1142 {
1143 LayerTreeHostImpl::FrameData frame;
1144
1145 layer->set_will_draw_returns_false();
1146 layer->ClearDidDrawCheck();
1147
1148 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect(10, 10)));
1149 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1150 host_impl_->DidDrawAllLayers(frame);
1151
1152 EXPECT_TRUE(layer->will_draw_called());
1153 EXPECT_FALSE(layer->append_quads_called());
1154 EXPECT_FALSE(layer->did_draw_called());
1155 }
1156 }
1157
1100 TEST_F(LayerTreeHostImplTest, DidDrawNotCalledOnHiddenLayer) { 1158 TEST_F(LayerTreeHostImplTest, DidDrawNotCalledOnHiddenLayer) {
1101 // The root layer is always drawn, so run this test on a child layer that 1159 // The root layer is always drawn, so run this test on a child layer that
1102 // will be masked out by the root layer's bounds. 1160 // will be masked out by the root layer's bounds.
1103 host_impl_->active_tree()->SetRootLayer( 1161 host_impl_->active_tree()->SetRootLayer(
1104 DidDrawCheckLayer::Create(host_impl_->active_tree(), 1)); 1162 DidDrawCheckLayer::Create(host_impl_->active_tree(), 1));
1105 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>( 1163 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(
1106 host_impl_->active_tree()->root_layer()); 1164 host_impl_->active_tree()->root_layer());
1107 root->SetMasksToBounds(true); 1165 root->SetMasksToBounds(true);
1108 1166
1109 root->AddChild(DidDrawCheckLayer::Create(host_impl_->active_tree(), 2)); 1167 root->AddChild(DidDrawCheckLayer::Create(host_impl_->active_tree(), 2));
(...skipping 4632 matching lines...) Expand 10 before | Expand all | Expand 10 after
5742 DrawFrame(); 5800 DrawFrame();
5743 5801
5744 EXPECT_EQ(1, software_device->frames_began_); 5802 EXPECT_EQ(1, software_device->frames_began_);
5745 EXPECT_EQ(1, software_device->frames_ended_); 5803 EXPECT_EQ(1, software_device->frames_ended_);
5746 5804
5747 // Call other API methods that are likely to hit NULL pointer in this mode. 5805 // Call other API methods that are likely to hit NULL pointer in this mode.
5748 EXPECT_TRUE(host_impl_->AsValue()); 5806 EXPECT_TRUE(host_impl_->AsValue());
5749 EXPECT_TRUE(host_impl_->ActivationStateAsValue()); 5807 EXPECT_TRUE(host_impl_->ActivationStateAsValue());
5750 } 5808 }
5751 5809
5810 TEST_F(LayerTreeHostImplTest,
5811 ForcedDrawToSoftwareDeviceSkipsUnsupportedLayers) {
5812 FakeOutputSurface* output_surface = FakeOutputSurface::CreateDeferredGL(
5813 scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice())).release();
5814 host_impl_->InitializeRenderer(
5815 scoped_ptr<OutputSurface>(output_surface));
5816
5817 output_surface->set_forced_draw_to_software_device(true);
5818 EXPECT_TRUE(output_surface->ForcedDrawToSoftwareDevice());
5819
5820 // SolidColorLayerImpl will be drawn.
5821 scoped_ptr<SolidColorLayerImpl> root_layer =
5822 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1);
5823
5824 // VideoLayerImpl will not be drawn.
5825 FakeVideoFrameProvider provider;
5826 scoped_ptr<VideoLayerImpl> video_layer =
5827 VideoLayerImpl::Create(host_impl_->active_tree(), 2, &provider);
5828 video_layer->SetBounds(gfx::Size(10, 10));
5829 video_layer->SetContentBounds(gfx::Size(10, 10));
5830 video_layer->SetDrawsContent(true);
5831 root_layer->AddChild(video_layer.PassAs<LayerImpl>());
5832 SetupRootLayerImpl(root_layer.PassAs<LayerImpl>());
5833
5834 LayerTreeHostImpl::FrameData frame;
5835 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
5836 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
5837 host_impl_->DidDrawAllLayers(frame);
5838
5839 EXPECT_EQ(1u, frame.will_draw_layers.size());
5840 EXPECT_EQ(host_impl_->active_tree()->root_layer(), frame.will_draw_layers[0]);
5841 }
5842
5752 } // namespace 5843 } // namespace
5753 } // namespace cc 5844 } // namespace cc
OLDNEW
« cc/layers/video_layer_impl.cc ('K') | « cc/trees/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698