summaryrefslogtreecommitdiffstats
path: root/cc/test/pixel_test.cc
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-15 04:57:34 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-15 04:57:34 +0000
commita7252f11b13e3e5193f7d40ae9e6464a3dbdb2ac (patch)
tree116654d64447a41283154671a99c42cb2adfcf37 /cc/test/pixel_test.cc
parentfb52ada47741872b4add857717c9d79cf23b6704 (diff)
downloadchromium_src-a7252f11b13e3e5193f7d40ae9e6464a3dbdb2ac.zip
chromium_src-a7252f11b13e3e5193f7d40ae9e6464a3dbdb2ac.tar.gz
chromium_src-a7252f11b13e3e5193f7d40ae9e6464a3dbdb2ac.tar.bz2
cc: Add layer-based pixel tests.
This adds a test framework for pixel tests based on a layer tree. Included is a single new pixel test to demonstrate the framework, which is a test derived from the layout test platform/chromium/compositing/filters/background-filter-blur.html reproduced with solid color layers. New test: LayerTreeHostFiltersPixelTest.BackgroundFilterBlur R=jamesr BUG=191170 Review URL: https://chromiumcodereview.appspot.com/12518026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188262 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/test/pixel_test.cc')
-rw-r--r--cc/test/pixel_test.cc99
1 files changed, 99 insertions, 0 deletions
diff --git a/cc/test/pixel_test.cc b/cc/test/pixel_test.cc
new file mode 100644
index 0000000..59ea9bb
--- /dev/null
+++ b/cc/test/pixel_test.cc
@@ -0,0 +1,99 @@
+// 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/pixel_test.h"
+
+#include "base/path_service.h"
+#include "cc/compositor_frame_metadata.h"
+#include "cc/gl_renderer.h"
+#include "cc/output_surface.h"
+#include "cc/resource_provider.h"
+#include "cc/test/paths.h"
+#include "cc/test/pixel_test_utils.h"
+#include "testing/gtest/include/gtest/gtest.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 {
+
+class PixelTest::PixelTestRendererClient : public RendererClient {
+ public:
+ PixelTestRendererClient(gfx::Size device_viewport_size)
+ : device_viewport_size_(device_viewport_size) {}
+
+ // RendererClient implementation.
+ virtual gfx::Size DeviceViewportSize() const OVERRIDE {
+ return device_viewport_size_;
+ }
+ virtual const LayerTreeSettings& Settings() const OVERRIDE {
+ return settings_;
+ }
+ virtual void DidLoseOutputSurface() OVERRIDE {}
+ virtual void OnSwapBuffersComplete() OVERRIDE {}
+ virtual void SetFullRootLayerDamage() OVERRIDE {}
+ virtual void SetManagedMemoryPolicy(
+ const ManagedMemoryPolicy& policy) OVERRIDE {}
+ virtual void EnforceManagedMemoryPolicy(
+ const ManagedMemoryPolicy& policy) OVERRIDE {}
+ virtual bool HasImplThread() const OVERRIDE { return false; }
+ virtual bool ShouldClearRootRenderPass() const OVERRIDE { return true; }
+ virtual CompositorFrameMetadata MakeCompositorFrameMetadata() const
+ OVERRIDE {
+ return CompositorFrameMetadata();
+ }
+
+ private:
+ gfx::Size device_viewport_size_;
+ LayerTreeSettings settings_;
+};
+
+PixelTest::PixelTest() : device_viewport_size_(gfx::Size(200, 200)) {}
+
+PixelTest::~PixelTest() {}
+
+void PixelTest::SetUp() {
+ gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL);
+ scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl>
+ context3d(
+ new webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl);
+ context3d->Initialize(WebKit::WebGraphicsContext3D::Attributes(), NULL);
+ output_surface_.reset(new OutputSurface(
+ context3d.PassAs<WebKit::WebGraphicsContext3D>()));
+ resource_provider_ = ResourceProvider::Create(output_surface_.get());
+ fake_client_ =
+ make_scoped_ptr(new PixelTestRendererClient(device_viewport_size_));
+ renderer_ = GLRenderer::Create(fake_client_.get(),
+ output_surface_.get(),
+ resource_provider_.get());
+
+ scoped_refptr<cc::ContextProvider> offscreen_contexts =
+ new webkit::gpu::ContextProviderInProcess(
+ webkit::gpu::ContextProviderInProcess::IN_PROCESS_COMMAND_BUFFER);
+ ASSERT_TRUE(offscreen_contexts->InitializeOnMainThread());
+ resource_provider_->SetOffscreenContextProvider(offscreen_contexts);
+}
+
+bool PixelTest::PixelsMatchReference(const base::FilePath& ref_file) {
+ gfx::Rect device_viewport_rect(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());
+ renderer_->GetFramebufferPixels(pixels, device_viewport_rect);
+
+ base::FilePath test_data_dir;
+ if (!PathService::Get(cc::DIR_TEST_DATA, &test_data_dir))
+ return false;
+
+ // To rebaseline:
+ //return WritePNGFile(bitmap, test_data_dir.Append(ref_file));
+
+ return IsSameAsPNGFile(bitmap, test_data_dir.Append(ref_file));
+}
+
+} // namespace cc