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/test/mock_quad_culler.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" | |
17 | |
18 #if !defined(OS_ANDROID) | |
19 | |
20 namespace cc { | |
21 namespace { | |
22 | |
23 class LayerTreeHostOnDemandRasterPixelTest : public LayerTreePixelTest { | |
24 public: | |
25 LayerTreeHostOnDemandRasterPixelTest() { | |
26 m_settings.implSidePainting = true; | |
danakj
2013/03/21 02:34:42
This will have to go in an override of InitializeS
Leandro Graciá Gil
2013/03/21 16:42:48
Done.
| |
27 } | |
28 | |
29 virtual void beginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
30 // Not enough memory available. Enforce on-demand rasterization. | |
31 impl->SetManagedMemoryPolicy( | |
32 ManagedMemoryPolicy(1, ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING, | |
33 1, ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING)); | |
34 } | |
35 | |
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)); | |
43 | |
44 QuadList quads; | |
45 SharedQuadStateList shared_states; | |
46 MockQuadCuller quad_culler(quads, shared_states); | |
47 | |
48 AppendQuadsData data; | |
49 picture_layer->AppendQuads(&quad_culler, &data); | |
50 | |
51 for (size_t i = 0; i < quads.size(); ++i) | |
52 EXPECT_EQ(quads[i]->material, DrawQuad::PICTURE_CONTENT); | |
53 | |
54 // Triggers pixel readback and ends the test. | |
55 LayerTreePixelTest::swapBuffersOnThread(host_impl, result); | |
56 } | |
57 }; | |
58 | |
59 class BlueYellowLayerClient : public ContentLayerClient { | |
60 public: | |
61 BlueYellowLayerClient(const gfx::Rect& rect) : rect_(rect) { } | |
danakj
2013/03/21 02:34:42
by value
Leandro Graciá Gil
2013/03/21 03:35:50
Why? As we assign the const ref argument to a gfx:
danakj
2013/03/21 04:33:39
Same comment here re gfx:: types.
Leandro Graciá Gil
2013/03/21 16:42:48
Done.
| |
62 | |
63 virtual void PaintContents(SkCanvas* canvas, | |
64 gfx::Rect clip, | |
65 gfx::RectF* opaque) OVERRIDE { | |
66 *opaque = gfx::RectF(rect_.width(), rect_.height()); | |
67 | |
68 // Skia uses BGRA ordering rather than RGBA. As the results will be later | |
69 // compared with a RGBA image, swap the red and blue components here. | |
70 SkPaint paint; | |
71 paint.setColor(SwapRB(SK_ColorBLUE)); | |
72 canvas->drawRect(SkRect::MakeWH(rect_.width() / 2, rect_.height()), paint); | |
73 | |
74 paint.setColor(SwapRB(SK_ColorYELLOW)); | |
75 canvas->drawRect( | |
76 SkRect::MakeXYWH(rect_.width() / 2, 0, | |
77 rect_.width() / 2, rect_.height()), | |
78 paint); | |
79 } | |
80 | |
81 static SkColor SwapRB(SkColor color) { | |
82 return SkColorSetARGB( | |
83 SkColorGetA(color), | |
84 SkColorGetB(color), | |
85 SkColorGetG(color), | |
86 SkColorGetR(color)); | |
87 } | |
88 | |
89 private: | |
90 gfx::Rect rect_; | |
91 }; | |
92 | |
93 TEST_F(LayerTreeHostOnDemandRasterPixelTest, RasterPictureLayer) { | |
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 rect(200, 200); | |
danakj
2013/03/21 02:34:42
can you give this a better name than "rect"?
Leandro Graciá Gil
2013/03/21 03:35:50
Perhaps bounds?
danakj
2013/03/21 04:33:39
I don't think that does more than describe the sto
Leandro Graciá Gil
2013/03/21 16:42:48
Done.
| |
97 BlueYellowLayerClient client(rect); | |
98 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); | |
99 | |
100 layer->SetIsDrawable(true); | |
101 layer->SetAnchorPoint(gfx::PointF()); | |
102 layer->SetBounds(rect.size()); | |
103 layer->SetPosition(rect.origin()); | |
104 | |
105 RunPixelTest(layer, base::FilePath(FILE_PATH_LITERAL("blue_yellow.png"))); | |
106 } | |
107 | |
108 } // namespace | |
109 } // namespace cc | |
110 | |
111 #endif // OS_ANDROID | |
OLD | NEW |