Chromium Code Reviews| Index: cc/gl_renderer_pixel_test.cc |
| diff --git a/cc/gl_renderer_pixel_test.cc b/cc/gl_renderer_pixel_test.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..147cb1e33d22cce6fac1b1c539b099953131bac3 |
| --- /dev/null |
| +++ b/cc/gl_renderer_pixel_test.cc |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2012 The Chromium Authors. All rights reserved. |
|
danakj
2012/12/01 01:56:36
should this file be chromium style names and inden
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/gl_renderer.h" |
| + |
| +#include "base/file_util.h" |
| +#include "base/path_service.h" |
| +#include "cc/draw_quad.h" |
| +#include "cc/prioritized_resource_manager.h" |
| +#include "cc/resource_provider.h" |
| +#include "cc/test/pixel_test_graphics_context.h" |
| +#include "cc/test/render_pass_test_common.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/gfx/codec/png_codec.h" |
| +#include "ui/gl/gl_implementation.h" |
| + |
| +using WebKitTests::TestRenderPass; |
| + |
| +namespace cc { |
| +namespace { |
| + |
| +class FakeRendererClient : public RendererClient { |
| +public: |
| + FakeRendererClient() |
| + { |
| + } |
| + |
| + // RendererClient methods. |
| + virtual const gfx::Size& deviceViewportSize() const OVERRIDE { static gfx::Size fakeSize(200, 200); return fakeSize; } |
| + virtual const LayerTreeSettings& settings() const OVERRIDE { static LayerTreeSettings fakeSettings; return fakeSettings; } |
| + virtual void didLoseContext() 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; } |
| +}; |
| + |
| + |
| +class GLRendererPixelTest : public testing::Test { |
| +protected: |
| + GLRendererPixelTest() |
| + { |
| + } |
| + |
| + virtual void SetUp() |
| + { |
| + gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL); |
| + m_context = PixelTestGraphicsContext::create(); |
| + m_resourceProvider = ResourceProvider::create(m_context.get()); |
| + m_renderer = GLRenderer::create(&m_mockClient, m_resourceProvider.get()); |
| + } |
| + |
| + scoped_ptr<GraphicsContext> m_context; |
| + FakeRendererClient m_mockClient; |
| + scoped_ptr<ResourceProvider> m_resourceProvider; |
| + scoped_ptr<GLRenderer> m_renderer; |
| +}; |
| + |
| +TEST_F(GLRendererPixelTest, simpleGreenRect) |
| +{ |
| + RenderPass::Id id(1, 1); |
| + scoped_ptr<RenderPass> pass = RenderPass::Create(); |
| + |
| + gfx::Rect rect(0, 0, 100, 100); |
| + scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create(); |
| + shared_state->SetAll(gfx::Transform(), |
| + rect, |
| + rect, |
| + rect, |
| + false, |
| + 1); |
| + |
| + scoped_ptr<SolidColorDrawQuad> colorQuad = SolidColorDrawQuad::Create(); |
| + colorQuad->SetNew(shared_state.get(), rect, SK_ColorGREEN); |
| + |
| + pass->quad_list.append(colorQuad.PassAs<DrawQuad>()); |
| + |
| + RenderPassList passList; |
| + passList.push_back(pass.get()); |
| + RenderPassIdHashMap passMap; |
| + passMap.add(id, pass.PassAs<RenderPass>()); |
| + |
| + m_renderer->drawFrame(passList, passMap); |
| + |
| + unsigned char pixels[4*200*200]; |
| + m_renderer->getFramebufferPixels(pixels, gfx::Rect(0, 0, 200, 200)); |
| + |
| + std::vector<gfx::PNGCodec::Comment> comments; |
| + std::vector<unsigned char> png; |
| + ASSERT_TRUE(gfx::PNGCodec::Encode(pixels, gfx::PNGCodec::FORMAT_RGBA, gfx::Size(200, 200), 200 * 4, false, comments, &png)); |
| + |
| + FilePath base_path; |
|
danakj
2012/12/01 01:56:36
Can the non-test-specific stuff go in a test basec
|
| + ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &base_path)); |
| + FilePath test_data_directory = base_path; |
| + //ASSERT_TRUE(PathService::Get(cc::DIR_TEST_DATA, &test_data_directory)); |
| + file_util::WriteFile(test_data_directory.AppendASCII("green.png"), |
|
danakj
2012/12/01 01:56:36
Why writing a file instead of comparing?
|
| + reinterpret_cast<const char*>(png.data()), png.size()); |
| +} |
| + |
| +} // namespace |
| +} // namespace cc |