| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/skia/include/core/SkColor.h" | 10 #include "third_party/skia/include/core/SkColor.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 256 |
| 257 TEST_F(DriSurfaceFactoryTest, FailSurfaceInitialization) { | 257 TEST_F(DriSurfaceFactoryTest, FailSurfaceInitialization) { |
| 258 factory_->set_initialize_controller_expectation(false); | 258 factory_->set_initialize_controller_expectation(false); |
| 259 | 259 |
| 260 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, | 260 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, |
| 261 factory_->InitializeHardware()); | 261 factory_->InitializeHardware()); |
| 262 | 262 |
| 263 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); | 263 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); |
| 264 EXPECT_EQ(kDefaultWidgetHandle, w); | 264 EXPECT_EQ(kDefaultWidgetHandle, w); |
| 265 | 265 |
| 266 EXPECT_EQ(gfx::kNullAcceleratedWidget, factory_->RealizeAcceleratedWidget(w)); | 266 EXPECT_FALSE(factory_->CreateSurfaceForWidget(w)); |
| 267 } | 267 } |
| 268 | 268 |
| 269 TEST_F(DriSurfaceFactoryTest, FailBindingSurfaceToController) { | 269 TEST_F(DriSurfaceFactoryTest, FailBindingSurfaceToController) { |
| 270 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, | 270 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, |
| 271 factory_->InitializeHardware()); | 271 factory_->InitializeHardware()); |
| 272 | 272 |
| 273 factory_->get_drm()->set_add_framebuffer_expectation(false); | 273 factory_->get_drm()->set_add_framebuffer_expectation(false); |
| 274 | 274 |
| 275 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); | 275 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); |
| 276 EXPECT_EQ(kDefaultWidgetHandle, w); | 276 EXPECT_EQ(kDefaultWidgetHandle, w); |
| 277 | 277 |
| 278 EXPECT_EQ(gfx::kNullAcceleratedWidget, factory_->RealizeAcceleratedWidget(w)); | 278 EXPECT_FALSE(factory_->CreateSurfaceForWidget(w)); |
| 279 } | 279 } |
| 280 | 280 |
| 281 TEST_F(DriSurfaceFactoryTest, SuccessfulWidgetRealization) { | 281 TEST_F(DriSurfaceFactoryTest, SuccessfulWidgetRealization) { |
| 282 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, | 282 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, |
| 283 factory_->InitializeHardware()); | 283 factory_->InitializeHardware()); |
| 284 | 284 |
| 285 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); | 285 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); |
| 286 EXPECT_EQ(kDefaultWidgetHandle, w); | 286 EXPECT_EQ(kDefaultWidgetHandle, w); |
| 287 | 287 |
| 288 EXPECT_NE(gfx::kNullAcceleratedWidget, factory_->RealizeAcceleratedWidget(w)); | 288 EXPECT_TRUE(factory_->CreateSurfaceForWidget(w)); |
| 289 } | 289 } |
| 290 | 290 |
| 291 TEST_F(DriSurfaceFactoryTest, FailSchedulePageFlip) { | 291 TEST_F(DriSurfaceFactoryTest, FailSchedulePageFlip) { |
| 292 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, | 292 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, |
| 293 factory_->InitializeHardware()); | 293 factory_->InitializeHardware()); |
| 294 | 294 |
| 295 factory_->get_drm()->set_page_flip_expectation(false); | 295 factory_->get_drm()->set_page_flip_expectation(false); |
| 296 | 296 |
| 297 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); | 297 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); |
| 298 EXPECT_EQ(kDefaultWidgetHandle, w); | 298 EXPECT_EQ(kDefaultWidgetHandle, w); |
| 299 | 299 |
| 300 EXPECT_NE(gfx::kNullAcceleratedWidget, factory_->RealizeAcceleratedWidget(w)); | 300 scoped_ptr<gfx::SurfaceOzone> surf = factory_->CreateSurfaceForWidget(w); |
| 301 EXPECT_TRUE(surf); |
| 301 | 302 |
| 302 EXPECT_FALSE(factory_->SchedulePageFlip(w)); | 303 EXPECT_FALSE(factory_->SchedulePageFlip(w)); |
| 303 } | 304 } |
| 304 | 305 |
| 305 TEST_F(DriSurfaceFactoryTest, SuccessfulSchedulePageFlip) { | 306 TEST_F(DriSurfaceFactoryTest, SuccessfulSchedulePageFlip) { |
| 306 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, | 307 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, |
| 307 factory_->InitializeHardware()); | 308 factory_->InitializeHardware()); |
| 308 | 309 |
| 309 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); | 310 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); |
| 310 EXPECT_EQ(kDefaultWidgetHandle, w); | 311 EXPECT_EQ(kDefaultWidgetHandle, w); |
| 311 | 312 |
| 312 EXPECT_NE(gfx::kNullAcceleratedWidget, factory_->RealizeAcceleratedWidget(w)); | 313 scoped_ptr<gfx::SurfaceOzone> surf = factory_->CreateSurfaceForWidget(w); |
| 314 EXPECT_TRUE(surf); |
| 313 | 315 |
| 314 EXPECT_TRUE(factory_->SchedulePageFlip(w)); | 316 EXPECT_TRUE(factory_->SchedulePageFlip(w)); |
| 315 } | 317 } |
| 316 | 318 |
| 317 TEST_F(DriSurfaceFactoryTest, SetCursorImage) { | 319 TEST_F(DriSurfaceFactoryTest, SetCursorImage) { |
| 318 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, | 320 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, |
| 319 factory_->InitializeHardware()); | 321 factory_->InitializeHardware()); |
| 320 | 322 |
| 321 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); | 323 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); |
| 322 EXPECT_EQ(kDefaultWidgetHandle, w); | 324 EXPECT_EQ(kDefaultWidgetHandle, w); |
| 323 EXPECT_NE(gfx::kNullAcceleratedWidget, factory_->RealizeAcceleratedWidget(w)); | 325 |
| 326 scoped_ptr<gfx::SurfaceOzone> surf = factory_->CreateSurfaceForWidget(w); |
| 327 EXPECT_TRUE(surf); |
| 324 | 328 |
| 325 SkBitmap image; | 329 SkBitmap image; |
| 326 SkImageInfo info = SkImageInfo::Make( | 330 SkImageInfo info = SkImageInfo::Make( |
| 327 6, 4, kPMColor_SkColorType, kPremul_SkAlphaType); | 331 6, 4, kPMColor_SkColorType, kPremul_SkAlphaType); |
| 328 image.allocPixels(info); | 332 image.allocPixels(info); |
| 329 image.eraseColor(SK_ColorWHITE); | 333 image.eraseColor(SK_ColorWHITE); |
| 330 | 334 |
| 331 factory_->SetHardwareCursor(w, image, gfx::Point(4, 2)); | 335 factory_->SetHardwareCursor(w, image, gfx::Point(4, 2)); |
| 332 const std::vector<MockDriSurface*>& surfaces = factory_->get_surfaces(); | 336 const std::vector<MockDriSurface*>& surfaces = factory_->get_surfaces(); |
| 333 | 337 |
| 334 // The first surface is the cursor surface since it is allocated early in the | 338 // The first surface is the cursor surface since it is allocated early in the |
| 335 // initialization process. | 339 // initialization process. |
| 336 const std::vector<MockDriSkBitmap*>& bitmaps = surfaces[0]->bitmaps(); | 340 const std::vector<MockDriSkBitmap*>& bitmaps = surfaces[0]->bitmaps(); |
| 337 | 341 |
| 338 // The surface should have been initialized to a double-buffered surface. | 342 // The surface should have been initialized to a double-buffered surface. |
| 339 EXPECT_EQ(2u, bitmaps.size()); | 343 EXPECT_EQ(2u, bitmaps.size()); |
| 340 // Check that the frontbuffer is displaying the right image as set above. | 344 // Check that the frontbuffer is displaying the right image as set above. |
| 341 for (int i = 0; i < bitmaps[1]->height(); ++i) { | 345 for (int i = 0; i < bitmaps[1]->height(); ++i) { |
| 342 for (int j = 0; j < bitmaps[1]->width(); ++j) { | 346 for (int j = 0; j < bitmaps[1]->width(); ++j) { |
| 343 if (j < info.width() && i < info.height()) | 347 if (j < info.width() && i < info.height()) |
| 344 EXPECT_EQ(SK_ColorWHITE, bitmaps[1]->getColor(j, i)); | 348 EXPECT_EQ(SK_ColorWHITE, bitmaps[1]->getColor(j, i)); |
| 345 else | 349 else |
| 346 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), | 350 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), |
| 347 bitmaps[1]->getColor(j, i)); | 351 bitmaps[1]->getColor(j, i)); |
| 348 } | 352 } |
| 349 } | 353 } |
| 350 } | 354 } |
| OLD | NEW |