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

Side by Side Diff: cc/test/layer_tree_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/layer_tree_pixel_test.h ('k') | cc/test/layer_tree_test_common.h » ('j') | 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/layer_tree_pixel_test.h"
6
7 #include "base/path_service.h"
8 #include "cc/layer_tree_impl.h"
9 #include "cc/test/paths.h"
10 #include "cc/test/pixel_test_utils.h"
11 #include "ui/gl/gl_implementation.h"
12 #include "webkit/gpu/context_provider_in_process.h"
13 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
14
15 namespace cc {
16
17 LayerTreePixelTest::LayerTreePixelTest() {}
18
19 LayerTreePixelTest::~LayerTreePixelTest() {}
20
21 scoped_ptr<OutputSurface> LayerTreePixelTest::createOutputSurface() {
22 CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL));
23
24 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
25 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d(
26 new WebGraphicsContext3DInProcessCommandBufferImpl);
27 context3d->Initialize(WebKit::WebGraphicsContext3D::Attributes(), NULL);
28 return make_scoped_ptr(
29 new OutputSurface(context3d.PassAs<WebKit::WebGraphicsContext3D>()));
30 }
31
32 scoped_refptr<cc::ContextProvider>
33 LayerTreePixelTest::OffscreenContextProviderForMainThread() {
34 return new webkit::gpu::ContextProviderInProcess(
35 webkit::gpu::ContextProviderInProcess::IN_PROCESS_COMMAND_BUFFER);
36 }
37
38 scoped_refptr<cc::ContextProvider>
39 LayerTreePixelTest::OffscreenContextProviderForCompositorThread() {
40 return new webkit::gpu::ContextProviderInProcess(
41 webkit::gpu::ContextProviderInProcess::IN_PROCESS_COMMAND_BUFFER);
42 }
43
44 void LayerTreePixelTest::swapBuffersOnThread(LayerTreeHostImpl* host_impl,
45 bool result) {
46 EXPECT_TRUE(result);
47
48 gfx::Rect device_viewport_rect(
49 host_impl->active_tree()->device_viewport_size());
50
51 SkBitmap bitmap;
52 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
53 device_viewport_rect.width(),
54 device_viewport_rect.height());
55 bitmap.allocPixels();
56 unsigned char* pixels = static_cast<unsigned char*>(bitmap.getPixels());
57 host_impl->Readback(pixels, device_viewport_rect);
58
59 base::FilePath test_data_dir;
60 EXPECT_TRUE(PathService::Get(cc::DIR_TEST_DATA, &test_data_dir));
61
62 // To rebaseline:
63 //EXPECT_TRUE(WritePNGFile(bitmap, test_data_dir.Append(ref_file_)));
64
65 EXPECT_TRUE(IsSameAsPNGFile(bitmap, test_data_dir.Append(ref_file_)));
66
67 endTest();
68 }
69
70 void LayerTreePixelTest::beginTest() {
71 postSetNeedsCommitToMainThread();
72 }
73
74 void LayerTreePixelTest::afterTest() {}
75
76 scoped_refptr<SolidColorLayer> LayerTreePixelTest::CreateSolidColorLayer(
77 gfx::Rect rect, SkColor color) {
78 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::Create();
79 layer->SetIsDrawable(true);
80 layer->SetAnchorPoint(gfx::PointF());
81 layer->SetBounds(rect.size());
82 layer->SetPosition(rect.origin());
83 layer->SetBackgroundColor(color);
84 return layer;
85 }
86
87 void LayerTreePixelTest::RunPixelTest(
88 scoped_refptr<Layer> content_root,
89 base::FilePath file_name)
90 {
91 content_root_ = content_root;
92 ref_file_ = file_name;
93 runTest(true);
94 }
95
96 void LayerTreePixelTest::setupTree() {
97 scoped_refptr<Layer> root = Layer::Create();
98 root->SetBounds(content_root_->bounds());
99 root->AddChild(content_root_);
100 m_layerTreeHost->SetRootLayer(root);
101 ThreadedTest::setupTree();
102 }
103
104 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/layer_tree_pixel_test.h ('k') | cc/test/layer_tree_test_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698