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

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

Issue 1139063002: cc: Partial tile update for one-copy raster. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: monocle: tilemanagerconsistency Created 5 years, 7 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
OLDNEW
(Empty)
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.
4
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"
14
15 #if !defined(OS_ANDROID)
16
17 namespace cc {
18 namespace {
19
20 enum RasterMode {
21 PARTIAL_ONE_COPY,
22 FULL_ONE_COPY,
23 };
24
25 class LayerTreeHostTilesPixelTest : public LayerTreePixelTest {
26 protected:
27 void InitializeSettings(LayerTreeSettings* settings) override {
28 LayerTreePixelTest::InitializeSettings(settings);
29 settings->use_display_lists = true;
30 switch (raster_mode_) {
31 case PARTIAL_ONE_COPY:
32 settings->use_one_copy = true;
33 settings->use_zero_copy = false;
34 settings->have_persistent_gpu_memory_buffers = true;
35 break;
36 case FULL_ONE_COPY:
37 settings->use_one_copy = true;
38 settings->use_zero_copy = false;
39 settings->have_persistent_gpu_memory_buffers = false;
40 break;
41 }
42 }
43
44 void BeginTest() override {
45 // Don't set up a readback target at the start of the test.
46 PostSetNeedsCommitToMainThread();
47 }
48
49 void DoReadback() {
50 Layer* target =
51 readback_target_ ? readback_target_ : layer_tree_host()->root_layer();
52 target->RequestCopyOfOutput(CreateCopyOutputRequest().Pass());
53 }
54
55 void RunRasterPixelTest(bool threaded,
56 RasterMode mode,
57 scoped_refptr<Layer> content_root,
58 base::FilePath file_name) {
59 raster_mode_ = mode;
60
61 PixelTestType test_type;
62 switch (mode) {
63 case PARTIAL_ONE_COPY:
64 case FULL_ONE_COPY:
65 test_type = PIXEL_TEST_GL;
66 break;
67 }
68
69 if (threaded)
70 RunPixelTest(test_type, content_root, file_name);
71 else
72 RunSingleThreadedPixelTest(test_type, content_root, file_name);
73 }
74
75 base::FilePath ref_file_;
76 scoped_ptr<SkBitmap> result_bitmap_;
77 RasterMode raster_mode_;
78 };
79
80 class BlueYellowClient : public ContentLayerClient {
81 public:
82 explicit BlueYellowClient(const gfx::Size& size)
83 : size_(size), blue_top_(true) {}
84
85 void PaintContents(SkCanvas* canvas,
86 const gfx::Rect& clip,
87 PaintingControlSetting painting_status) override {}
88
89 void PaintContentsToDisplayList(
90 DisplayItemList* display_list,
91 const gfx::Rect& clip,
92 PaintingControlSetting painting_status) override {
93 SkPictureRecorder recorder;
94 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(
95 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(size_))));
96 gfx::Rect top(0, 0, size_.width(), size_.height() / 2);
97 gfx::Rect bottom(0, size_.height() / 2, size_.width(), size_.height() / 2);
98
99 gfx::Rect blue_rect = blue_top_ ? top : bottom;
100 gfx::Rect yellow_rect = blue_top_ ? bottom : top;
101
102 SkPaint paint;
103 paint.setStyle(SkPaint::kFill_Style);
104
105 paint.setColor(SK_ColorBLUE);
106 canvas->drawRect(gfx::RectToSkRect(blue_rect), paint);
107 paint.setColor(SK_ColorYELLOW);
108 canvas->drawRect(gfx::RectToSkRect(yellow_rect), paint);
109
110 skia::RefPtr<SkPicture> picture =
111 skia::AdoptRef(recorder.endRecordingAsPicture());
112
113 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>();
114 item->SetNew(picture.Pass());
115 }
116
117 bool FillsBoundsCompletely() const override { return true; }
118
119 void set_blue_top(bool b) { blue_top_ = b; }
120
121 private:
122 gfx::Size size_;
123 bool blue_top_;
124 };
125
126 class LayerTreeHostTilesTestPartialInvalidation
127 : public LayerTreeHostTilesPixelTest {
128 public:
129 LayerTreeHostTilesTestPartialInvalidation()
130 : client_(gfx::Size(200, 200)),
131 picture_layer_(PictureLayer::Create(&client_)) {
132 picture_layer_->SetBounds(gfx::Size(200, 200));
133 picture_layer_->SetIsDrawable(true);
134 }
135
136 void DidCommitAndDrawFrame() override {
137 switch (layer_tree_host()->source_frame_number()) {
138 case 1:
139 // We have done one frame, so the layer's content has been rastered.
140 // Now we change the picture behind it to record something completely
141 // different, but we give a smaller invalidation rect. The layer should
142 // only re-raster the stuff in the rect. If it doesn't do partial raster
143 // it would re-raster the whole thing instead.
144 client_.set_blue_top(false);
145 picture_layer_->SetNeedsDisplayRect(gfx::Rect(50, 50, 100, 100));
146
147 // Add a copy request to see what happened!
148 DoReadback();
149 break;
150 }
151 }
152
153 protected:
154 BlueYellowClient client_;
155 scoped_refptr<PictureLayer> picture_layer_;
156 };
157
158 TEST_F(LayerTreeHostTilesTestPartialInvalidation,
159 PartialRaster_SingleThread_OneCopy) {
160 RunRasterPixelTest(
161 false, PARTIAL_ONE_COPY, picture_layer_,
162 base::FilePath(FILE_PATH_LITERAL("blue_yellow_partial_flipped.png")));
163 }
164
165 TEST_F(LayerTreeHostTilesTestPartialInvalidation,
166 FullRaster_SingleThread_OneCopy) {
167 RunRasterPixelTest(
168 false, FULL_ONE_COPY, picture_layer_,
169 base::FilePath(FILE_PATH_LITERAL("blue_yellow_flipped.png")));
170 }
171
172 TEST_F(LayerTreeHostTilesTestPartialInvalidation,
173 FullRaster_MultiThread_OneCopy) {
174 RunRasterPixelTest(
175 true, FULL_ONE_COPY, picture_layer_,
176 base::FilePath(FILE_PATH_LITERAL("blue_yellow_flipped.png")));
177 }
178
179 } // namespace
180 } // namespace cc
181
182 #endif // !defined(OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698