Chromium Code Reviews| 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/test/layer_tree_pixel_test.h" | |
| 6 | |
| 7 #include "base/path_service.h" | |
| 8 #include "cc/layer_tree_impl.h" | |
| 9 #include "cc/test/paths.h" | |
| 10 #include "cc/test/pixel_test_utils.h" | |
| 11 #include "ui/gl/gl_implementation.h" | |
| 12 #include "webkit/gpu/context_provider_in_process.h" | |
| 13 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | |
| 14 | |
| 15 namespace cc { | |
| 16 | |
| 17 LayerTreePixelTest::LayerTreePixelTest() {} | |
| 18 | |
| 19 LayerTreePixelTest::~LayerTreePixelTest() {} | |
| 20 | |
| 21 scoped_ptr<OutputSurface> LayerTreePixelTest::createOutputSurface() { | |
| 22 EXPECT_TRUE(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL)); | |
|
jamesr
2013/03/14 20:00:46
InitializeGLBindings() doesn't look safe to call m
danakj
2013/03/14 20:43:50
Oh ok. I had actually looked in the function and m
danakj
2013/03/14 21:33:51
Can't ASSERT_TRUE unless the return type is void.
| |
| 23 | |
| 24 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | |
| 25 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d( | |
| 26 new WebGraphicsContext3DInProcessCommandBufferImpl); | |
| 27 context3d->Initialize(WebKit::WebGraphicsContext3D::Attributes(), NULL); | |
| 28 return make_scoped_ptr( | |
| 29 new OutputSurface(context3d.PassAs<WebKit::WebGraphicsContext3D>())); | |
| 30 } | |
| 31 | |
| 32 scoped_refptr<cc::ContextProvider> | |
| 33 LayerTreePixelTest::OffscreenContextProviderForMainThread() { | |
| 34 return new webkit::gpu::ContextProviderInProcess( | |
| 35 webkit::gpu::ContextProviderInProcess::IN_PROCESS_COMMAND_BUFFER); | |
| 36 } | |
| 37 | |
| 38 scoped_refptr<cc::ContextProvider> | |
| 39 LayerTreePixelTest::OffscreenContextProviderForCompositorThread() { | |
| 40 return new webkit::gpu::ContextProviderInProcess( | |
| 41 webkit::gpu::ContextProviderInProcess::IN_PROCESS_COMMAND_BUFFER); | |
| 42 } | |
| 43 | |
| 44 void LayerTreePixelTest::swapBuffersOnThread(LayerTreeHostImpl* host_impl, | |
| 45 bool result) { | |
| 46 EXPECT_TRUE(result); | |
| 47 | |
| 48 gfx::Rect device_viewport_rect( | |
| 49 host_impl->active_tree()->device_viewport_size()); | |
| 50 | |
| 51 SkBitmap bitmap; | |
| 52 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | |
| 53 device_viewport_rect.width(), | |
| 54 device_viewport_rect.height()); | |
| 55 bitmap.allocPixels(); | |
| 56 unsigned char* pixels = static_cast<unsigned char*>(bitmap.getPixels()); | |
| 57 host_impl->Readback(pixels, device_viewport_rect); | |
| 58 | |
| 59 base::FilePath test_data_dir; | |
| 60 EXPECT_TRUE(PathService::Get(cc::DIR_TEST_DATA, &test_data_dir)); | |
| 61 | |
| 62 // To rebaseline: | |
| 63 //EXPECT_TRUE(WritePNGFile(bitmap, test_data_dir.Append(ref_file_))); | |
| 64 | |
| 65 EXPECT_TRUE(IsSameAsPNGFile(bitmap, test_data_dir.Append(ref_file_))); | |
| 66 | |
| 67 endTest(); | |
| 68 } | |
| 69 | |
| 70 void LayerTreePixelTest::beginTest() { | |
| 71 postSetNeedsCommitToMainThread(); | |
| 72 } | |
| 73 | |
| 74 void LayerTreePixelTest::afterTest() {} | |
| 75 | |
| 76 scoped_refptr<SolidColorLayer> LayerTreePixelTest::CreateSolidColorLayer( | |
| 77 gfx::Rect rect, SkColor color) { | |
| 78 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::Create(); | |
| 79 layer->SetIsDrawable(true); | |
| 80 layer->SetAnchorPoint(gfx::PointF()); | |
| 81 layer->SetBounds(rect.size()); | |
| 82 layer->SetPosition(rect.origin()); | |
| 83 layer->SetBackgroundColor(color); | |
| 84 return layer; | |
| 85 } | |
| 86 | |
| 87 void LayerTreePixelTest::RunPixelTest( | |
| 88 scoped_refptr<Layer> content_root, | |
| 89 base::FilePath file_name) | |
| 90 { | |
| 91 content_root_ = content_root; | |
| 92 ref_file_ = file_name; | |
| 93 runTest(true); | |
| 94 } | |
| 95 | |
| 96 void LayerTreePixelTest::setupTree() { | |
| 97 scoped_refptr<Layer> root = Layer::Create(); | |
| 98 root->SetBounds(content_root_->bounds()); | |
| 99 root->AddChild(content_root_); | |
| 100 m_layerTreeHost->SetRootLayer(root); | |
| 101 ThreadedTest::setupTree(); | |
| 102 } | |
| 103 | |
| 104 } // namespace cc | |
| OLD | NEW |