OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "third_party/skia/include/core/SkCanvas.h" | 6 #include "third_party/skia/include/core/SkCanvas.h" |
7 #include "third_party/skia/include/core/SkColor.h" | 7 #include "third_party/skia/include/core/SkColor.h" |
8 #include "third_party/skia/include/core/SkDevice.h" | 8 #include "third_party/skia/include/core/SkDevice.h" |
9 #include "ui/gfx/ozone/impl/drm_skbitmap_ozone.h" | 9 #include "ui/gfx/ozone/impl/dri_skbitmap.h" |
10 #include "ui/gfx/ozone/impl/hardware_display_controller_ozone.h" | 10 #include "ui/gfx/ozone/impl/dri_surface.h" |
11 #include "ui/gfx/ozone/impl/software_surface_ozone.h" | 11 #include "ui/gfx/ozone/impl/hardware_display_controller.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Create a basic mode for a 6x4 screen. | 15 // Create a basic mode for a 6x4 screen. |
16 const drmModeModeInfo kDefaultMode = | 16 const drmModeModeInfo kDefaultMode = |
17 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; | 17 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; |
18 | 18 |
19 // Mock file descriptor ID. | 19 // Mock file descriptor ID. |
20 const int kFd = 3; | 20 const int kFd = 3; |
21 | 21 |
22 // Mock connector ID. | 22 // Mock connector ID. |
23 const uint32_t kConnectorId = 1; | 23 const uint32_t kConnectorId = 1; |
24 | 24 |
25 // Mock CRTC ID. | 25 // Mock CRTC ID. |
26 const uint32_t kCrtcId = 1; | 26 const uint32_t kCrtcId = 1; |
27 | 27 |
28 // Mock DPMS property ID. | 28 // Mock DPMS property ID. |
29 const uint32_t kDPMSPropertyId = 1; | 29 const uint32_t kDPMSPropertyId = 1; |
30 | 30 |
31 class MockDrmWrapperOzone : public gfx::DrmWrapperOzone { | 31 class MockDriWrapper : public gfx::DriWrapper { |
32 public: | 32 public: |
33 MockDrmWrapperOzone() : DrmWrapperOzone(""), id_(1) { fd_ = kFd; } | 33 MockDriWrapper() : DriWrapper(""), id_(1) { fd_ = kFd; } |
34 virtual ~MockDrmWrapperOzone() { fd_ = -1; } | 34 virtual ~MockDriWrapper() { fd_ = -1; } |
35 | 35 |
36 virtual drmModeCrtc* GetCrtc(uint32_t crtc_id) OVERRIDE { return NULL; } | 36 virtual drmModeCrtc* GetCrtc(uint32_t crtc_id) OVERRIDE { return NULL; } |
37 virtual void FreeCrtc(drmModeCrtc* crtc) OVERRIDE {} | 37 virtual void FreeCrtc(drmModeCrtc* crtc) OVERRIDE {} |
38 virtual bool SetCrtc(uint32_t crtc_id, | 38 virtual bool SetCrtc(uint32_t crtc_id, |
39 uint32_t framebuffer, | 39 uint32_t framebuffer, |
40 uint32_t* connectors, | 40 uint32_t* connectors, |
41 drmModeModeInfo* mode) OVERRIDE { return true; } | 41 drmModeModeInfo* mode) OVERRIDE { return true; } |
42 virtual bool SetCrtc(drmModeCrtc* crtc, uint32_t* connectors) OVERRIDE { | 42 virtual bool SetCrtc(drmModeCrtc* crtc, uint32_t* connectors) OVERRIDE { |
43 return true; | 43 return true; |
44 } | 44 } |
(...skipping 11 matching lines...) Expand all Loading... |
56 uint32_t framebuffer, | 56 uint32_t framebuffer, |
57 void* data) OVERRIDE { | 57 void* data) OVERRIDE { |
58 return true; | 58 return true; |
59 } | 59 } |
60 virtual bool ConnectorSetProperty(uint32_t connector_id, | 60 virtual bool ConnectorSetProperty(uint32_t connector_id, |
61 uint32_t property_id, | 61 uint32_t property_id, |
62 uint64_t value) OVERRIDE { return true; } | 62 uint64_t value) OVERRIDE { return true; } |
63 | 63 |
64 private: | 64 private: |
65 int id_; | 65 int id_; |
66 DISALLOW_COPY_AND_ASSIGN(MockDrmWrapperOzone); | 66 DISALLOW_COPY_AND_ASSIGN(MockDriWrapper); |
67 }; | 67 }; |
68 | 68 |
69 class MockDrmSkBitmapOzone : public gfx::DrmSkBitmapOzone { | 69 class MockDriSkBitmap : public gfx::DriSkBitmap { |
70 public: | 70 public: |
71 MockDrmSkBitmapOzone(int fd, | 71 MockDriSkBitmap(int fd, |
72 bool initialize_expectation) | 72 bool initialize_expectation) |
73 : DrmSkBitmapOzone(fd), | 73 : DriSkBitmap(fd), |
74 initialize_expectation_(initialize_expectation) {} | 74 initialize_expectation_(initialize_expectation) {} |
75 virtual ~MockDrmSkBitmapOzone() {} | 75 virtual ~MockDriSkBitmap() {} |
76 | 76 |
77 virtual bool Initialize() OVERRIDE { | 77 virtual bool Initialize() OVERRIDE { |
78 if (!initialize_expectation_) | 78 if (!initialize_expectation_) |
79 return false; | 79 return false; |
80 | 80 |
81 allocPixels(); | 81 allocPixels(); |
82 // Clear the bitmap to black. | 82 // Clear the bitmap to black. |
83 eraseColor(SK_ColorBLACK); | 83 eraseColor(SK_ColorBLACK); |
84 | 84 |
85 return true; | 85 return true; |
86 } | 86 } |
87 private: | 87 private: |
88 bool initialize_expectation_; | 88 bool initialize_expectation_; |
89 | 89 |
90 DISALLOW_COPY_AND_ASSIGN(MockDrmSkBitmapOzone); | 90 DISALLOW_COPY_AND_ASSIGN(MockDriSkBitmap); |
91 }; | 91 }; |
92 | 92 |
93 class MockSoftwareSurfaceOzone : public gfx::SoftwareSurfaceOzone { | 93 class MockDriSurface : public gfx::DriSurface { |
94 public: | 94 public: |
95 MockSoftwareSurfaceOzone(gfx::HardwareDisplayControllerOzone* controller) | 95 MockDriSurface(gfx::HardwareDisplayController* controller) |
96 : SoftwareSurfaceOzone(controller), | 96 : DriSurface(controller), |
97 initialize_expectation_(true) {} | 97 initialize_expectation_(true) {} |
98 virtual ~MockSoftwareSurfaceOzone() {} | 98 virtual ~MockDriSurface() {} |
99 | 99 |
100 void set_initialize_expectation(bool state) { | 100 void set_initialize_expectation(bool state) { |
101 initialize_expectation_ = state; | 101 initialize_expectation_ = state; |
102 } | 102 } |
103 | 103 |
104 private: | 104 private: |
105 virtual gfx::DrmSkBitmapOzone* CreateBuffer() OVERRIDE { | 105 virtual gfx::DriSkBitmap* CreateBuffer() OVERRIDE { |
106 return new MockDrmSkBitmapOzone(kFd, initialize_expectation_); | 106 return new MockDriSkBitmap(kFd, initialize_expectation_); |
107 } | 107 } |
108 | 108 |
109 bool initialize_expectation_; | 109 bool initialize_expectation_; |
110 | 110 |
111 DISALLOW_COPY_AND_ASSIGN(MockSoftwareSurfaceOzone); | 111 DISALLOW_COPY_AND_ASSIGN(MockDriSurface); |
112 }; | 112 }; |
113 | 113 |
114 } // namespace | 114 } // namespace |
115 | 115 |
116 class SoftwareSurfaceOzoneTest : public testing::Test { | 116 class DriSurfaceTest : public testing::Test { |
117 public: | 117 public: |
118 SoftwareSurfaceOzoneTest() {} | 118 DriSurfaceTest() {} |
119 | 119 |
120 virtual void SetUp() OVERRIDE; | 120 virtual void SetUp() OVERRIDE; |
121 virtual void TearDown() OVERRIDE; | 121 virtual void TearDown() OVERRIDE; |
122 | 122 |
123 protected: | 123 protected: |
124 scoped_ptr<MockDrmWrapperOzone> drm_; | 124 scoped_ptr<MockDriWrapper> drm_; |
125 scoped_ptr<gfx::HardwareDisplayControllerOzone> controller_; | 125 scoped_ptr<gfx::HardwareDisplayController> controller_; |
126 scoped_ptr<MockSoftwareSurfaceOzone> surface_; | 126 scoped_ptr<MockDriSurface> surface_; |
127 | 127 |
128 private: | 128 private: |
129 DISALLOW_COPY_AND_ASSIGN(SoftwareSurfaceOzoneTest); | 129 DISALLOW_COPY_AND_ASSIGN(DriSurfaceTest); |
130 }; | 130 }; |
131 | 131 |
132 void SoftwareSurfaceOzoneTest::SetUp() { | 132 void DriSurfaceTest::SetUp() { |
133 drm_.reset(new MockDrmWrapperOzone()); | 133 drm_.reset(new MockDriWrapper()); |
134 controller_.reset(new gfx::HardwareDisplayControllerOzone()); | 134 controller_.reset(new gfx::HardwareDisplayController()); |
135 controller_->SetControllerInfo( | 135 controller_->SetControllerInfo( |
136 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); | 136 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); |
137 | 137 |
138 surface_.reset(new MockSoftwareSurfaceOzone(controller_.get())); | 138 surface_.reset(new MockDriSurface(controller_.get())); |
139 } | 139 } |
140 | 140 |
141 void SoftwareSurfaceOzoneTest::TearDown() { | 141 void DriSurfaceTest::TearDown() { |
142 surface_.reset(); | 142 surface_.reset(); |
143 controller_.reset(); | 143 controller_.reset(); |
144 drm_.reset(); | 144 drm_.reset(); |
145 } | 145 } |
146 | 146 |
147 TEST_F(SoftwareSurfaceOzoneTest, FailInitialization) { | 147 TEST_F(DriSurfaceTest, FailInitialization) { |
148 surface_->set_initialize_expectation(false); | 148 surface_->set_initialize_expectation(false); |
149 EXPECT_FALSE(surface_->Initialize()); | 149 EXPECT_FALSE(surface_->Initialize()); |
150 } | 150 } |
151 | 151 |
152 TEST_F(SoftwareSurfaceOzoneTest, SuccessfulInitialization) { | 152 TEST_F(DriSurfaceTest, SuccessfulInitialization) { |
153 EXPECT_TRUE(surface_->Initialize()); | 153 EXPECT_TRUE(surface_->Initialize()); |
154 } | 154 } |
155 | 155 |
156 TEST_F(SoftwareSurfaceOzoneTest, CheckFBIDOnSwap) { | 156 TEST_F(DriSurfaceTest, CheckFBIDOnSwap) { |
157 EXPECT_TRUE(surface_->Initialize()); | 157 EXPECT_TRUE(surface_->Initialize()); |
158 controller_->BindSurfaceToController( | 158 controller_->BindSurfaceToController( |
159 surface_.PassAs<gfx::SoftwareSurfaceOzone>()); | 159 surface_.PassAs<gfx::DriSurface>()); |
160 | 160 |
161 // Check that the framebuffer ID is correct. | 161 // Check that the framebuffer ID is correct. |
162 EXPECT_EQ(2u, controller_->get_surface()->GetFramebufferId()); | 162 EXPECT_EQ(2u, controller_->get_surface()->GetFramebufferId()); |
163 | 163 |
164 controller_->get_surface()->SwapBuffers(); | 164 controller_->get_surface()->SwapBuffers(); |
165 | 165 |
166 EXPECT_EQ(1u, controller_->get_surface()->GetFramebufferId()); | 166 EXPECT_EQ(1u, controller_->get_surface()->GetFramebufferId()); |
167 } | 167 } |
168 | 168 |
169 TEST_F(SoftwareSurfaceOzoneTest, CheckPixelPointerOnSwap) { | 169 TEST_F(DriSurfaceTest, CheckPixelPointerOnSwap) { |
170 EXPECT_TRUE(surface_->Initialize()); | 170 EXPECT_TRUE(surface_->Initialize()); |
171 | 171 |
172 void* bitmap_pixels1 = surface_->GetDrawableForWidget()->getDevice() | 172 void* bitmap_pixels1 = surface_->GetDrawableForWidget()->getDevice() |
173 ->accessBitmap(false).getPixels(); | 173 ->accessBitmap(false).getPixels(); |
174 | 174 |
175 surface_->SwapBuffers(); | 175 surface_->SwapBuffers(); |
176 | 176 |
177 void* bitmap_pixels2 = surface_->GetDrawableForWidget()->getDevice() | 177 void* bitmap_pixels2 = surface_->GetDrawableForWidget()->getDevice() |
178 ->accessBitmap(false).getPixels(); | 178 ->accessBitmap(false).getPixels(); |
179 | 179 |
180 // Check that once the buffers have been swapped the drawable's underlying | 180 // Check that once the buffers have been swapped the drawable's underlying |
181 // pixels have been changed. | 181 // pixels have been changed. |
182 EXPECT_NE(bitmap_pixels1, bitmap_pixels2); | 182 EXPECT_NE(bitmap_pixels1, bitmap_pixels2); |
183 } | 183 } |
184 | 184 |
185 TEST_F(SoftwareSurfaceOzoneTest, CheckCorrectBufferSync) { | 185 TEST_F(DriSurfaceTest, CheckCorrectBufferSync) { |
186 EXPECT_TRUE(surface_->Initialize()); | 186 EXPECT_TRUE(surface_->Initialize()); |
187 | 187 |
188 SkCanvas* canvas = surface_->GetDrawableForWidget(); | 188 SkCanvas* canvas = surface_->GetDrawableForWidget(); |
189 SkRect clip; | 189 SkRect clip; |
190 // Modify part of the canvas. | 190 // Modify part of the canvas. |
191 clip.set(0, 0, | 191 clip.set(0, 0, |
192 canvas->getDeviceSize().width() / 2, | 192 canvas->getDeviceSize().width() / 2, |
193 canvas->getDeviceSize().height() / 2); | 193 canvas->getDeviceSize().height() / 2); |
194 canvas->clipRect(clip, SkRegion::kReplace_Op); | 194 canvas->clipRect(clip, SkRegion::kReplace_Op); |
195 | 195 |
196 canvas->drawColor(SK_ColorWHITE); | 196 canvas->drawColor(SK_ColorWHITE); |
197 | 197 |
198 surface_->SwapBuffers(); | 198 surface_->SwapBuffers(); |
199 | 199 |
200 // Verify that the modified contents have been copied over on swap (make sure | 200 // Verify that the modified contents have been copied over on swap (make sure |
201 // the 2 buffers have the same content). | 201 // the 2 buffers have the same content). |
202 for (int i = 0; i < canvas->getDeviceSize().height(); ++i) { | 202 for (int i = 0; i < canvas->getDeviceSize().height(); ++i) { |
203 for (int j = 0; j < canvas->getDeviceSize().width(); ++j) { | 203 for (int j = 0; j < canvas->getDeviceSize().width(); ++j) { |
204 if (i < clip.height() && j < clip.width()) | 204 if (i < clip.height() && j < clip.width()) |
205 EXPECT_EQ(SK_ColorWHITE, | 205 EXPECT_EQ(SK_ColorWHITE, |
206 canvas->getDevice()->accessBitmap(false).getColor(j, i)); | 206 canvas->getDevice()->accessBitmap(false).getColor(j, i)); |
207 else | 207 else |
208 EXPECT_EQ(SK_ColorBLACK, | 208 EXPECT_EQ(SK_ColorBLACK, |
209 canvas->getDevice()->accessBitmap(false).getColor(j, i)); | 209 canvas->getDevice()->accessBitmap(false).getColor(j, i)); |
210 } | 210 } |
211 } | 211 } |
212 } | 212 } |
OLD | NEW |