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/test/layer_tree_pixel_test.h" | 5 #include "cc/test/layer_tree_pixel_test.h" |
6 | 6 |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "cc/test/paths.h" | 8 #include "cc/test/paths.h" |
9 #include "cc/test/pixel_comparator.h" | 9 #include "cc/test/pixel_comparator.h" |
10 #include "cc/test/pixel_test_utils.h" | 10 #include "cc/test/pixel_test_utils.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 } | 40 } |
41 | 41 |
42 scoped_refptr<cc::ContextProvider> | 42 scoped_refptr<cc::ContextProvider> |
43 LayerTreePixelTest::OffscreenContextProviderForCompositorThread() { | 43 LayerTreePixelTest::OffscreenContextProviderForCompositorThread() { |
44 scoped_refptr<webkit::gpu::ContextProviderInProcess> provider = | 44 scoped_refptr<webkit::gpu::ContextProviderInProcess> provider = |
45 webkit::gpu::ContextProviderInProcess::Create(); | 45 webkit::gpu::ContextProviderInProcess::Create(); |
46 CHECK(provider); | 46 CHECK(provider); |
47 return provider; | 47 return provider; |
48 } | 48 } |
49 | 49 |
50 void LayerTreePixelTest::SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | 50 void LayerTreePixelTest::ReadbackResult(scoped_ptr<SkBitmap> bitmap) { |
51 bool result) { | 51 ASSERT_TRUE(bitmap); |
52 EXPECT_TRUE(result); | |
53 | |
54 gfx::Rect device_viewport_rect( | |
55 host_impl->active_tree()->device_viewport_size()); | |
56 | |
57 SkBitmap bitmap; | |
58 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | |
59 device_viewport_rect.width(), | |
60 device_viewport_rect.height()); | |
61 bitmap.allocPixels(); | |
62 unsigned char* pixels = static_cast<unsigned char*>(bitmap.getPixels()); | |
63 host_impl->Readback(pixels, device_viewport_rect); | |
64 | 52 |
65 base::FilePath test_data_dir; | 53 base::FilePath test_data_dir; |
66 EXPECT_TRUE(PathService::Get(cc::DIR_TEST_DATA, &test_data_dir)); | 54 EXPECT_TRUE(PathService::Get(cc::DIR_TEST_DATA, &test_data_dir)); |
67 | 55 |
68 // To rebaseline: | 56 // To rebaseline: |
69 // EXPECT_TRUE(WritePNGFile(bitmap, test_data_dir.Append(ref_file_), true)); | 57 // EXPECT_TRUE(WritePNGFile(*bitmap, test_data_dir.Append(ref_file_), true)); |
70 | 58 |
71 EXPECT_TRUE(MatchesPNGFile(bitmap, | 59 EXPECT_TRUE(MatchesPNGFile(*bitmap, |
72 test_data_dir.Append(ref_file_), | 60 test_data_dir.Append(ref_file_), |
73 *pixel_comparator_)); | 61 *pixel_comparator_)); |
74 | |
75 EndTest(); | 62 EndTest(); |
76 } | 63 } |
77 | 64 |
78 void LayerTreePixelTest::BeginTest() { | 65 void LayerTreePixelTest::BeginTest() { |
| 66 layer_tree_host()->root_layer()->RequestCopyAsBitmap( |
| 67 base::Bind(&LayerTreePixelTest::ReadbackResult, |
| 68 base::Unretained(this))); |
79 PostSetNeedsCommitToMainThread(); | 69 PostSetNeedsCommitToMainThread(); |
80 } | 70 } |
81 | 71 |
82 void LayerTreePixelTest::AfterTest() {} | 72 void LayerTreePixelTest::AfterTest() {} |
83 | 73 |
84 scoped_refptr<SolidColorLayer> LayerTreePixelTest::CreateSolidColorLayer( | 74 scoped_refptr<SolidColorLayer> LayerTreePixelTest::CreateSolidColorLayer( |
85 gfx::Rect rect, SkColor color) { | 75 gfx::Rect rect, SkColor color) { |
86 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::Create(); | 76 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::Create(); |
87 layer->SetIsDrawable(true); | 77 layer->SetIsDrawable(true); |
88 layer->SetAnchorPoint(gfx::PointF()); | 78 layer->SetAnchorPoint(gfx::PointF()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 120 |
131 void LayerTreePixelTest::SetupTree() { | 121 void LayerTreePixelTest::SetupTree() { |
132 scoped_refptr<Layer> root = Layer::Create(); | 122 scoped_refptr<Layer> root = Layer::Create(); |
133 root->SetBounds(content_root_->bounds()); | 123 root->SetBounds(content_root_->bounds()); |
134 root->AddChild(content_root_); | 124 root->AddChild(content_root_); |
135 layer_tree_host()->SetRootLayer(root); | 125 layer_tree_host()->SetRootLayer(root); |
136 LayerTreeTest::SetupTree(); | 126 LayerTreeTest::SetupTree(); |
137 } | 127 } |
138 | 128 |
139 } // namespace cc | 129 } // namespace cc |
OLD | NEW |