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

Side by Side Diff: ui/gfx/ozone/impl/software_surface_ozone_unittest.cc

Issue 26179005: [Ozone] SoftwareSurfaceOzone unittests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 | « no previous file | 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 (c) 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 "testing/gtest/include/gtest/gtest.h"
6 #include "third_party/skia/include/core/SkCanvas.h"
7 #include "third_party/skia/include/core/SkColor.h"
8 #include "third_party/skia/include/core/SkDevice.h"
9 #include "ui/gfx/ozone/impl/drm_skbitmap_ozone.h"
10 #include "ui/gfx/ozone/impl/hardware_display_controller_ozone.h"
11 #include "ui/gfx/ozone/impl/software_surface_ozone.h"
12
13 namespace {
14
15 // Create a basic mode for a 6x4 screen.
16 const drmModeModeInfo kDefaultMode =
17 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}};
18
19 // Mock file descriptor ID.
20 const int kFd = 3;
21
22 // Mock connector ID.
23 const uint32_t kConnectorId = 1;
24
25 // Mock CRTC ID.
26 const uint32_t kCrtcId = 1;
27
28 class MockDrmWrapperOzone : public gfx::DrmWrapperOzone {
29 public:
30 MockDrmWrapperOzone() : DrmWrapperOzone(""), id_(1) { fd_ = kFd; }
31 virtual ~MockDrmWrapperOzone() { fd_ = -1; }
32
33 virtual drmModeCrtc* GetCrtc(uint32_t crtc_id) OVERRIDE { return NULL; }
34 virtual void FreeCrtc(drmModeCrtc* crtc) OVERRIDE {}
35 virtual bool SetCrtc(uint32_t crtc_id,
36 uint32_t framebuffer,
37 uint32_t* connectors,
38 drmModeModeInfo* mode) OVERRIDE { return true; }
39 virtual bool SetCrtc(drmModeCrtc* crtc, uint32_t* connectors) OVERRIDE {
40 return true;
41 }
42 virtual bool AddFramebuffer(const drmModeModeInfo& mode,
43 uint8_t depth,
44 uint8_t bpp,
45 uint32_t stride,
46 uint32_t handle,
47 uint32_t* framebuffer) OVERRIDE {
48 *framebuffer = id_++;
49 return true;
50 }
51 virtual bool RemoveFramebuffer(uint32_t framebuffer) OVERRIDE { return true; }
52 virtual bool PageFlip(uint32_t crtc_id,
53 uint32_t framebuffer,
54 void* data) OVERRIDE {
55 return true;
56 }
57
58 private:
59 int id_;
60 DISALLOW_COPY_AND_ASSIGN(MockDrmWrapperOzone);
61 };
62
63 class MockDrmSkBitmapOzone : public gfx::DrmSkBitmapOzone {
64 public:
65 MockDrmSkBitmapOzone(int fd,
66 bool initialize_expectation)
67 : DrmSkBitmapOzone(fd),
68 initialize_expectation_(initialize_expectation) {}
69 virtual ~MockDrmSkBitmapOzone() {}
70
71 virtual bool Initialize() OVERRIDE {
72 if (!initialize_expectation_)
73 return false;
74
75 allocPixels();
76 // Clear the bitmap to black.
77 eraseColor(SK_ColorBLACK);
78
79 return true;
80 }
81 private:
82 bool initialize_expectation_;
83
84 DISALLOW_COPY_AND_ASSIGN(MockDrmSkBitmapOzone);
85 };
86
87 class MockSoftwareSurfaceOzone : public gfx::SoftwareSurfaceOzone {
88 public:
89 MockSoftwareSurfaceOzone(gfx::HardwareDisplayControllerOzone* controller)
90 : SoftwareSurfaceOzone(controller),
91 initialize_expectation_(true) {}
92 virtual ~MockSoftwareSurfaceOzone() {}
93
94 void set_initialize_expectation(bool state) {
95 initialize_expectation_ = state;
96 }
97
98 private:
99 virtual gfx::DrmSkBitmapOzone* CreateBuffer() OVERRIDE {
100 return new MockDrmSkBitmapOzone(kFd, initialize_expectation_);
101 }
102
103 bool initialize_expectation_;
104
105 DISALLOW_COPY_AND_ASSIGN(MockSoftwareSurfaceOzone);
106 };
107
108 } // namespace
109
110 class SoftwareSurfaceOzoneTest : public testing::Test {
111 public:
112 SoftwareSurfaceOzoneTest() {}
113
114 virtual void SetUp() OVERRIDE;
115 virtual void TearDown() OVERRIDE;
116
117 protected:
118 scoped_ptr<MockDrmWrapperOzone> drm_;
119 scoped_ptr<gfx::HardwareDisplayControllerOzone> controller_;
120 scoped_ptr<MockSoftwareSurfaceOzone> surface_;
121
122 private:
123 DISALLOW_COPY_AND_ASSIGN(SoftwareSurfaceOzoneTest);
124 };
125
126 void SoftwareSurfaceOzoneTest::SetUp() {
127 drm_.reset(new MockDrmWrapperOzone());
128 controller_.reset(new gfx::HardwareDisplayControllerOzone());
129 controller_->SetControllerInfo(
130 drm_.get(), kConnectorId, kCrtcId, kDefaultMode);
131
132 surface_.reset(new MockSoftwareSurfaceOzone(controller_.get()));
133 }
134
135 void SoftwareSurfaceOzoneTest::TearDown() {
136 surface_.reset();
137 controller_.reset();
138 drm_.reset();
139 }
140
141 TEST_F(SoftwareSurfaceOzoneTest, FailInitialization) {
142 surface_->set_initialize_expectation(false);
143 EXPECT_FALSE(surface_->Initialize());
144 }
145
146 TEST_F(SoftwareSurfaceOzoneTest, SuccessfulInitialization) {
147 EXPECT_TRUE(surface_->Initialize());
148 }
149
150 TEST_F(SoftwareSurfaceOzoneTest, CheckFBIDOnSwap) {
151 EXPECT_TRUE(surface_->Initialize());
152 controller_->BindSurfaceToController(surface_.release());
153
154 // Check that the framebuffer ID is correct.
155 EXPECT_EQ(2u, controller_->get_surface()->GetFramebufferId());
156
157 controller_->get_surface()->SwapBuffers();
158
159 EXPECT_EQ(1u, controller_->get_surface()->GetFramebufferId());
160 }
161
162 TEST_F(SoftwareSurfaceOzoneTest, CheckPixelPointerOnSwap) {
163 EXPECT_TRUE(surface_->Initialize());
164
165 void* bitmap_pixels1 = surface_->GetDrawableForWidget()->getDevice()
166 ->accessBitmap(false).getPixels();
167
168 surface_->SwapBuffers();
169
170 void* bitmap_pixels2 = surface_->GetDrawableForWidget()->getDevice()
171 ->accessBitmap(false).getPixels();
172
173 // Check that once the buffers have been swapped the drawable's underlying
174 // pixels have been changed.
175 EXPECT_NE(bitmap_pixels1, bitmap_pixels2);
176 }
177
178 TEST_F(SoftwareSurfaceOzoneTest, CheckCorrectBufferSync) {
179 EXPECT_TRUE(surface_->Initialize());
180
181 SkCanvas* canvas = surface_->GetDrawableForWidget();
182 SkRect clip;
183 // Modify part of the canvas.
184 clip.set(0, 0,
185 canvas->getDeviceSize().width() / 2,
186 canvas->getDeviceSize().height() / 2);
187 canvas->clipRect(clip, SkRegion::kReplace_Op);
188
189 canvas->drawColor(SK_ColorWHITE);
190
191 surface_->SwapBuffers();
192
193 // Verify that the modified contents have been copied over on swap (make sure
194 // the 2 buffers have the same content).
195 for (int i = 0; i < canvas->getDeviceSize().height(); ++i) {
196 for (int j = 0; j < canvas->getDeviceSize().width(); ++j) {
197 if (i < clip.height() && j < clip.width())
198 EXPECT_EQ(SK_ColorWHITE,
199 canvas->getDevice()->accessBitmap(false).getColor(j, i));
200 else
201 EXPECT_EQ(SK_ColorBLACK,
202 canvas->getDevice()->accessBitmap(false).getColor(j, i));
203 }
204 }
205 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698