| 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_test_utils.h" | 10 #include "cc/test/pixel_test_utils.h" |
| 10 #include "cc/trees/layer_tree_impl.h" | 11 #include "cc/trees/layer_tree_impl.h" |
| 11 #include "ui/gl/gl_implementation.h" | 12 #include "ui/gl/gl_implementation.h" |
| 12 #include "webkit/gpu/context_provider_in_process.h" | 13 #include "webkit/gpu/context_provider_in_process.h" |
| 13 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | 14 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
| 14 | 15 |
| 15 namespace cc { | 16 namespace cc { |
| 16 | 17 |
| 17 LayerTreePixelTest::LayerTreePixelTest() {} | 18 LayerTreePixelTest::LayerTreePixelTest() |
| 19 : pixel_comparator_(new ExactPixelComparator(true)) {} |
| 18 | 20 |
| 19 LayerTreePixelTest::~LayerTreePixelTest() {} | 21 LayerTreePixelTest::~LayerTreePixelTest() {} |
| 20 | 22 |
| 21 scoped_ptr<OutputSurface> LayerTreePixelTest::CreateOutputSurface() { | 23 scoped_ptr<OutputSurface> LayerTreePixelTest::CreateOutputSurface() { |
| 22 CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL)); | 24 CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL)); |
| 23 | 25 |
| 24 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | 26 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; |
| 25 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d( | 27 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d( |
| 26 new WebGraphicsContext3DInProcessCommandBufferImpl( | 28 new WebGraphicsContext3DInProcessCommandBufferImpl( |
| 27 WebKit::WebGraphicsContext3D::Attributes())); | 29 WebKit::WebGraphicsContext3D::Attributes())); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 bitmap.allocPixels(); | 61 bitmap.allocPixels(); |
| 60 unsigned char* pixels = static_cast<unsigned char*>(bitmap.getPixels()); | 62 unsigned char* pixels = static_cast<unsigned char*>(bitmap.getPixels()); |
| 61 host_impl->Readback(pixels, device_viewport_rect); | 63 host_impl->Readback(pixels, device_viewport_rect); |
| 62 | 64 |
| 63 base::FilePath test_data_dir; | 65 base::FilePath test_data_dir; |
| 64 EXPECT_TRUE(PathService::Get(cc::DIR_TEST_DATA, &test_data_dir)); | 66 EXPECT_TRUE(PathService::Get(cc::DIR_TEST_DATA, &test_data_dir)); |
| 65 | 67 |
| 66 // To rebaseline: | 68 // To rebaseline: |
| 67 // EXPECT_TRUE(WritePNGFile(bitmap, test_data_dir.Append(ref_file_))); | 69 // EXPECT_TRUE(WritePNGFile(bitmap, test_data_dir.Append(ref_file_))); |
| 68 | 70 |
| 69 EXPECT_TRUE(MatchesPNGFile(bitmap, test_data_dir.Append(ref_file_), | 71 EXPECT_TRUE(MatchesPNGFile(bitmap, |
| 70 ExactPixelComparator(true))); | 72 test_data_dir.Append(ref_file_), |
| 73 *pixel_comparator_)); |
| 71 | 74 |
| 72 EndTest(); | 75 EndTest(); |
| 73 } | 76 } |
| 74 | 77 |
| 75 void LayerTreePixelTest::BeginTest() { | 78 void LayerTreePixelTest::BeginTest() { |
| 76 PostSetNeedsCommitToMainThread(); | 79 PostSetNeedsCommitToMainThread(); |
| 77 } | 80 } |
| 78 | 81 |
| 79 void LayerTreePixelTest::AfterTest() {} | 82 void LayerTreePixelTest::AfterTest() {} |
| 80 | 83 |
| 81 scoped_refptr<SolidColorLayer> LayerTreePixelTest::CreateSolidColorLayer( | 84 scoped_refptr<SolidColorLayer> LayerTreePixelTest::CreateSolidColorLayer( |
| 82 gfx::Rect rect, SkColor color) { | 85 gfx::Rect rect, SkColor color) { |
| 83 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::Create(); | 86 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::Create(); |
| 84 layer->SetIsDrawable(true); | 87 layer->SetIsDrawable(true); |
| 85 layer->SetAnchorPoint(gfx::PointF()); | 88 layer->SetAnchorPoint(gfx::PointF()); |
| 86 layer->SetBounds(rect.size()); | 89 layer->SetBounds(rect.size()); |
| 87 layer->SetPosition(rect.origin()); | 90 layer->SetPosition(rect.origin()); |
| 88 layer->SetBackgroundColor(color); | 91 layer->SetBackgroundColor(color); |
| 89 return layer; | 92 return layer; |
| 90 } | 93 } |
| 91 | 94 |
| 95 scoped_refptr<SolidColorLayer> LayerTreePixelTest:: |
| 96 CreateSolidColorLayerWithBorder( |
| 97 gfx::Rect rect, SkColor color, int border_width, SkColor border_color) { |
| 98 scoped_refptr<SolidColorLayer> layer = CreateSolidColorLayer(rect, color); |
| 99 scoped_refptr<SolidColorLayer> border_top = CreateSolidColorLayer( |
| 100 gfx::Rect(0, 0, rect.width(), border_width), border_color); |
| 101 scoped_refptr<SolidColorLayer> border_left = CreateSolidColorLayer( |
| 102 gfx::Rect(0, |
| 103 border_width, |
| 104 border_width, |
| 105 rect.height() - border_width * 2), |
| 106 border_color); |
| 107 scoped_refptr<SolidColorLayer> border_right = CreateSolidColorLayer( |
| 108 gfx::Rect(rect.width() - border_width, |
| 109 border_width, |
| 110 border_width, |
| 111 rect.height() - border_width * 2), |
| 112 border_color); |
| 113 scoped_refptr<SolidColorLayer> border_bottom = CreateSolidColorLayer( |
| 114 gfx::Rect(0, rect.height() - border_width, rect.width(), border_width), |
| 115 border_color); |
| 116 layer->AddChild(border_top); |
| 117 layer->AddChild(border_left); |
| 118 layer->AddChild(border_right); |
| 119 layer->AddChild(border_bottom); |
| 120 return layer; |
| 121 } |
| 122 |
| 92 void LayerTreePixelTest::RunPixelTest( | 123 void LayerTreePixelTest::RunPixelTest( |
| 93 scoped_refptr<Layer> content_root, | 124 scoped_refptr<Layer> content_root, |
| 94 base::FilePath file_name) { | 125 base::FilePath file_name) { |
| 95 content_root_ = content_root; | 126 content_root_ = content_root; |
| 96 ref_file_ = file_name; | 127 ref_file_ = file_name; |
| 97 RunTest(true); | 128 RunTest(true); |
| 98 } | 129 } |
| 99 | 130 |
| 100 void LayerTreePixelTest::SetupTree() { | 131 void LayerTreePixelTest::SetupTree() { |
| 101 scoped_refptr<Layer> root = Layer::Create(); | 132 scoped_refptr<Layer> root = Layer::Create(); |
| 102 root->SetBounds(content_root_->bounds()); | 133 root->SetBounds(content_root_->bounds()); |
| 103 root->AddChild(content_root_); | 134 root->AddChild(content_root_); |
| 104 layer_tree_host()->SetRootLayer(root); | 135 layer_tree_host()->SetRootLayer(root); |
| 105 LayerTreeTest::SetupTree(); | 136 LayerTreeTest::SetupTree(); |
| 106 } | 137 } |
| 107 | 138 |
| 108 } // namespace cc | 139 } // namespace cc |
| OLD | NEW |