| 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/draw_quad.h" | |
| 10 #include "cc/prioritized_resource_manager.h" | |
| 11 #include "cc/resource_provider.h" | |
| 12 #include "cc/test/paths.h" | |
| 13 #include "cc/test/pixel_test_output_surface.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 fake_size(200, 200); | |
| 31 return fake_size; | |
| 32 } | |
| 33 virtual const LayerTreeSettings& settings() const OVERRIDE { | |
| 34 static LayerTreeSettings fake_settings; | |
| 35 return fake_settings; | |
| 36 } | |
| 37 virtual void didLoseOutputSurface() 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 { | |
| 48 protected: | |
| 49 GLRendererPixelTest() {} | |
| 50 | |
| 51 virtual void SetUp() { | |
| 52 gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL); | |
| 53 output_surface_ = PixelTestOutputSurface::create(); | |
| 54 resource_provider_ = ResourceProvider::create(output_surface_.get()); | |
| 55 renderer_ = GLRenderer::create(&fake_client_, resource_provider_.get()); | |
| 56 } | |
| 57 | |
| 58 scoped_ptr<OutputSurface> output_surface_; | |
| 59 FakeRendererClient fake_client_; | |
| 60 scoped_ptr<ResourceProvider> resource_provider_; | |
| 61 scoped_ptr<GLRenderer> renderer_; | |
| 62 }; | |
| 63 | |
| 64 #if !defined(OS_ANDROID) | |
| 65 TEST_F(GLRendererPixelTest, simpleGreenRect) { | |
| 66 gfx::Rect rect(0, 0, 200, 200); | |
| 67 | |
| 68 RenderPass::Id id(1, 1); | |
| 69 const gfx::Rect output_rect = rect; | |
| 70 const gfx::RectF damage_rect = rect; | |
| 71 const gfx::Transform transform_to_root_target; | |
| 72 scoped_ptr<RenderPass> pass = RenderPass::Create(); | |
| 73 pass->SetNew(id, output_rect, damage_rect, transform_to_root_target); | |
| 74 | |
| 75 const gfx::Transform content_to_target_transform; | |
| 76 const gfx::Rect visible_content_rect = rect; | |
| 77 const gfx::Rect clipped_rect_in_target = rect; | |
| 78 const gfx::Rect clip_rect = rect; | |
| 79 const bool is_clipped = false; | |
| 80 const float opacity = 1.0f; | |
| 81 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create(); | |
| 82 shared_state->SetAll(content_to_target_transform, | |
| 83 visible_content_rect, | |
| 84 clipped_rect_in_target, | |
| 85 clip_rect, | |
| 86 is_clipped, | |
| 87 opacity); | |
| 88 | |
| 89 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); | |
| 90 color_quad->SetNew(shared_state.get(), rect, SK_ColorGREEN); | |
| 91 | |
| 92 pass->quad_list.append(color_quad.PassAs<DrawQuad>()); | |
| 93 | |
| 94 RenderPassList pass_list; | |
| 95 pass_list.push_back(pass.get()); | |
| 96 RenderPassIdHashMap pass_map; | |
| 97 pass_map.add(id, pass.PassAs<RenderPass>()); | |
| 98 | |
| 99 renderer_->drawFrame(pass_list, pass_map); | |
| 100 | |
| 101 SkBitmap bitmap; | |
| 102 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 200, 200); | |
| 103 bitmap.allocPixels(); | |
| 104 unsigned char* pixels = static_cast<unsigned char*>(bitmap.getPixels()); | |
| 105 renderer_->getFramebufferPixels(pixels, gfx::Rect(0, 0, 200, 200)); | |
| 106 | |
| 107 FilePath test_data_dir; | |
| 108 ASSERT_TRUE(PathService::Get(cc::test::DIR_TEST_DATA, &test_data_dir)); | |
| 109 // test::WritePNGFile(bitmap, test_data_dir.AppendASCII("green.png")); | |
| 110 EXPECT_TRUE(test::IsSameAsPNGFile(bitmap, | |
| 111 test_data_dir.AppendASCII("green.png"))); | |
| 112 } | |
| 113 #endif | |
| 114 | |
| 115 } // namespace | |
| 116 } // namespace cc | |
| OLD | NEW |