OLD | NEW |
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 "cc/layers/append_quads_data.h" | 5 #include "cc/layers/append_quads_data.h" |
6 #include "cc/layers/content_layer_client.h" | 6 #include "cc/layers/content_layer_client.h" |
7 #include "cc/layers/picture_layer.h" | 7 #include "cc/layers/picture_layer.h" |
8 #include "cc/layers/picture_layer_impl.h" | 8 #include "cc/layers/picture_layer_impl.h" |
9 #include "cc/quads/draw_quad.h" | 9 #include "cc/quads/draw_quad.h" |
10 #include "cc/test/layer_tree_pixel_test.h" | 10 #include "cc/test/layer_tree_pixel_test.h" |
11 #include "cc/trees/layer_tree_impl.h" | 11 #include "cc/trees/layer_tree_impl.h" |
12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
13 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
15 #include "ui/gfx/rect_f.h" | 15 #include "ui/gfx/rect_f.h" |
16 | 16 |
17 #if !defined(OS_ANDROID) | 17 #if !defined(OS_ANDROID) |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 namespace { | 20 namespace { |
21 | 21 |
22 class LayerTreeHostOnDemandRasterPixelTest : public LayerTreePixelTest { | 22 class LayerTreeHostOnDemandRasterPixelTest : public LayerTreePixelTest { |
23 public: | 23 public: |
24 virtual void InitializeSettings(LayerTreeSettings* settings) override { | 24 void InitializeSettings(LayerTreeSettings* settings) override { |
25 settings->impl_side_painting = true; | 25 settings->impl_side_painting = true; |
26 } | 26 } |
27 | 27 |
28 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) override { | 28 void BeginCommitOnThread(LayerTreeHostImpl* impl) override { |
29 // Not enough memory available. Enforce on-demand rasterization. | 29 // Not enough memory available. Enforce on-demand rasterization. |
30 impl->SetMemoryPolicy( | 30 impl->SetMemoryPolicy( |
31 ManagedMemoryPolicy(1, gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, | 31 ManagedMemoryPolicy(1, gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, |
32 1000)); | 32 1000)); |
33 } | 33 } |
34 | 34 |
35 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | 35 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { |
36 bool result) override { | |
37 // Find the PictureLayerImpl ask it to append quads to check their material. | 36 // Find the PictureLayerImpl ask it to append quads to check their material. |
38 // The PictureLayerImpl is assumed to be the first child of the root layer | 37 // The PictureLayerImpl is assumed to be the first child of the root layer |
39 // in the active tree. | 38 // in the active tree. |
40 PictureLayerImpl* picture_layer = static_cast<PictureLayerImpl*>( | 39 PictureLayerImpl* picture_layer = static_cast<PictureLayerImpl*>( |
41 host_impl->active_tree()->root_layer()->child_at(0)); | 40 host_impl->active_tree()->root_layer()->child_at(0)); |
42 | 41 |
43 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 42 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
44 | 43 |
45 AppendQuadsData data; | 44 AppendQuadsData data; |
46 picture_layer->AppendQuads(render_pass.get(), Occlusion(), &data); | 45 picture_layer->AppendQuads(render_pass.get(), Occlusion(), &data); |
47 | 46 |
48 for (const auto& quad : render_pass->quad_list) | 47 for (const auto& quad : render_pass->quad_list) |
49 EXPECT_EQ(quad.material, DrawQuad::PICTURE_CONTENT); | 48 EXPECT_EQ(quad.material, DrawQuad::PICTURE_CONTENT); |
50 | 49 |
51 // Triggers pixel readback and ends the test. | 50 // Triggers pixel readback and ends the test. |
52 LayerTreePixelTest::SwapBuffersOnThread(host_impl, result); | 51 LayerTreePixelTest::SwapBuffersOnThread(host_impl, result); |
53 } | 52 } |
54 | 53 |
55 void RunOnDemandRasterPixelTest(); | 54 void RunOnDemandRasterPixelTest(); |
56 }; | 55 }; |
57 | 56 |
58 class BlueYellowLayerClient : public ContentLayerClient { | 57 class BlueYellowLayerClient : public ContentLayerClient { |
59 public: | 58 public: |
60 explicit BlueYellowLayerClient(gfx::Rect layer_rect) | 59 explicit BlueYellowLayerClient(gfx::Rect layer_rect) |
61 : layer_rect_(layer_rect) {} | 60 : layer_rect_(layer_rect) {} |
62 | 61 |
63 virtual void DidChangeLayerCanUseLCDText() override { } | 62 void DidChangeLayerCanUseLCDText() override {} |
64 | 63 |
65 virtual bool FillsBoundsCompletely() const override { return false; } | 64 bool FillsBoundsCompletely() const override { return false; } |
66 | 65 |
67 virtual void PaintContents( | 66 void PaintContents( |
68 SkCanvas* canvas, | 67 SkCanvas* canvas, |
69 const gfx::Rect& clip, | 68 const gfx::Rect& clip, |
70 ContentLayerClient::GraphicsContextStatus gc_status) override { | 69 ContentLayerClient::GraphicsContextStatus gc_status) override { |
71 SkPaint paint; | 70 SkPaint paint; |
72 paint.setColor(SK_ColorBLUE); | 71 paint.setColor(SK_ColorBLUE); |
73 canvas->drawRect(SkRect::MakeWH(layer_rect_.width(), | 72 canvas->drawRect(SkRect::MakeWH(layer_rect_.width(), |
74 layer_rect_.height() / 2), | 73 layer_rect_.height() / 2), |
75 paint); | 74 paint); |
76 | 75 |
77 paint.setColor(SK_ColorYELLOW); | 76 paint.setColor(SK_ColorYELLOW); |
(...skipping 24 matching lines...) Expand all Loading... |
102 layer, | 101 layer, |
103 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png"))); | 102 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png"))); |
104 } | 103 } |
105 | 104 |
106 TEST_F(LayerTreeHostOnDemandRasterPixelTest, RasterPictureLayer) { | 105 TEST_F(LayerTreeHostOnDemandRasterPixelTest, RasterPictureLayer) { |
107 RunOnDemandRasterPixelTest(); | 106 RunOnDemandRasterPixelTest(); |
108 } | 107 } |
109 | 108 |
110 class LayerTreeHostOnDemandRasterPixelTestWithGpuRasterizationForced | 109 class LayerTreeHostOnDemandRasterPixelTestWithGpuRasterizationForced |
111 : public LayerTreeHostOnDemandRasterPixelTest { | 110 : public LayerTreeHostOnDemandRasterPixelTest { |
112 virtual void InitializeSettings(LayerTreeSettings* settings) override { | 111 void InitializeSettings(LayerTreeSettings* settings) override { |
113 LayerTreeHostOnDemandRasterPixelTest::InitializeSettings(settings); | 112 LayerTreeHostOnDemandRasterPixelTest::InitializeSettings(settings); |
114 settings->gpu_rasterization_forced = true; | 113 settings->gpu_rasterization_forced = true; |
115 } | 114 } |
116 }; | 115 }; |
117 | 116 |
118 TEST_F(LayerTreeHostOnDemandRasterPixelTestWithGpuRasterizationForced, | 117 TEST_F(LayerTreeHostOnDemandRasterPixelTestWithGpuRasterizationForced, |
119 RasterPictureLayer) { | 118 RasterPictureLayer) { |
120 RunOnDemandRasterPixelTest(); | 119 RunOnDemandRasterPixelTest(); |
121 } | 120 } |
122 | 121 |
123 } // namespace | 122 } // namespace |
124 } // namespace cc | 123 } // namespace cc |
125 | 124 |
126 #endif // OS_ANDROID | 125 #endif // OS_ANDROID |
OLD | NEW |