Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Side by Side Diff: cc/gl_renderer_pixel_test.cc

Issue 11412289: Basic pixel tests for cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2012 The Chromium Authors. All rights reserved.
danakj 2012/12/01 01:56:36 should this file be chromium style names and inden
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/gl_renderer.h"
6
7 #include "base/file_util.h"
8 #include "base/path_service.h"
9 #include "cc/draw_quad.h"
10 #include "cc/prioritized_resource_manager.h"
11 #include "cc/resource_provider.h"
12 #include "cc/test/pixel_test_graphics_context.h"
13 #include "cc/test/render_pass_test_common.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gfx/codec/png_codec.h"
17 #include "ui/gl/gl_implementation.h"
18
19 using WebKitTests::TestRenderPass;
20
21 namespace cc {
22 namespace {
23
24 class FakeRendererClient : public RendererClient {
25 public:
26 FakeRendererClient()
27 {
28 }
29
30 // RendererClient methods.
31 virtual const gfx::Size& deviceViewportSize() const OVERRIDE { static gfx::S ize fakeSize(200, 200); return fakeSize; }
32 virtual const LayerTreeSettings& settings() const OVERRIDE { static LayerTre eSettings fakeSettings; return fakeSettings; }
33 virtual void didLoseContext() OVERRIDE { }
34 virtual void onSwapBuffersComplete() OVERRIDE { }
35 virtual void setFullRootLayerDamage() OVERRIDE { }
36 virtual void setManagedMemoryPolicy(const ManagedMemoryPolicy& policy) OVERR IDE { }
37 virtual void enforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy) O VERRIDE { }
38 virtual bool hasImplThread() const OVERRIDE { return false; }
39 };
40
41
42 class GLRendererPixelTest : public testing::Test {
43 protected:
44 GLRendererPixelTest()
45 {
46 }
47
48 virtual void SetUp()
49 {
50 gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL);
51 m_context = PixelTestGraphicsContext::create();
52 m_resourceProvider = ResourceProvider::create(m_context.get());
53 m_renderer = GLRenderer::create(&m_mockClient, m_resourceProvider.get()) ;
54 }
55
56 scoped_ptr<GraphicsContext> m_context;
57 FakeRendererClient m_mockClient;
58 scoped_ptr<ResourceProvider> m_resourceProvider;
59 scoped_ptr<GLRenderer> m_renderer;
60 };
61
62 TEST_F(GLRendererPixelTest, simpleGreenRect)
63 {
64 RenderPass::Id id(1, 1);
65 scoped_ptr<RenderPass> pass = RenderPass::Create();
66
67 gfx::Rect rect(0, 0, 100, 100);
68 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create();
69 shared_state->SetAll(gfx::Transform(),
70 rect,
71 rect,
72 rect,
73 false,
74 1);
75
76 scoped_ptr<SolidColorDrawQuad> colorQuad = SolidColorDrawQuad::Create();
77 colorQuad->SetNew(shared_state.get(), rect, SK_ColorGREEN);
78
79 pass->quad_list.append(colorQuad.PassAs<DrawQuad>());
80
81 RenderPassList passList;
82 passList.push_back(pass.get());
83 RenderPassIdHashMap passMap;
84 passMap.add(id, pass.PassAs<RenderPass>());
85
86 m_renderer->drawFrame(passList, passMap);
87
88 unsigned char pixels[4*200*200];
89 m_renderer->getFramebufferPixels(pixels, gfx::Rect(0, 0, 200, 200));
90
91 std::vector<gfx::PNGCodec::Comment> comments;
92 std::vector<unsigned char> png;
93 ASSERT_TRUE(gfx::PNGCodec::Encode(pixels, gfx::PNGCodec::FORMAT_RGBA, gfx::S ize(200, 200), 200 * 4, false, comments, &png));
94
95 FilePath base_path;
danakj 2012/12/01 01:56:36 Can the non-test-specific stuff go in a test basec
96 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &base_path));
97 FilePath test_data_directory = base_path;
98 //ASSERT_TRUE(PathService::Get(cc::DIR_TEST_DATA, &test_data_directory));
99 file_util::WriteFile(test_data_directory.AppendASCII("green.png"),
danakj 2012/12/01 01:56:36 Why writing a file instead of comparing?
100 reinterpret_cast<const char*>(png.data()), png.size());
101 }
102
103 } // namespace
104 } // namespace cc
OLDNEW
« cc/gl_renderer.h ('K') | « cc/gl_renderer.h ('k') | cc/test/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698