Add ICU message format support
[chromium-blink-merge.git] / cc / trees / layer_tree_host_pixeltest_tiles.cc
bloba07f100c31a0748adf7851ff5c35f024ebbd411b
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_one_copy = true;
35 settings->use_zero_copy = false;
36 settings->use_persistent_map_for_gpu_memory_buffers = true;
37 break;
38 case FULL_ONE_COPY:
39 settings->use_one_copy = true;
40 settings->use_zero_copy = false;
41 settings->use_persistent_map_for_gpu_memory_buffers = false;
42 break;
43 case BITMAP:
44 // This is done via context creation. No settings to change here!
45 break;
46 case GPU:
47 settings->gpu_rasterization_enabled = true;
48 settings->gpu_rasterization_forced = true;
49 break;
53 void BeginTest() override {
54 // Don't set up a readback target at the start of the test.
55 PostSetNeedsCommitToMainThread();
58 void DoReadback() {
59 Layer* target =
60 readback_target_ ? readback_target_ : layer_tree_host()->root_layer();
61 target->RequestCopyOfOutput(CreateCopyOutputRequest());
64 void RunRasterPixelTest(bool threaded,
65 RasterMode mode,
66 scoped_refptr<Layer> content_root,
67 base::FilePath file_name) {
68 raster_mode_ = mode;
70 PixelTestType test_type = PIXEL_TEST_SOFTWARE;
71 switch (mode) {
72 case PARTIAL_ONE_COPY:
73 case FULL_ONE_COPY:
74 case GPU:
75 test_type = PIXEL_TEST_GL;
76 break;
77 case BITMAP:
78 test_type = PIXEL_TEST_SOFTWARE;
81 if (threaded)
82 RunPixelTest(test_type, content_root, file_name);
83 else
84 RunSingleThreadedPixelTest(test_type, content_root, file_name);
87 base::FilePath ref_file_;
88 scoped_ptr<SkBitmap> result_bitmap_;
89 RasterMode raster_mode_;
92 class BlueYellowClient : public ContentLayerClient {
93 public:
94 explicit BlueYellowClient(const gfx::Size& size)
95 : size_(size), blue_top_(true) {}
97 void PaintContents(SkCanvas* canvas,
98 const gfx::Rect& clip,
99 PaintingControlSetting painting_status) override {}
101 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
102 const gfx::Rect& clip,
103 PaintingControlSetting painting_status) override {
104 bool use_cached_picture = false;
105 scoped_refptr<DisplayItemList> display_list =
106 DisplayItemList::Create(clip, use_cached_picture);
108 SkPictureRecorder recorder;
109 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(
110 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(size_))));
111 gfx::Rect top(0, 0, size_.width(), size_.height() / 2);
112 gfx::Rect bottom(0, size_.height() / 2, size_.width(), size_.height() / 2);
114 gfx::Rect blue_rect = blue_top_ ? top : bottom;
115 gfx::Rect yellow_rect = blue_top_ ? bottom : top;
117 SkPaint paint;
118 paint.setStyle(SkPaint::kFill_Style);
120 paint.setColor(SK_ColorBLUE);
121 canvas->drawRect(gfx::RectToSkRect(blue_rect), paint);
122 paint.setColor(SK_ColorYELLOW);
123 canvas->drawRect(gfx::RectToSkRect(yellow_rect), paint);
125 skia::RefPtr<SkPicture> picture =
126 skia::AdoptRef(recorder.endRecordingAsPicture());
128 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>();
129 item->SetNew(picture.Pass());
131 display_list->Finalize();
132 return display_list;
135 bool FillsBoundsCompletely() const override { return true; }
136 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; }
138 void set_blue_top(bool b) { blue_top_ = b; }
140 private:
141 gfx::Size size_;
142 bool blue_top_;
145 class LayerTreeHostTilesTestPartialInvalidation
146 : public LayerTreeHostTilesPixelTest {
147 public:
148 LayerTreeHostTilesTestPartialInvalidation()
149 : client_(gfx::Size(200, 200)),
150 picture_layer_(PictureLayer::Create(layer_settings(), &client_)) {
151 picture_layer_->SetBounds(gfx::Size(200, 200));
152 picture_layer_->SetIsDrawable(true);
155 void DidCommitAndDrawFrame() override {
156 switch (layer_tree_host()->source_frame_number()) {
157 case 1:
158 // We have done one frame, so the layer's content has been rastered.
159 // Now we change the picture behind it to record something completely
160 // different, but we give a smaller invalidation rect. The layer should
161 // only re-raster the stuff in the rect. If it doesn't do partial raster
162 // it would re-raster the whole thing instead.
163 client_.set_blue_top(false);
164 picture_layer_->SetNeedsDisplayRect(gfx::Rect(50, 50, 100, 100));
166 // Add a copy request to see what happened!
167 DoReadback();
168 break;
172 protected:
173 BlueYellowClient client_;
174 scoped_refptr<PictureLayer> picture_layer_;
177 TEST_F(LayerTreeHostTilesTestPartialInvalidation,
178 PartialRaster_SingleThread_OneCopy) {
179 RunRasterPixelTest(
180 false, PARTIAL_ONE_COPY, picture_layer_,
181 base::FilePath(FILE_PATH_LITERAL("blue_yellow_partial_flipped.png")));
184 TEST_F(LayerTreeHostTilesTestPartialInvalidation,
185 FullRaster_SingleThread_OneCopy) {
186 RunRasterPixelTest(
187 false, FULL_ONE_COPY, picture_layer_,
188 base::FilePath(FILE_PATH_LITERAL("blue_yellow_flipped.png")));
191 TEST_F(LayerTreeHostTilesTestPartialInvalidation,
192 FullRaster_MultiThread_OneCopy) {
193 RunRasterPixelTest(
194 true, FULL_ONE_COPY, picture_layer_,
195 base::FilePath(FILE_PATH_LITERAL("blue_yellow_flipped.png")));
198 TEST_F(LayerTreeHostTilesTestPartialInvalidation,
199 PartialRaster_SingleThread_Software) {
200 RunRasterPixelTest(
201 false, BITMAP, picture_layer_,
202 base::FilePath(FILE_PATH_LITERAL("blue_yellow_partial_flipped.png")));
205 TEST_F(LayerTreeHostTilesTestPartialInvalidation,
206 PartialRaster_SingleThread_GpuRaster) {
207 RunRasterPixelTest(
208 false, GPU, picture_layer_,
209 base::FilePath(FILE_PATH_LITERAL("blue_yellow_partial_flipped.png")));
212 } // namespace
213 } // namespace cc
215 #endif // !defined(OS_ANDROID)