OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2012 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/gl_renderer.h" | |
6 | |
7 #include "base/file_util.h" | |
8 #include "base/path_service.h" | |
9 #include "cc/cc_paths.h" | |
10 #include "cc/draw_quad.h" | |
11 #include "cc/prioritized_resource_manager.h" | |
12 #include "cc/resource_provider.h" | |
13 #include "cc/test/pixel_test_graphics_context.h" | |
14 #include "cc/test/pixel_test_utils.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 namespace cc { | |
20 namespace { | |
21 | |
22 class FakeRendererClient : public RendererClient { | |
23 public: | |
24 FakeRendererClient() | |
25 { | |
26 } | |
27 | |
28 // RendererClient methods. | |
29 virtual const gfx::Size& deviceViewportSize() const OVERRIDE { | |
30 static gfx::Size fakeSize(200, 200); | |
danakj
2012/12/03 19:14:10
nit: fake_size
| |
31 return fakeSize; | |
32 } | |
33 virtual const LayerTreeSettings& settings() const OVERRIDE { | |
34 static LayerTreeSettings fakeSettings; | |
danakj
2012/12/03 19:14:10
nit: fake_settings
| |
35 return fakeSettings; | |
36 } | |
37 virtual void didLoseContext() OVERRIDE { } | |
38 virtual void onSwapBuffersComplete() OVERRIDE { } | |
39 virtual void setFullRootLayerDamage() OVERRIDE { } | |
40 virtual void setManagedMemoryPolicy(const ManagedMemoryPolicy&) OVERRIDE {} | |
41 virtual void enforceManagedMemoryPolicy( | |
42 const ManagedMemoryPolicy&) OVERRIDE {} | |
43 virtual bool hasImplThread() const OVERRIDE { return false; } | |
44 }; | |
45 | |
46 | |
47 class GLRendererPixeltest : public testing::Test { | |
enne (OOO)
2012/12/03 21:40:29
Can you be consistent in your capitalization of Te
| |
48 protected: | |
49 GLRendererPixeltest() {} | |
50 | |
51 virtual void SetUp() { | |
52 gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL); | |
53 context_ = PixelTestGraphicsContext::create(); | |
54 resource_provider_ = ResourceProvider::create(context_.get()); | |
55 renderer_ = GLRenderer::create(&fake_client_, resource_provider_.get()); | |
56 } | |
57 | |
58 scoped_ptr<GraphicsContext> context_; | |
59 FakeRendererClient fake_client_; | |
60 scoped_ptr<ResourceProvider> resource_provider_; | |
61 scoped_ptr<GLRenderer> renderer_; | |
62 }; | |
63 | |
64 TEST_F(GLRendererPixeltest, simpleGreenRect) { | |
65 gfx::Rect rect(0, 0, 200, 200); | |
66 | |
67 RenderPass::Id id(1, 1); | |
68 scoped_ptr<RenderPass> pass = RenderPass::Create(); | |
69 pass->SetNew(id, rect, rect, gfx::Transform()); | |
70 | |
71 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create(); | |
72 shared_state->SetAll(gfx::Transform(), | |
73 rect, | |
danakj
2012/12/03 19:14:10
can you use temp vars for these so we can see what
| |
74 rect, | |
75 rect, | |
76 false, | |
77 1); | |
78 | |
79 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); | |
80 color_quad->SetNew(shared_state.get(), rect, SK_ColorGREEN); | |
81 | |
82 pass->quad_list.append(color_quad.PassAs<DrawQuad>()); | |
83 | |
84 RenderPassList pass_list; | |
85 pass_list.push_back(pass.get()); | |
86 RenderPassIdHashMap pass_map; | |
87 pass_map.add(id, pass.PassAs<RenderPass>()); | |
88 | |
89 renderer_->drawFrame(pass_list, pass_map); | |
90 | |
91 SkBitmap bitmap; | |
92 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 200, 200); | |
93 bitmap.allocPixels(); | |
94 unsigned char* pixels = static_cast<unsigned char*>(bitmap.getPixels()); | |
95 renderer_->getFramebufferPixels(pixels, gfx::Rect(0, 0, 200, 200)); | |
96 | |
97 FilePath test_data_dir; | |
98 ASSERT_TRUE(PathService::Get(cc::DIR_TEST_DATA, &test_data_dir)); | |
99 // test::WritePNGFile(bitmap, test_data_dir.AppendASCII("green.png")); | |
100 EXPECT_TRUE(test::IsSameAsPNGFile(bitmap, | |
101 test_data_dir.AppendASCII("green.png"))); | |
102 } | |
103 | |
104 } // namespace | |
105 } // namespace cc | |
OLD | NEW |