OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 set_delegate(this); | 125 set_delegate(this); |
126 } | 126 } |
127 | 127 |
128 virtual ~ColoredLayer() { } | 128 virtual ~ColoredLayer() { } |
129 | 129 |
130 // Overridden from LayerDelegate: | 130 // Overridden from LayerDelegate: |
131 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { | 131 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { |
132 canvas->DrawColor(color_); | 132 canvas->DrawColor(color_); |
133 } | 133 } |
134 | 134 |
| 135 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { |
| 136 } |
| 137 |
135 private: | 138 private: |
136 SkColor color_; | 139 SkColor color_; |
137 }; | 140 }; |
138 | 141 |
139 class LayerWithRealCompositorTest : public testing::Test { | 142 class LayerWithRealCompositorTest : public testing::Test { |
140 public: | 143 public: |
141 LayerWithRealCompositorTest() { | 144 LayerWithRealCompositorTest() { |
142 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) { | 145 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) { |
143 test_data_directory_ = test_data_directory_.AppendASCII("compositor"); | 146 test_data_directory_ = test_data_directory_.AppendASCII("compositor"); |
144 } else { | 147 } else { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 208 |
206 // The root directory for test files. | 209 // The root directory for test files. |
207 FilePath test_data_directory_; | 210 FilePath test_data_directory_; |
208 | 211 |
209 DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest); | 212 DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest); |
210 }; | 213 }; |
211 | 214 |
212 // LayerDelegate that paints colors to the layer. | 215 // LayerDelegate that paints colors to the layer. |
213 class TestLayerDelegate : public LayerDelegate { | 216 class TestLayerDelegate : public LayerDelegate { |
214 public: | 217 public: |
215 explicit TestLayerDelegate() : color_index_(0) {} | 218 explicit TestLayerDelegate() { reset(); } |
216 virtual ~TestLayerDelegate() {} | 219 virtual ~TestLayerDelegate() {} |
217 | 220 |
218 void AddColor(SkColor color) { | 221 void AddColor(SkColor color) { |
219 colors_.push_back(color); | 222 colors_.push_back(color); |
220 } | 223 } |
221 | 224 |
222 const gfx::Size& paint_size() const { return paint_size_; } | 225 const gfx::Size& paint_size() const { return paint_size_; } |
223 int color_index() const { return color_index_; } | 226 int color_index() const { return color_index_; } |
224 | 227 |
225 std::string ToScaleString() const { | 228 std::string ToScaleString() const { |
226 return StringPrintf("%.1f %.1f", scale_x_, scale_y_); | 229 return StringPrintf("%.1f %.1f", scale_x_, scale_y_); |
227 } | 230 } |
228 | 231 |
| 232 float device_scale_factor() const { |
| 233 return device_scale_factor_; |
| 234 } |
| 235 |
229 // Overridden from LayerDelegate: | 236 // Overridden from LayerDelegate: |
230 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { | 237 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { |
231 SkBitmap contents = canvas->ExtractBitmap(); | 238 SkBitmap contents = canvas->ExtractBitmap(); |
232 paint_size_ = gfx::Size(contents.width(), contents.height()); | 239 paint_size_ = gfx::Size(contents.width(), contents.height()); |
233 canvas->FillRect(gfx::Rect(paint_size_), colors_[color_index_]); | 240 canvas->FillRect(gfx::Rect(paint_size_), colors_[color_index_]); |
234 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size()); | 241 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size()); |
235 const SkMatrix& matrix = canvas->sk_canvas()->getTotalMatrix(); | 242 const SkMatrix& matrix = canvas->sk_canvas()->getTotalMatrix(); |
236 scale_x_ = matrix.getScaleX(); | 243 scale_x_ = matrix.getScaleX(); |
237 scale_y_ = matrix.getScaleY(); | 244 scale_y_ = matrix.getScaleY(); |
238 } | 245 } |
239 | 246 |
| 247 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { |
| 248 device_scale_factor_ = device_scale_factor; |
| 249 } |
| 250 |
240 void reset() { | 251 void reset() { |
241 color_index_ = 0; | 252 color_index_ = 0; |
242 paint_size_.SetSize(0, 0); | 253 paint_size_.SetSize(0, 0); |
243 scale_x_ = scale_y_ = 0.0f; | 254 scale_x_ = scale_y_ = 0.0f; |
| 255 device_scale_factor_ = 0.0f; |
244 } | 256 } |
245 | 257 |
246 private: | 258 private: |
247 std::vector<SkColor> colors_; | 259 std::vector<SkColor> colors_; |
248 int color_index_; | 260 int color_index_; |
249 gfx::Size paint_size_; | 261 gfx::Size paint_size_; |
250 float scale_x_; | 262 float scale_x_; |
251 float scale_y_; | 263 float scale_y_; |
| 264 float device_scale_factor_; |
252 | 265 |
253 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate); | 266 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate); |
254 }; | 267 }; |
255 | 268 |
256 // LayerDelegate that verifies that a layer was asked to update its canvas. | 269 // LayerDelegate that verifies that a layer was asked to update its canvas. |
257 class DrawTreeLayerDelegate : public LayerDelegate { | 270 class DrawTreeLayerDelegate : public LayerDelegate { |
258 public: | 271 public: |
259 DrawTreeLayerDelegate() : painted_(false) {} | 272 DrawTreeLayerDelegate() : painted_(false) {} |
260 virtual ~DrawTreeLayerDelegate() {} | 273 virtual ~DrawTreeLayerDelegate() {} |
261 | 274 |
262 void Reset() { | 275 void Reset() { |
263 painted_ = false; | 276 painted_ = false; |
264 } | 277 } |
265 | 278 |
266 bool painted() const { return painted_; } | 279 bool painted() const { return painted_; } |
267 | 280 |
268 private: | 281 private: |
269 // Overridden from LayerDelegate: | 282 // Overridden from LayerDelegate: |
270 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { | 283 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { |
271 painted_ = true; | 284 painted_ = true; |
272 } | 285 } |
| 286 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { |
| 287 } |
273 | 288 |
274 bool painted_; | 289 bool painted_; |
275 | 290 |
276 DISALLOW_COPY_AND_ASSIGN(DrawTreeLayerDelegate); | 291 DISALLOW_COPY_AND_ASSIGN(DrawTreeLayerDelegate); |
277 }; | 292 }; |
278 | 293 |
279 // The simplest possible layer delegate. Does nothing. | 294 // The simplest possible layer delegate. Does nothing. |
280 class NullLayerDelegate : public LayerDelegate { | 295 class NullLayerDelegate : public LayerDelegate { |
281 public: | 296 public: |
282 NullLayerDelegate() {} | 297 NullLayerDelegate() {} |
283 virtual ~NullLayerDelegate() {} | 298 virtual ~NullLayerDelegate() {} |
284 | 299 |
285 private: | 300 private: |
286 // Overridden from LayerDelegate: | 301 // Overridden from LayerDelegate: |
287 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { | 302 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { |
288 } | 303 } |
| 304 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { |
| 305 } |
289 | 306 |
290 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); | 307 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); |
291 }; | 308 }; |
292 | 309 |
293 // Remembers if it has been notified. | 310 // Remembers if it has been notified. |
294 class TestCompositorObserver : public CompositorObserver { | 311 class TestCompositorObserver : public CompositorObserver { |
295 public: | 312 public: |
296 TestCompositorObserver() : started_(false), ended_(false) {} | 313 TestCompositorObserver() : started_(false), ended_(false) {} |
297 | 314 |
298 bool notified() const { return started_ && ended_; } | 315 bool notified() const { return started_ && ended_; } |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 paint_count_++; | 1010 paint_count_++; |
994 if (!schedule_paint_rect_.IsEmpty()) { | 1011 if (!schedule_paint_rect_.IsEmpty()) { |
995 layer_->SchedulePaint(schedule_paint_rect_); | 1012 layer_->SchedulePaint(schedule_paint_rect_); |
996 schedule_paint_rect_ = gfx::Rect(); | 1013 schedule_paint_rect_ = gfx::Rect(); |
997 } | 1014 } |
998 SkRect sk_clip_rect; | 1015 SkRect sk_clip_rect; |
999 if (canvas->sk_canvas()->getClipBounds(&sk_clip_rect)) | 1016 if (canvas->sk_canvas()->getClipBounds(&sk_clip_rect)) |
1000 last_clip_rect_ = gfx::SkRectToRect(sk_clip_rect); | 1017 last_clip_rect_ = gfx::SkRectToRect(sk_clip_rect); |
1001 } | 1018 } |
1002 | 1019 |
| 1020 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { |
| 1021 } |
| 1022 |
1003 int paint_count_; | 1023 int paint_count_; |
1004 Layer* layer_; | 1024 Layer* layer_; |
1005 gfx::Rect schedule_paint_rect_; | 1025 gfx::Rect schedule_paint_rect_; |
1006 gfx::Rect last_clip_rect_; | 1026 gfx::Rect last_clip_rect_; |
1007 | 1027 |
1008 DISALLOW_COPY_AND_ASSIGN(SchedulePaintLayerDelegate); | 1028 DISALLOW_COPY_AND_ASSIGN(SchedulePaintLayerDelegate); |
1009 }; | 1029 }; |
1010 | 1030 |
1011 } // namespace | 1031 } // namespace |
1012 | 1032 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 GetCompositor()->SetRootLayer(root.get()); | 1084 GetCompositor()->SetRootLayer(root.get()); |
1065 root->Add(l1.get()); | 1085 root->Add(l1.get()); |
1066 RunPendingMessages(); | 1086 RunPendingMessages(); |
1067 | 1087 |
1068 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1088 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
1069 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1089 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
1070 gfx::Size size_in_pixel = root->web_layer().bounds(); | 1090 gfx::Size size_in_pixel = root->web_layer().bounds(); |
1071 EXPECT_EQ("200x220", size_in_pixel.ToString()); | 1091 EXPECT_EQ("200x220", size_in_pixel.ToString()); |
1072 size_in_pixel = l1->web_layer().bounds(); | 1092 size_in_pixel = l1->web_layer().bounds(); |
1073 EXPECT_EQ("140x180", size_in_pixel.ToString()); | 1093 EXPECT_EQ("140x180", size_in_pixel.ToString()); |
| 1094 // No scale change, so no scale notification. |
| 1095 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); |
| 1096 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); |
1074 | 1097 |
1075 RunPendingMessages(); | 1098 RunPendingMessages(); |
1076 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); | 1099 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); |
1077 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); | 1100 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); |
1078 | 1101 |
1079 // Scale up to 2.0. Changing scale doesn't change the bounds in DIP. | 1102 // Scale up to 2.0. Changing scale doesn't change the bounds in DIP. |
1080 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); | 1103 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); |
1081 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1104 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
1082 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1105 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
1083 // Pixel size must have been scaled up. | 1106 // Pixel size must have been scaled up. |
1084 size_in_pixel = root->web_layer().bounds(); | 1107 size_in_pixel = root->web_layer().bounds(); |
1085 EXPECT_EQ("400x440", size_in_pixel.ToString()); | 1108 EXPECT_EQ("400x440", size_in_pixel.ToString()); |
1086 size_in_pixel = l1->web_layer().bounds(); | 1109 size_in_pixel = l1->web_layer().bounds(); |
1087 EXPECT_EQ("280x360", size_in_pixel.ToString()); | 1110 EXPECT_EQ("280x360", size_in_pixel.ToString()); |
| 1111 // New scale factor must have been notified. |
| 1112 EXPECT_EQ(2.0f, root_delegate.device_scale_factor()); |
| 1113 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); |
1088 | 1114 |
1089 // Canvas size must have been scaled down up. | 1115 // Canvas size must have been scaled down up. |
1090 RunPendingMessages(); | 1116 RunPendingMessages(); |
1091 EXPECT_EQ("400x440", root_delegate.paint_size().ToString()); | 1117 EXPECT_EQ("400x440", root_delegate.paint_size().ToString()); |
1092 EXPECT_EQ("2.0 2.0", root_delegate.ToScaleString()); | 1118 EXPECT_EQ("2.0 2.0", root_delegate.ToScaleString()); |
1093 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); | 1119 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); |
1094 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); | 1120 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); |
1095 | 1121 |
1096 // Scale down back to 1.0f. | 1122 // Scale down back to 1.0f. |
1097 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); | 1123 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); |
1098 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1124 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
1099 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1125 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
1100 // Pixel size must have been scaled down. | 1126 // Pixel size must have been scaled down. |
1101 size_in_pixel = root->web_layer().bounds(); | 1127 size_in_pixel = root->web_layer().bounds(); |
1102 EXPECT_EQ("200x220", size_in_pixel.ToString()); | 1128 EXPECT_EQ("200x220", size_in_pixel.ToString()); |
1103 size_in_pixel = l1->web_layer().bounds(); | 1129 size_in_pixel = l1->web_layer().bounds(); |
1104 EXPECT_EQ("140x180", size_in_pixel.ToString()); | 1130 EXPECT_EQ("140x180", size_in_pixel.ToString()); |
| 1131 // New scale factor must have been notified. |
| 1132 EXPECT_EQ(1.0f, root_delegate.device_scale_factor()); |
| 1133 EXPECT_EQ(1.0f, l1_delegate.device_scale_factor()); |
1105 | 1134 |
1106 // Canvas size must have been scaled down too. | 1135 // Canvas size must have been scaled down too. |
1107 RunPendingMessages(); | 1136 RunPendingMessages(); |
1108 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); | 1137 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); |
1109 EXPECT_EQ("1.0 1.0", root_delegate.ToScaleString()); | 1138 EXPECT_EQ("1.0 1.0", root_delegate.ToScaleString()); |
1110 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); | 1139 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); |
1111 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); | 1140 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); |
1112 | 1141 |
1113 root_delegate.reset(); | 1142 root_delegate.reset(); |
1114 l1_delegate.reset(); | 1143 l1_delegate.reset(); |
1115 // Just changing the size shouldn't trigger repaint. | 1144 // Just changing the size shouldn't notify the scale change nor |
| 1145 // trigger repaint. |
1116 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); | 1146 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); |
| 1147 // No scale change, so no scale notification. |
| 1148 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); |
| 1149 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); |
1117 RunPendingMessages(); | 1150 RunPendingMessages(); |
1118 EXPECT_EQ("0x0", root_delegate.paint_size().ToString()); | 1151 EXPECT_EQ("0x0", root_delegate.paint_size().ToString()); |
1119 EXPECT_EQ("0.0 0.0", root_delegate.ToScaleString()); | 1152 EXPECT_EQ("0.0 0.0", root_delegate.ToScaleString()); |
1120 EXPECT_EQ("0x0", l1_delegate.paint_size().ToString()); | 1153 EXPECT_EQ("0x0", l1_delegate.paint_size().ToString()); |
1121 EXPECT_EQ("0.0 0.0", l1_delegate.ToScaleString()); | 1154 EXPECT_EQ("0.0 0.0", l1_delegate.ToScaleString()); |
1122 } | 1155 } |
1123 | 1156 |
1124 TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleReparent) { | 1157 TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleReparent) { |
1125 test::ScopedDIPEnablerForTest enable; | 1158 test::ScopedDIPEnablerForTest enable; |
1126 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, | 1159 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, |
1127 gfx::Rect(10, 20, 200, 220))); | 1160 gfx::Rect(10, 20, 200, 220))); |
1128 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, | 1161 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, |
1129 gfx::Rect(10, 20, 140, 180))); | 1162 gfx::Rect(10, 20, 140, 180))); |
1130 TestLayerDelegate l1_delegate; | 1163 TestLayerDelegate l1_delegate; |
1131 l1_delegate.AddColor(SK_ColorWHITE); | 1164 l1_delegate.AddColor(SK_ColorWHITE); |
1132 l1->set_delegate(&l1_delegate); | 1165 l1->set_delegate(&l1_delegate); |
1133 | 1166 |
1134 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); | 1167 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); |
1135 GetCompositor()->SetRootLayer(root.get()); | 1168 GetCompositor()->SetRootLayer(root.get()); |
1136 RunPendingMessages(); | 1169 RunPendingMessages(); |
1137 | 1170 |
1138 root->Add(l1.get()); | 1171 root->Add(l1.get()); |
1139 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1172 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
1140 gfx::Size size_in_pixel = l1->web_layer().bounds(); | 1173 gfx::Size size_in_pixel = l1->web_layer().bounds(); |
1141 EXPECT_EQ("140x180", size_in_pixel.ToString()); | 1174 EXPECT_EQ("140x180", size_in_pixel.ToString()); |
| 1175 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); |
1142 | 1176 |
1143 RunPendingMessages(); | 1177 RunPendingMessages(); |
1144 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); | 1178 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); |
1145 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); | 1179 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); |
1146 | 1180 |
1147 // Remove l1 from root and change the scale. | 1181 // Remove l1 from root and change the scale. |
1148 root->Remove(l1.get()); | 1182 root->Remove(l1.get()); |
1149 EXPECT_EQ(NULL, l1->parent()); | 1183 EXPECT_EQ(NULL, l1->parent()); |
1150 EXPECT_EQ(NULL, l1->GetCompositor()); | 1184 EXPECT_EQ(NULL, l1->GetCompositor()); |
1151 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); | 1185 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); |
1152 // Sanity check on root and l1. | 1186 // Sanity check on root and l1. |
1153 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1187 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
1154 size_in_pixel = l1->web_layer().bounds(); | 1188 size_in_pixel = l1->web_layer().bounds(); |
1155 EXPECT_EQ("140x180", size_in_pixel.ToString()); | 1189 EXPECT_EQ("140x180", size_in_pixel.ToString()); |
1156 | 1190 |
1157 | 1191 |
1158 root->Add(l1.get()); | 1192 root->Add(l1.get()); |
1159 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1193 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
1160 size_in_pixel = l1->web_layer().bounds(); | 1194 size_in_pixel = l1->web_layer().bounds(); |
1161 EXPECT_EQ("280x360", size_in_pixel.ToString()); | 1195 EXPECT_EQ("280x360", size_in_pixel.ToString()); |
| 1196 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); |
1162 RunPendingMessages(); | 1197 RunPendingMessages(); |
1163 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); | 1198 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); |
1164 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); | 1199 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); |
1165 } | 1200 } |
1166 | 1201 |
1167 // Tests layer::set_scale_canvas(false). | 1202 // Tests layer::set_scale_canvas(false). |
1168 TEST_F(LayerWithRealCompositorTest, MAYBE_NoScaleCanvas) { | 1203 TEST_F(LayerWithRealCompositorTest, MAYBE_NoScaleCanvas) { |
1169 test::ScopedDIPEnablerForTest enable; | 1204 test::ScopedDIPEnablerForTest enable; |
1170 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, | 1205 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, |
1171 gfx::Rect(10, 20, 200, 220))); | 1206 gfx::Rect(10, 20, 200, 220))); |
1172 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, | 1207 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, |
1173 gfx::Rect(10, 20, 140, 180))); | 1208 gfx::Rect(10, 20, 140, 180))); |
1174 l1->set_scale_canvas(false); | 1209 l1->set_scale_canvas(false); |
1175 root->Add(l1.get()); | 1210 root->Add(l1.get()); |
1176 TestLayerDelegate l1_delegate; | 1211 TestLayerDelegate l1_delegate; |
1177 l1_delegate.AddColor(SK_ColorWHITE); | 1212 l1_delegate.AddColor(SK_ColorWHITE); |
1178 l1->set_delegate(&l1_delegate); | 1213 l1->set_delegate(&l1_delegate); |
1179 | 1214 |
1180 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); | 1215 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); |
1181 GetCompositor()->SetRootLayer(root.get()); | 1216 GetCompositor()->SetRootLayer(root.get()); |
| 1217 // Scale factor change is notified regardless of scale_canvas flag. |
| 1218 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); |
| 1219 |
1182 RunPendingMessages(); | 1220 RunPendingMessages(); |
1183 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); | 1221 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); |
1184 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); | 1222 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); |
1185 } | 1223 } |
1186 | 1224 |
1187 // Verifies that when changing bounds on a layer that is invisible, and then | 1225 // Verifies that when changing bounds on a layer that is invisible, and then |
1188 // made visible, the right thing happens: | 1226 // made visible, the right thing happens: |
1189 // - if just a move, then no painting should happen. | 1227 // - if just a move, then no painting should happen. |
1190 // - if a resize, the layer should be repainted. | 1228 // - if a resize, the layer should be repainted. |
1191 TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) { | 1229 TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) { |
(...skipping 30 matching lines...) Expand all Loading... |
1222 | 1260 |
1223 // Resize layer. | 1261 // Resize layer. |
1224 child->SetBounds(gfx::Rect(200, 200, 400, 400)); | 1262 child->SetBounds(gfx::Rect(200, 200, 400, 400)); |
1225 child->SetVisible(true); | 1263 child->SetVisible(true); |
1226 EXPECT_TRUE(schedule_draw_invoked_); | 1264 EXPECT_TRUE(schedule_draw_invoked_); |
1227 DrawTree(root.get()); | 1265 DrawTree(root.get()); |
1228 EXPECT_TRUE(delegate.painted()); | 1266 EXPECT_TRUE(delegate.painted()); |
1229 } | 1267 } |
1230 | 1268 |
1231 } // namespace ui | 1269 } // namespace ui |
OLD | NEW |