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

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

Issue 1489713004: Remove the clip parameter from ContentLayerClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@clipremoval
Patch Set: Created 5 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "build/build_config.h" 5 #include "build/build_config.h"
6 #include "cc/layers/content_layer_client.h" 6 #include "cc/layers/content_layer_client.h"
7 #include "cc/layers/picture_image_layer.h" 7 #include "cc/layers/picture_image_layer.h"
8 #include "cc/layers/picture_layer.h" 8 #include "cc/layers/picture_layer.h"
9 #include "cc/layers/solid_color_layer.h" 9 #include "cc/layers/solid_color_layer.h"
10 #include "cc/playback/display_item_list_settings.h" 10 #include "cc/playback/display_item_list_settings.h"
(...skipping 17 matching lines...) Expand all
28 public: 28 public:
29 explicit MaskContentLayerClient(const gfx::Size& bounds) : bounds_(bounds) {} 29 explicit MaskContentLayerClient(const gfx::Size& bounds) : bounds_(bounds) {}
30 ~MaskContentLayerClient() override {} 30 ~MaskContentLayerClient() override {}
31 31
32 bool FillsBoundsCompletely() const override { return false; } 32 bool FillsBoundsCompletely() const override { return false; }
33 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } 33 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; }
34 34
35 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } 35 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); }
36 36
37 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( 37 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
38 const gfx::Rect& clip,
39 PaintingControlSetting picture_control) override { 38 PaintingControlSetting picture_control) override {
40 SkPictureRecorder recorder; 39 SkPictureRecorder recorder;
41 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( 40 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(
42 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); 41 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_))));
43 42
44 SkPaint paint; 43 SkPaint paint;
45 paint.setStyle(SkPaint::kStroke_Style); 44 paint.setStyle(SkPaint::kStroke_Style);
46 paint.setStrokeWidth(SkIntToScalar(2)); 45 paint.setStrokeWidth(SkIntToScalar(2));
47 paint.setColor(SK_ColorWHITE); 46 paint.setColor(SK_ColorWHITE);
48 47
49 canvas->clear(SK_ColorTRANSPARENT); 48 canvas->clear(SK_ColorTRANSPARENT);
50 gfx::Rect inset_rect(bounds_); 49 gfx::Rect inset_rect(bounds_);
51 while (!inset_rect.IsEmpty()) { 50 while (!inset_rect.IsEmpty()) {
52 inset_rect.Inset(3, 3, 2, 2); 51 inset_rect.Inset(3, 3, 2, 2);
53 canvas->drawRect( 52 canvas->drawRect(
54 SkRect::MakeXYWH(inset_rect.x(), inset_rect.y(), 53 SkRect::MakeXYWH(inset_rect.x(), inset_rect.y(),
55 inset_rect.width(), inset_rect.height()), 54 inset_rect.width(), inset_rect.height()),
56 paint); 55 paint);
57 inset_rect.Inset(3, 3, 2, 2); 56 inset_rect.Inset(3, 3, 2, 2);
58 } 57 }
59 58
60 scoped_refptr<DisplayItemList> display_list = 59 scoped_refptr<DisplayItemList> display_list =
61 DisplayItemList::Create(clip, DisplayItemListSettings()); 60 DisplayItemList::Create(PaintableRegion(), DisplayItemListSettings());
62 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(clip); 61 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(
62 PaintableRegion());
63 63
64 skia::RefPtr<SkPicture> picture = 64 skia::RefPtr<SkPicture> picture =
65 skia::AdoptRef(recorder.endRecordingAsPicture()); 65 skia::AdoptRef(recorder.endRecordingAsPicture());
66 item->SetNew(std::move(picture)); 66 item->SetNew(std::move(picture));
67 67
68 display_list->Finalize(); 68 display_list->Finalize();
69 return display_list; 69 return display_list;
70 } 70 }
71 71
72 private: 72 private:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 mask->SetIsMask(true); 106 mask->SetIsMask(true);
107 mask->SetBounds(mask_bounds); 107 mask->SetBounds(mask_bounds);
108 108
109 skia::RefPtr<SkSurface> surface = 109 skia::RefPtr<SkSurface> surface =
110 skia::AdoptRef(SkSurface::NewRasterN32Premul(200, 200)); 110 skia::AdoptRef(SkSurface::NewRasterN32Premul(200, 200));
111 SkCanvas* canvas = surface->getCanvas(); 111 SkCanvas* canvas = surface->getCanvas();
112 canvas->scale(SkIntToScalar(4), SkIntToScalar(4)); 112 canvas->scale(SkIntToScalar(4), SkIntToScalar(4));
113 MaskContentLayerClient client(mask_bounds); 113 MaskContentLayerClient client(mask_bounds);
114 scoped_refptr<DisplayItemList> mask_display_list = 114 scoped_refptr<DisplayItemList> mask_display_list =
115 client.PaintContentsToDisplayList( 115 client.PaintContentsToDisplayList(
116 gfx::Rect(mask_bounds), ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); 116 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL);
117 mask_display_list->Raster(canvas, nullptr, gfx::Rect(mask_bounds), 1.0f); 117 mask_display_list->Raster(canvas, nullptr, gfx::Rect(mask_bounds), 1.0f);
118 skia::RefPtr<const SkImage> image = 118 skia::RefPtr<const SkImage> image =
119 skia::AdoptRef(surface->newImageSnapshot()); 119 skia::AdoptRef(surface->newImageSnapshot());
120 mask->SetImage(std::move(image)); 120 mask->SetImage(std::move(image));
121 121
122 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( 122 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
123 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); 123 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK);
124 green->SetMaskLayer(mask.get()); 124 green->SetMaskLayer(mask.get());
125 background->AddChild(green); 125 background->AddChild(green);
126 126
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 public: 308 public:
309 CheckerContentLayerClient(const gfx::Size& bounds, 309 CheckerContentLayerClient(const gfx::Size& bounds,
310 SkColor color, 310 SkColor color,
311 bool vertical) 311 bool vertical)
312 : bounds_(bounds), color_(color), vertical_(vertical) {} 312 : bounds_(bounds), color_(color), vertical_(vertical) {}
313 ~CheckerContentLayerClient() override {} 313 ~CheckerContentLayerClient() override {}
314 bool FillsBoundsCompletely() const override { return false; } 314 bool FillsBoundsCompletely() const override { return false; }
315 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } 315 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; }
316 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } 316 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); }
317 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( 317 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
318 const gfx::Rect& clip,
319 PaintingControlSetting picture_control) override { 318 PaintingControlSetting picture_control) override {
320 SkPictureRecorder recorder; 319 SkPictureRecorder recorder;
321 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( 320 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(
322 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); 321 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_))));
323 322
324 SkPaint paint; 323 SkPaint paint;
325 paint.setStyle(SkPaint::kStroke_Style); 324 paint.setStyle(SkPaint::kStroke_Style);
326 paint.setStrokeWidth(SkIntToScalar(4)); 325 paint.setStrokeWidth(SkIntToScalar(4));
327 paint.setColor(color_); 326 paint.setColor(color_);
328 canvas->clear(SK_ColorTRANSPARENT); 327 canvas->clear(SK_ColorTRANSPARENT);
329 if (vertical_) { 328 if (vertical_) {
330 for (int i = 4; i < bounds_.width(); i += 16) { 329 for (int i = 4; i < bounds_.width(); i += 16) {
331 canvas->drawLine(i, 0, i, bounds_.height(), paint); 330 canvas->drawLine(i, 0, i, bounds_.height(), paint);
332 } 331 }
333 } else { 332 } else {
334 for (int i = 4; i < bounds_.height(); i += 16) { 333 for (int i = 4; i < bounds_.height(); i += 16) {
335 canvas->drawLine(0, i, bounds_.width(), i, paint); 334 canvas->drawLine(0, i, bounds_.width(), i, paint);
336 } 335 }
337 } 336 }
338 337
339 scoped_refptr<DisplayItemList> display_list = 338 scoped_refptr<DisplayItemList> display_list =
340 DisplayItemList::Create(clip, DisplayItemListSettings()); 339 DisplayItemList::Create(PaintableRegion(), DisplayItemListSettings());
341 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(clip); 340 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(
341 PaintableRegion());
342 342
343 skia::RefPtr<SkPicture> picture = 343 skia::RefPtr<SkPicture> picture =
344 skia::AdoptRef(recorder.endRecordingAsPicture()); 344 skia::AdoptRef(recorder.endRecordingAsPicture());
345 item->SetNew(std::move(picture)); 345 item->SetNew(std::move(picture));
346 346
347 display_list->Finalize(); 347 display_list->Finalize();
348 return display_list; 348 return display_list;
349 } 349 }
350 350
351 private: 351 private:
352 gfx::Size bounds_; 352 gfx::Size bounds_;
353 SkColor color_; 353 SkColor color_;
354 bool vertical_; 354 bool vertical_;
355 }; 355 };
356 356
357 class CircleContentLayerClient : public ContentLayerClient { 357 class CircleContentLayerClient : public ContentLayerClient {
358 public: 358 public:
359 explicit CircleContentLayerClient(const gfx::Size& bounds) 359 explicit CircleContentLayerClient(const gfx::Size& bounds)
360 : bounds_(bounds) {} 360 : bounds_(bounds) {}
361 ~CircleContentLayerClient() override {} 361 ~CircleContentLayerClient() override {}
362 bool FillsBoundsCompletely() const override { return false; } 362 bool FillsBoundsCompletely() const override { return false; }
363 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } 363 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; }
364 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } 364 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); }
365 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( 365 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
366 const gfx::Rect& clip,
367 PaintingControlSetting picture_control) override { 366 PaintingControlSetting picture_control) override {
368 SkPictureRecorder recorder; 367 SkPictureRecorder recorder;
369 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( 368 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(
370 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); 369 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_))));
371 370
372 SkPaint paint; 371 SkPaint paint;
373 paint.setStyle(SkPaint::kFill_Style); 372 paint.setStyle(SkPaint::kFill_Style);
374 paint.setColor(SK_ColorWHITE); 373 paint.setColor(SK_ColorWHITE);
375 canvas->clear(SK_ColorTRANSPARENT); 374 canvas->clear(SK_ColorTRANSPARENT);
376 canvas->drawCircle(bounds_.width() / 2, 375 canvas->drawCircle(bounds_.width() / 2,
377 bounds_.height() / 2, 376 bounds_.height() / 2,
378 bounds_.width() / 4, 377 bounds_.width() / 4,
379 paint); 378 paint);
380 379
381 scoped_refptr<DisplayItemList> display_list = 380 scoped_refptr<DisplayItemList> display_list =
382 DisplayItemList::Create(clip, DisplayItemListSettings()); 381 DisplayItemList::Create(PaintableRegion(), DisplayItemListSettings());
383 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(clip); 382 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(
383 PaintableRegion());
384 skia::RefPtr<SkPicture> picture = 384 skia::RefPtr<SkPicture> picture =
385 skia::AdoptRef(recorder.endRecordingAsPicture()); 385 skia::AdoptRef(recorder.endRecordingAsPicture());
386 item->SetNew(std::move(picture)); 386 item->SetNew(std::move(picture));
387 387
388 display_list->Finalize(); 388 display_list->Finalize();
389 return display_list; 389 return display_list;
390 } 390 }
391 391
392 private: 392 private:
393 gfx::Size bounds_; 393 gfx::Size bounds_;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 504
505 RunPixelResourceTest(background, 505 RunPixelResourceTest(background,
506 base::FilePath( 506 base::FilePath(
507 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); 507 FILE_PATH_LITERAL("mask_of_layer_with_blend.png")));
508 } 508 }
509 509
510 } // namespace 510 } // namespace
511 } // namespace cc 511 } // namespace cc
512 512
513 #endif // !defined(OS_ANDROID) 513 #endif // !defined(OS_ANDROID)
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_common_unittest.cc ('k') | cc/trees/layer_tree_host_pixeltest_tiles.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698