| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/layers/append_quads_data.h" | |
| 6 #include "cc/layers/content_layer_client.h" | |
| 7 #include "cc/layers/picture_layer.h" | |
| 8 #include "cc/layers/picture_layer_impl.h" | |
| 9 #include "cc/quads/draw_quad.h" | |
| 10 #include "cc/test/layer_tree_pixel_test.h" | |
| 11 #include "cc/trees/layer_tree_impl.h" | |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | |
| 13 #include "third_party/skia/include/core/SkColor.h" | |
| 14 #include "ui/gfx/geometry/rect.h" | |
| 15 #include "ui/gfx/geometry/rect_f.h" | |
| 16 | |
| 17 #if !defined(OS_ANDROID) | |
| 18 | |
| 19 namespace cc { | |
| 20 namespace { | |
| 21 | |
| 22 class LayerTreeHostOnDemandRasterPixelTest : public LayerTreePixelTest { | |
| 23 public: | |
| 24 void InitializeSettings(LayerTreeSettings* settings) override { | |
| 25 settings->impl_side_painting = true; | |
| 26 } | |
| 27 | |
| 28 void BeginCommitOnThread(LayerTreeHostImpl* impl) override { | |
| 29 // Not enough memory available. Enforce on-demand rasterization. | |
| 30 impl->SetMemoryPolicy( | |
| 31 ManagedMemoryPolicy(1, gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, | |
| 32 1000)); | |
| 33 } | |
| 34 | |
| 35 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { | |
| 36 // Find the PictureLayerImpl ask it to append quads to check their material. | |
| 37 // The PictureLayerImpl is assumed to be the first child of the root layer | |
| 38 // in the active tree. | |
| 39 PictureLayerImpl* picture_layer = static_cast<PictureLayerImpl*>( | |
| 40 host_impl->active_tree()->root_layer()->child_at(0)); | |
| 41 | |
| 42 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | |
| 43 | |
| 44 AppendQuadsData data; | |
| 45 picture_layer->AppendQuads(render_pass.get(), &data); | |
| 46 | |
| 47 for (const auto& quad : render_pass->quad_list) | |
| 48 EXPECT_EQ(quad->material, DrawQuad::PICTURE_CONTENT); | |
| 49 | |
| 50 // Triggers pixel readback and ends the test. | |
| 51 LayerTreePixelTest::SwapBuffersOnThread(host_impl, result); | |
| 52 } | |
| 53 | |
| 54 void RunOnDemandRasterPixelTest(); | |
| 55 }; | |
| 56 | |
| 57 class BlueYellowLayerClient : public ContentLayerClient { | |
| 58 public: | |
| 59 explicit BlueYellowLayerClient(gfx::Rect layer_rect) | |
| 60 : layer_rect_(layer_rect) {} | |
| 61 | |
| 62 bool FillsBoundsCompletely() const override { return false; } | |
| 63 | |
| 64 void PaintContents(SkCanvas* canvas, | |
| 65 const gfx::Rect& clip, | |
| 66 PaintingControlSetting picture_control) override { | |
| 67 SkPaint paint; | |
| 68 paint.setColor(SK_ColorBLUE); | |
| 69 canvas->drawRect(SkRect::MakeWH(layer_rect_.width(), | |
| 70 layer_rect_.height() / 2), | |
| 71 paint); | |
| 72 | |
| 73 paint.setColor(SK_ColorYELLOW); | |
| 74 canvas->drawRect( | |
| 75 SkRect::MakeXYWH(0, | |
| 76 layer_rect_.height() / 2, | |
| 77 layer_rect_.width(), | |
| 78 layer_rect_.height() / 2), | |
| 79 paint); | |
| 80 } | |
| 81 | |
| 82 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | |
| 83 const gfx::Rect& clip, | |
| 84 PaintingControlSetting picture_control) override { | |
| 85 NOTIMPLEMENTED(); | |
| 86 return DisplayItemList::Create(); | |
| 87 } | |
| 88 | |
| 89 private: | |
| 90 gfx::Rect layer_rect_; | |
| 91 }; | |
| 92 | |
| 93 void LayerTreeHostOnDemandRasterPixelTest::RunOnDemandRasterPixelTest() { | |
| 94 // Use multiple colors in a single layer to prevent bypassing on-demand | |
| 95 // rasterization if a single solid color is detected in picture analysis. | |
| 96 gfx::Rect layer_rect(200, 200); | |
| 97 BlueYellowLayerClient client(layer_rect); | |
| 98 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); | |
| 99 | |
| 100 layer->SetIsDrawable(true); | |
| 101 layer->SetBounds(layer_rect.size()); | |
| 102 layer->SetPosition(layer_rect.origin()); | |
| 103 | |
| 104 RunPixelTest(PIXEL_TEST_GL, | |
| 105 layer, | |
| 106 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png"))); | |
| 107 } | |
| 108 | |
| 109 TEST_F(LayerTreeHostOnDemandRasterPixelTest, RasterPictureLayer) { | |
| 110 RunOnDemandRasterPixelTest(); | |
| 111 } | |
| 112 | |
| 113 } // namespace | |
| 114 } // namespace cc | |
| 115 | |
| 116 #endif // OS_ANDROID | |
| OLD | NEW |