Infobar material design refresh: bg color
[chromium-blink-merge.git] / cc / trees / layer_tree_host_pixeltest_tiles.cc
blob9259ca3dd341a4b7eda8dc6fd38d30882a95fba7
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/content_layer_client.h"
6 #include "cc/layers/picture_layer.h"
7 #include "cc/output/copy_output_request.h"
8 #include "cc/playback/display_item_list.h"
9 #include "cc/playback/drawing_display_item.h"
10 #include "cc/test/layer_tree_pixel_test.h"
11 #include "cc/test/test_gpu_memory_buffer_manager.h"
12 #include "third_party/skia/include/core/SkCanvas.h"
13 #include "third_party/skia/include/core/SkPictureRecorder.h"
15 #if !defined(OS_ANDROID)
17 namespace cc {
18 namespace {
20 enum RasterMode {
21 PARTIAL_ONE_COPY,
22 FULL_ONE_COPY,
23 GPU,
24 BITMAP,
27 class LayerTreeHostTilesPixelTest : public LayerTreePixelTest {
28 protected:
29 void InitializeSettings(LayerTreeSettings* settings) override {
30 LayerTreePixelTest::InitializeSettings(settings);
31 settings->use_display_lists = true;
32 switch (raster_mode_) {
33 case PARTIAL_ONE_COPY:
34 settings->use_zero_copy = false;
35 settings->use_persistent_map_for_gpu_memory_buffers = true;
36 break;
37 case FULL_ONE_COPY:
38 settings->use_zero_copy = false;
39 settings->use_persistent_map_for_gpu_memory_buffers = false;
40 break;
41 case BITMAP:
42 // This is done via context creation. No settings to change here!
43 break;
44 case GPU:
45 settings->gpu_rasterization_enabled = true;
46 settings->gpu_rasterization_forced = true;
47 break;
51 void BeginTest() override {
52 // Don't set up a readback target at the start of the test.
53 PostSetNeedsCommitToMainThread();
56 void DoReadback() {
57 Layer* target =
58 readback_target_ ? readback_target_ : layer_tree_host()->root_layer();
59 target->RequestCopyOfOutput(CreateCopyOutputRequest());
62 void RunRasterPixelTest(bool threaded,
63 RasterMode mode,
64 scoped_refptr<Layer> content_root,
65 base::FilePath file_name) {
66 raster_mode_ = mode;
68 PixelTestType test_type = PIXEL_TEST_SOFTWARE;
69 switch (mode) {
70 case PARTIAL_ONE_COPY:
71 case FULL_ONE_COPY:
72 case GPU:
73 test_type = PIXEL_TEST_GL;
74 break;
75 case BITMAP:
76 test_type = PIXEL_TEST_SOFTWARE;
79 if (threaded)
80 RunPixelTest(test_type, content_root, file_name);
81 else
82 RunSingleThreadedPixelTest(test_type, content_root, file_name);
85 base::FilePath ref_file_;
86 scoped_ptr<SkBitmap> result_bitmap_;
87 RasterMode raster_mode_;
90 class BlueYellowClient : public ContentLayerClient {
91 public:
92 explicit BlueYellowClient(const gfx::Size& size)
93 : size_(size), blue_top_(true) {}
95 void PaintContents(SkCanvas* canvas,
96 const gfx::Rect& clip,
97 PaintingControlSetting painting_status) override {}
99 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
100 const gfx::Rect& clip,
101 PaintingControlSetting painting_status) override {
102 bool use_cached_picture = false;
103 scoped_refptr<DisplayItemList> display_list =
104 DisplayItemList::Create(clip, use_cached_picture);
106 SkPictureRecorder recorder;
107 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(
108 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(size_))));
109 gfx::Rect top(0, 0, size_.width(), size_.height() / 2);
110 gfx::Rect bottom(0, size_.height() / 2, size_.width(), size_.height() / 2);
112 gfx::Rect blue_rect = blue_top_ ? top : bottom;
113 gfx::Rect yellow_rect = blue_top_ ? bottom : top;
115 SkPaint paint;
116 paint.setStyle(SkPaint::kFill_Style);
118 paint.setColor(SK_ColorBLUE);
119 canvas->drawRect(gfx::RectToSkRect(blue_rect), paint);
120 paint.setColor(SK_ColorYELLOW);
121 canvas->drawRect(gfx::RectToSkRect(yellow_rect), paint);
123 skia::RefPtr<SkPicture> picture =
124 skia::AdoptRef(recorder.endRecordingAsPicture());
126 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>();
127 item->SetNew(picture.Pass());
129 display_list->Finalize();
130 return display_list;
133 bool FillsBoundsCompletely() const override { return true; }
134 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; }
136 void set_blue_top(bool b) { blue_top_ = b; }
138 private:
139 gfx::Size size_;
140 bool blue_top_;
143 class LayerTreeHostTilesTestPartialInvalidation
144 : public LayerTreeHostTilesPixelTest {
145 public:
146 LayerTreeHostTilesTestPartialInvalidation()
147 : client_(gfx::Size(200, 200)),
148 picture_layer_(PictureLayer::Create(layer_settings(), &client_)) {
149 picture_layer_->SetBounds(gfx::Size(200, 200));
150 picture_layer_->SetIsDrawable(true);
153 void DidCommitAndDrawFrame() override {
154 switch (layer_tree_host()->source_frame_number()) {
155 case 1:
156 // We have done one frame, so the layer's content has been rastered.
157 // Now we change the picture behind it to record something completely
158 // different, but we give a smaller invalidation rect. The layer should
159 // only re-raster the stuff in the rect. If it doesn't do partial raster
160 // it would re-raster the whole thing instead.
161 client_.set_blue_top(false);
162 Finish();
163 picture_layer_->SetNeedsDisplayRect(gfx::Rect(50, 50, 100, 100));
165 // Add a copy request to see what happened!
166 DoReadback();
167 break;
171 protected:
172 BlueYellowClient client_;
173 scoped_refptr<PictureLayer> picture_layer_;
176 TEST_F(LayerTreeHostTilesTestPartialInvalidation,
177 PartialRaster_SingleThread_OneCopy) {
178 RunRasterPixelTest(
179 false, PARTIAL_ONE_COPY, picture_layer_,
180 base::FilePath(FILE_PATH_LITERAL("blue_yellow_partial_flipped.png")));
183 TEST_F(LayerTreeHostTilesTestPartialInvalidation,
184 FullRaster_SingleThread_OneCopy) {
185 RunRasterPixelTest(
186 false, FULL_ONE_COPY, picture_layer_,
187 base::FilePath(FILE_PATH_LITERAL("blue_yellow_flipped.png")));
190 TEST_F(LayerTreeHostTilesTestPartialInvalidation,
191 PartialRaster_MultiThread_OneCopy) {
192 RunRasterPixelTest(
193 true, PARTIAL_ONE_COPY, picture_layer_,
194 base::FilePath(FILE_PATH_LITERAL("blue_yellow_partial_flipped.png")));
197 TEST_F(LayerTreeHostTilesTestPartialInvalidation,
198 FullRaster_MultiThread_OneCopy) {
199 RunRasterPixelTest(
200 true, FULL_ONE_COPY, picture_layer_,
201 base::FilePath(FILE_PATH_LITERAL("blue_yellow_flipped.png")));
204 TEST_F(LayerTreeHostTilesTestPartialInvalidation,
205 PartialRaster_SingleThread_Software) {
206 RunRasterPixelTest(
207 false, BITMAP, picture_layer_,
208 base::FilePath(FILE_PATH_LITERAL("blue_yellow_partial_flipped.png")));
211 TEST_F(LayerTreeHostTilesTestPartialInvalidation,
212 PartialRaster_SingleThread_GpuRaster) {
213 RunRasterPixelTest(
214 false, GPU, picture_layer_,
215 base::FilePath(FILE_PATH_LITERAL("blue_yellow_partial_flipped.png")));
218 } // namespace
219 } // namespace cc
221 #endif // !defined(OS_ANDROID)