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/test/mock_occlusion_tracker.h"
12 #include "cc/trees/layer_tree_impl.h"
13 #include "third_party/skia/include/core/SkCanvas.h"
14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/gfx/rect.h"
16 #include "ui/gfx/rect_f.h"
18 #if !defined(OS_ANDROID)
23 class LayerTreeHostOnDemandRasterPixelTest
: public LayerTreePixelTest
{
25 virtual void InitializeSettings(LayerTreeSettings
* settings
) OVERRIDE
{
26 settings
->impl_side_painting
= true;
29 virtual void BeginCommitOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
30 // Not enough memory available. Enforce on-demand rasterization.
31 impl
->SetMemoryPolicy(
32 ManagedMemoryPolicy(1, gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING
,
36 virtual void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
,
37 bool result
) OVERRIDE
{
38 // Find the PictureLayerImpl ask it to append quads to check their material.
39 // The PictureLayerImpl is assumed to be the first child of the root layer
40 // in the active tree.
41 PictureLayerImpl
* picture_layer
= static_cast<PictureLayerImpl
*>(
42 host_impl
->active_tree()->root_layer()->child_at(0));
44 MockOcclusionTracker
<LayerImpl
> occlusion_tracker
;
45 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
48 picture_layer
->AppendQuads(render_pass
.get(), occlusion_tracker
, &data
);
50 for (size_t i
= 0; i
< render_pass
->quad_list
.size(); ++i
)
51 EXPECT_EQ(render_pass
->quad_list
[i
]->material
, DrawQuad::PICTURE_CONTENT
);
53 // Triggers pixel readback and ends the test.
54 LayerTreePixelTest::SwapBuffersOnThread(host_impl
, result
);
57 void RunOnDemandRasterPixelTest();
60 class BlueYellowLayerClient
: public ContentLayerClient
{
62 explicit BlueYellowLayerClient(gfx::Rect layer_rect
)
63 : layer_rect_(layer_rect
) {}
65 virtual void DidChangeLayerCanUseLCDText() OVERRIDE
{ }
67 virtual bool FillsBoundsCompletely() const OVERRIDE
{ return false; }
69 virtual void PaintContents(
71 const gfx::Rect
& clip
,
73 ContentLayerClient::GraphicsContextStatus gc_status
) OVERRIDE
{
74 *opaque
= gfx::RectF(layer_rect_
.width(), layer_rect_
.height());
77 paint
.setColor(SK_ColorBLUE
);
78 canvas
->drawRect(SkRect::MakeWH(layer_rect_
.width(),
79 layer_rect_
.height() / 2),
82 paint
.setColor(SK_ColorYELLOW
);
85 layer_rect_
.height() / 2,
87 layer_rect_
.height() / 2),
92 gfx::Rect layer_rect_
;
95 void LayerTreeHostOnDemandRasterPixelTest::RunOnDemandRasterPixelTest() {
96 // Use multiple colors in a single layer to prevent bypassing on-demand
97 // rasterization if a single solid color is detected in picture analysis.
98 gfx::Rect
layer_rect(200, 200);
99 BlueYellowLayerClient
client(layer_rect
);
100 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
102 layer
->SetIsDrawable(true);
103 layer
->SetBounds(layer_rect
.size());
104 layer
->SetPosition(layer_rect
.origin());
106 RunPixelTest(GL_WITH_BITMAP
,
108 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")));
111 TEST_F(LayerTreeHostOnDemandRasterPixelTest
, RasterPictureLayer
) {
112 RunOnDemandRasterPixelTest();
115 class LayerTreeHostOnDemandRasterPixelTestWithGpuRasterizationForced
116 : public LayerTreeHostOnDemandRasterPixelTest
{
117 virtual void InitializeSettings(LayerTreeSettings
* settings
) OVERRIDE
{
118 LayerTreeHostOnDemandRasterPixelTest::InitializeSettings(settings
);
119 settings
->gpu_rasterization_forced
= true;
123 TEST_F(LayerTreeHostOnDemandRasterPixelTestWithGpuRasterizationForced
,
124 RasterPictureLayer
) {
125 RunOnDemandRasterPixelTest();