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.
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/rect.h"
15 #include "ui/gfx/rect_f.h"
17 #if !defined(OS_ANDROID)
22 class LayerTreeHostOnDemandRasterPixelTest
: public LayerTreePixelTest
{
24 virtual void InitializeSettings(LayerTreeSettings
* settings
) override
{
25 settings
->impl_side_painting
= true;
28 virtual 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
,
35 virtual void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
,
36 bool result
) override
{
37 // 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
39 // in the active tree.
40 PictureLayerImpl
* picture_layer
= static_cast<PictureLayerImpl
*>(
41 host_impl
->active_tree()->root_layer()->child_at(0));
43 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
46 picture_layer
->AppendQuads(render_pass
.get(), Occlusion(), &data
);
48 for (const auto& quad
: render_pass
->quad_list
)
49 EXPECT_EQ(quad
.material
, DrawQuad::PICTURE_CONTENT
);
51 // Triggers pixel readback and ends the test.
52 LayerTreePixelTest::SwapBuffersOnThread(host_impl
, result
);
55 void RunOnDemandRasterPixelTest();
58 class BlueYellowLayerClient
: public ContentLayerClient
{
60 explicit BlueYellowLayerClient(gfx::Rect layer_rect
)
61 : layer_rect_(layer_rect
) {}
63 virtual void DidChangeLayerCanUseLCDText() override
{ }
65 virtual bool FillsBoundsCompletely() const override
{ return false; }
67 virtual void PaintContents(
69 const gfx::Rect
& clip
,
70 ContentLayerClient::GraphicsContextStatus gc_status
) override
{
72 paint
.setColor(SK_ColorBLUE
);
73 canvas
->drawRect(SkRect::MakeWH(layer_rect_
.width(),
74 layer_rect_
.height() / 2),
77 paint
.setColor(SK_ColorYELLOW
);
80 layer_rect_
.height() / 2,
82 layer_rect_
.height() / 2),
87 gfx::Rect layer_rect_
;
90 void LayerTreeHostOnDemandRasterPixelTest::RunOnDemandRasterPixelTest() {
91 // Use multiple colors in a single layer to prevent bypassing on-demand
92 // rasterization if a single solid color is detected in picture analysis.
93 gfx::Rect
layer_rect(200, 200);
94 BlueYellowLayerClient
client(layer_rect
);
95 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
97 layer
->SetIsDrawable(true);
98 layer
->SetBounds(layer_rect
.size());
99 layer
->SetPosition(layer_rect
.origin());
101 RunPixelTest(GL_WITH_BITMAP
,
103 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")));
106 TEST_F(LayerTreeHostOnDemandRasterPixelTest
, RasterPictureLayer
) {
107 RunOnDemandRasterPixelTest();
110 class LayerTreeHostOnDemandRasterPixelTestWithGpuRasterizationForced
111 : public LayerTreeHostOnDemandRasterPixelTest
{
112 virtual void InitializeSettings(LayerTreeSettings
* settings
) override
{
113 LayerTreeHostOnDemandRasterPixelTest::InitializeSettings(settings
);
114 settings
->gpu_rasterization_forced
= true;
118 TEST_F(LayerTreeHostOnDemandRasterPixelTestWithGpuRasterizationForced
,
119 RasterPictureLayer
) {
120 RunOnDemandRasterPixelTest();