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

Side by Side Diff: cc/test/pixel_test.cc

Issue 12518026: cc: Add layer-based pixel tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months 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
« no previous file with comments | « cc/test/pixel_test.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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/test/pixel_test.h"
6
7 #include "base/path_service.h"
8 #include "cc/compositor_frame_metadata.h"
9 #include "cc/gl_renderer.h"
10 #include "cc/output_surface.h"
11 #include "cc/resource_provider.h"
12 #include "cc/test/paths.h"
13 #include "cc/test/pixel_test_utils.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gl/gl_implementation.h"
16 #include "webkit/gpu/context_provider_in_process.h"
17 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
18
19 namespace cc {
20
21 class PixelTest::PixelTestRendererClient : public RendererClient {
22 public:
23 PixelTestRendererClient(gfx::Size device_viewport_size)
24 : device_viewport_size_(device_viewport_size) {}
25
26 // RendererClient implementation.
27 virtual gfx::Size DeviceViewportSize() const OVERRIDE {
28 return device_viewport_size_;
29 }
30 virtual const LayerTreeSettings& Settings() const OVERRIDE {
31 return settings_;
32 }
33 virtual void DidLoseOutputSurface() OVERRIDE {}
34 virtual void OnSwapBuffersComplete() OVERRIDE {}
35 virtual void SetFullRootLayerDamage() OVERRIDE {}
36 virtual void SetManagedMemoryPolicy(
37 const ManagedMemoryPolicy& policy) OVERRIDE {}
38 virtual void EnforceManagedMemoryPolicy(
39 const ManagedMemoryPolicy& policy) OVERRIDE {}
40 virtual bool HasImplThread() const OVERRIDE { return false; }
41 virtual bool ShouldClearRootRenderPass() const OVERRIDE { return true; }
42 virtual CompositorFrameMetadata MakeCompositorFrameMetadata() const
43 OVERRIDE {
44 return CompositorFrameMetadata();
45 }
46
47 private:
48 gfx::Size device_viewport_size_;
49 LayerTreeSettings settings_;
50 };
51
52 PixelTest::PixelTest() : device_viewport_size_(gfx::Size(200, 200)) {}
53
54 PixelTest::~PixelTest() {}
55
56 void PixelTest::SetUp() {
57 gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL);
58 scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl>
59 context3d(
60 new webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl);
61 context3d->Initialize(WebKit::WebGraphicsContext3D::Attributes(), NULL);
62 output_surface_.reset(new OutputSurface(
63 context3d.PassAs<WebKit::WebGraphicsContext3D>()));
64 resource_provider_ = ResourceProvider::Create(output_surface_.get());
65 fake_client_ =
66 make_scoped_ptr(new PixelTestRendererClient(device_viewport_size_));
67 renderer_ = GLRenderer::Create(fake_client_.get(),
68 output_surface_.get(),
69 resource_provider_.get());
70
71 scoped_refptr<cc::ContextProvider> offscreen_contexts =
72 new webkit::gpu::ContextProviderInProcess(
73 webkit::gpu::ContextProviderInProcess::IN_PROCESS_COMMAND_BUFFER);
74 ASSERT_TRUE(offscreen_contexts->InitializeOnMainThread());
75 resource_provider_->SetOffscreenContextProvider(offscreen_contexts);
76 }
77
78 bool PixelTest::PixelsMatchReference(const base::FilePath& ref_file) {
79 gfx::Rect device_viewport_rect(device_viewport_size_);
80
81 SkBitmap bitmap;
82 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
83 device_viewport_rect.width(),
84 device_viewport_rect.height());
85 bitmap.allocPixels();
86 unsigned char* pixels = static_cast<unsigned char*>(bitmap.getPixels());
87 renderer_->GetFramebufferPixels(pixels, device_viewport_rect);
88
89 base::FilePath test_data_dir;
90 if (!PathService::Get(cc::DIR_TEST_DATA, &test_data_dir))
91 return false;
92
93 // To rebaseline:
94 //return WritePNGFile(bitmap, test_data_dir.Append(ref_file));
95
96 return IsSameAsPNGFile(bitmap, test_data_dir.Append(ref_file));
97 }
98
99 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/pixel_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698