| Index: cc/test/layer_tree_pixel_test.cc
|
| diff --git a/cc/test/layer_tree_pixel_test.cc b/cc/test/layer_tree_pixel_test.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..63cfd6ff3305e72c09b868297345346021098f04
|
| --- /dev/null
|
| +++ b/cc/test/layer_tree_pixel_test.cc
|
| @@ -0,0 +1,104 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "cc/test/layer_tree_pixel_test.h"
|
| +
|
| +#include "base/path_service.h"
|
| +#include "cc/layer_tree_impl.h"
|
| +#include "cc/test/paths.h"
|
| +#include "cc/test/pixel_test_utils.h"
|
| +#include "ui/gl/gl_implementation.h"
|
| +#include "webkit/gpu/context_provider_in_process.h"
|
| +#include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
|
| +
|
| +namespace cc {
|
| +
|
| +LayerTreePixelTest::LayerTreePixelTest() {}
|
| +
|
| +LayerTreePixelTest::~LayerTreePixelTest() {}
|
| +
|
| +scoped_ptr<OutputSurface> LayerTreePixelTest::createOutputSurface() {
|
| + CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL));
|
| +
|
| + using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
|
| + scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d(
|
| + new WebGraphicsContext3DInProcessCommandBufferImpl);
|
| + context3d->Initialize(WebKit::WebGraphicsContext3D::Attributes(), NULL);
|
| + return make_scoped_ptr(
|
| + new OutputSurface(context3d.PassAs<WebKit::WebGraphicsContext3D>()));
|
| +}
|
| +
|
| +scoped_refptr<cc::ContextProvider>
|
| +LayerTreePixelTest::OffscreenContextProviderForMainThread() {
|
| + return new webkit::gpu::ContextProviderInProcess(
|
| + webkit::gpu::ContextProviderInProcess::IN_PROCESS_COMMAND_BUFFER);
|
| +}
|
| +
|
| +scoped_refptr<cc::ContextProvider>
|
| +LayerTreePixelTest::OffscreenContextProviderForCompositorThread() {
|
| + return new webkit::gpu::ContextProviderInProcess(
|
| + webkit::gpu::ContextProviderInProcess::IN_PROCESS_COMMAND_BUFFER);
|
| +}
|
| +
|
| +void LayerTreePixelTest::swapBuffersOnThread(LayerTreeHostImpl* host_impl,
|
| + bool result) {
|
| + EXPECT_TRUE(result);
|
| +
|
| + gfx::Rect device_viewport_rect(
|
| + host_impl->active_tree()->device_viewport_size());
|
| +
|
| + SkBitmap bitmap;
|
| + bitmap.setConfig(SkBitmap::kARGB_8888_Config,
|
| + device_viewport_rect.width(),
|
| + device_viewport_rect.height());
|
| + bitmap.allocPixels();
|
| + unsigned char* pixels = static_cast<unsigned char*>(bitmap.getPixels());
|
| + host_impl->Readback(pixels, device_viewport_rect);
|
| +
|
| + base::FilePath test_data_dir;
|
| + EXPECT_TRUE(PathService::Get(cc::DIR_TEST_DATA, &test_data_dir));
|
| +
|
| + // To rebaseline:
|
| + //EXPECT_TRUE(WritePNGFile(bitmap, test_data_dir.Append(ref_file_)));
|
| +
|
| + EXPECT_TRUE(IsSameAsPNGFile(bitmap, test_data_dir.Append(ref_file_)));
|
| +
|
| + endTest();
|
| +}
|
| +
|
| +void LayerTreePixelTest::beginTest() {
|
| + postSetNeedsCommitToMainThread();
|
| +}
|
| +
|
| +void LayerTreePixelTest::afterTest() {}
|
| +
|
| +scoped_refptr<SolidColorLayer> LayerTreePixelTest::CreateSolidColorLayer(
|
| + gfx::Rect rect, SkColor color) {
|
| + scoped_refptr<SolidColorLayer> layer = SolidColorLayer::Create();
|
| + layer->SetIsDrawable(true);
|
| + layer->SetAnchorPoint(gfx::PointF());
|
| + layer->SetBounds(rect.size());
|
| + layer->SetPosition(rect.origin());
|
| + layer->SetBackgroundColor(color);
|
| + return layer;
|
| +}
|
| +
|
| +void LayerTreePixelTest::RunPixelTest(
|
| + scoped_refptr<Layer> content_root,
|
| + base::FilePath file_name)
|
| +{
|
| + content_root_ = content_root;
|
| + ref_file_ = file_name;
|
| + runTest(true);
|
| +}
|
| +
|
| +void LayerTreePixelTest::setupTree() {
|
| + scoped_refptr<Layer> root = Layer::Create();
|
| + root->SetBounds(content_root_->bounds());
|
| + root->AddChild(content_root_);
|
| + m_layerTreeHost->SetRootLayer(root);
|
| + ThreadedTest::setupTree();
|
| +}
|
| +
|
| +} // namespace cc
|
|
|