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/test/layer_tree_pixel_test.h"
7 #include "base/path_service.h"
8 #include "cc/test/paths.h"
9 #include "cc/test/pixel_comparator.h"
10 #include "cc/test/pixel_test_utils.h"
11 #include "cc/trees/layer_tree_impl.h"
12 #include "ui/gl/gl_implementation.h"
13 #include "webkit/gpu/context_provider_in_process.h"
14 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
18 LayerTreePixelTest::LayerTreePixelTest()
19 : pixel_comparator_(new ExactPixelComparator(true)) {}
21 LayerTreePixelTest::~LayerTreePixelTest() {}
23 scoped_ptr
<OutputSurface
> LayerTreePixelTest::CreateOutputSurface() {
24 CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL
));
26 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl
;
27 scoped_ptr
<WebGraphicsContext3DInProcessCommandBufferImpl
> context3d(
28 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
29 WebKit::WebGraphicsContext3D::Attributes()));
30 return make_scoped_ptr(
31 new OutputSurface(context3d
.PassAs
<WebKit::WebGraphicsContext3D
>()));
34 scoped_refptr
<cc::ContextProvider
>
35 LayerTreePixelTest::OffscreenContextProviderForMainThread() {
36 scoped_refptr
<webkit::gpu::ContextProviderInProcess
> provider
=
37 webkit::gpu::ContextProviderInProcess::Create();
38 CHECK(provider
->BindToCurrentThread());
42 scoped_refptr
<cc::ContextProvider
>
43 LayerTreePixelTest::OffscreenContextProviderForCompositorThread() {
44 scoped_refptr
<webkit::gpu::ContextProviderInProcess
> provider
=
45 webkit::gpu::ContextProviderInProcess::Create();
50 void LayerTreePixelTest::ReadbackResult(scoped_ptr
<SkBitmap
> bitmap
) {
53 base::FilePath test_data_dir
;
54 EXPECT_TRUE(PathService::Get(cc::DIR_TEST_DATA
, &test_data_dir
));
57 // EXPECT_TRUE(WritePNGFile(*bitmap, test_data_dir.Append(ref_file_), true));
59 EXPECT_TRUE(MatchesPNGFile(*bitmap
,
60 test_data_dir
.Append(ref_file_
),
65 void LayerTreePixelTest::BeginTest() {
66 layer_tree_host()->root_layer()->RequestCopyAsBitmap(
67 base::Bind(&LayerTreePixelTest::ReadbackResult
,
68 base::Unretained(this)));
69 PostSetNeedsCommitToMainThread();
72 void LayerTreePixelTest::AfterTest() {}
74 scoped_refptr
<SolidColorLayer
> LayerTreePixelTest::CreateSolidColorLayer(
75 gfx::Rect rect
, SkColor color
) {
76 scoped_refptr
<SolidColorLayer
> layer
= SolidColorLayer::Create();
77 layer
->SetIsDrawable(true);
78 layer
->SetAnchorPoint(gfx::PointF());
79 layer
->SetBounds(rect
.size());
80 layer
->SetPosition(rect
.origin());
81 layer
->SetBackgroundColor(color
);
85 scoped_refptr
<SolidColorLayer
> LayerTreePixelTest::
86 CreateSolidColorLayerWithBorder(
87 gfx::Rect rect
, SkColor color
, int border_width
, SkColor border_color
) {
88 scoped_refptr
<SolidColorLayer
> layer
= CreateSolidColorLayer(rect
, color
);
89 scoped_refptr
<SolidColorLayer
> border_top
= CreateSolidColorLayer(
90 gfx::Rect(0, 0, rect
.width(), border_width
), border_color
);
91 scoped_refptr
<SolidColorLayer
> border_left
= CreateSolidColorLayer(
95 rect
.height() - border_width
* 2),
97 scoped_refptr
<SolidColorLayer
> border_right
= CreateSolidColorLayer(
98 gfx::Rect(rect
.width() - border_width
,
101 rect
.height() - border_width
* 2),
103 scoped_refptr
<SolidColorLayer
> border_bottom
= CreateSolidColorLayer(
104 gfx::Rect(0, rect
.height() - border_width
, rect
.width(), border_width
),
106 layer
->AddChild(border_top
);
107 layer
->AddChild(border_left
);
108 layer
->AddChild(border_right
);
109 layer
->AddChild(border_bottom
);
113 void LayerTreePixelTest::RunPixelTest(
114 scoped_refptr
<Layer
> content_root
,
115 base::FilePath file_name
) {
116 content_root_
= content_root
;
117 ref_file_
= file_name
;
121 void LayerTreePixelTest::SetupTree() {
122 scoped_refptr
<Layer
> root
= Layer::Create();
123 root
->SetBounds(content_root_
->bounds());
124 root
->AddChild(content_root_
);
125 layer_tree_host()->SetRootLayer(root
);
126 LayerTreeTest::SetupTree();