Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ozone/platform/dri/dri_buffer.h" | 9 #include "ui/ozone/platform/dri/dri_buffer.h" |
| 10 #include "ui/ozone/platform/dri/dri_surface.h" | 10 #include "ui/ozone/platform/dri/dri_surface.h" |
| 11 #include "ui/ozone/platform/dri/hardware_display_controller.h" | 11 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
| 12 #include "ui/ozone/platform/dri/test/mock_dri_surface.h" | |
| 13 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h" | 12 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h" |
| 14 | 13 |
| 15 namespace { | 14 namespace { |
| 16 | 15 |
| 17 // Create a basic mode for a 6x4 screen. | 16 // Create a basic mode for a 6x4 screen. |
| 18 const drmModeModeInfo kDefaultMode = | 17 const drmModeModeInfo kDefaultMode = |
| 19 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; | 18 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; |
| 20 | 19 |
| 21 } // namespace | 20 } // namespace |
| 22 | 21 |
| 23 class DriSurfaceTest : public testing::Test { | 22 class DriSurfaceTest : public testing::Test { |
| 24 public: | 23 public: |
| 25 DriSurfaceTest() {} | 24 DriSurfaceTest() {} |
| 26 | 25 |
| 27 virtual void SetUp() OVERRIDE; | 26 virtual void SetUp() OVERRIDE; |
| 28 virtual void TearDown() OVERRIDE; | 27 virtual void TearDown() OVERRIDE; |
| 29 | 28 |
| 30 protected: | 29 protected: |
| 31 scoped_ptr<ui::MockDriWrapper> drm_; | 30 scoped_ptr<ui::MockDriWrapper> drm_; |
| 32 scoped_ptr<ui::HardwareDisplayController> controller_; | 31 scoped_ptr<ui::HardwareDisplayController> controller_; |
| 33 scoped_ptr<ui::MockDriSurface> surface_; | 32 scoped_ptr<ui::DriSurface> surface_; |
| 34 | 33 |
| 35 private: | 34 private: |
| 36 DISALLOW_COPY_AND_ASSIGN(DriSurfaceTest); | 35 DISALLOW_COPY_AND_ASSIGN(DriSurfaceTest); |
| 37 }; | 36 }; |
| 38 | 37 |
| 39 void DriSurfaceTest::SetUp() { | 38 void DriSurfaceTest::SetUp() { |
| 40 drm_.reset(new ui::MockDriWrapper(3)); | 39 drm_.reset(new ui::MockDriWrapper(3)); |
| 41 controller_.reset(new ui::HardwareDisplayController(drm_.get(), 1, 1)); | 40 controller_.reset(new ui::HardwareDisplayController(drm_.get(), 1, 1)); |
| 42 | 41 |
| 43 surface_.reset(new ui::MockDriSurface( | 42 surface_.reset(new ui::DriSurface( |
| 44 drm_.get(), gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay))); | 43 drm_.get(), gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay))); |
| 45 } | 44 } |
| 46 | 45 |
| 47 void DriSurfaceTest::TearDown() { | 46 void DriSurfaceTest::TearDown() { |
| 48 surface_.reset(); | 47 surface_.reset(); |
| 49 controller_.reset(); | 48 controller_.reset(); |
| 50 drm_.reset(); | 49 drm_.reset(); |
| 51 } | 50 } |
| 52 | 51 |
| 53 TEST_F(DriSurfaceTest, FailInitialization) { | 52 TEST_F(DriSurfaceTest, FailInitialization) { |
| 54 surface_->set_initialize_expectation(false); | 53 drm_->set_create_dumb_buffer_expectation(false); |
| 55 EXPECT_FALSE(surface_->Initialize()); | 54 EXPECT_FALSE(surface_->Initialize()); |
| 56 } | 55 } |
| 57 | 56 |
| 58 TEST_F(DriSurfaceTest, SuccessfulInitialization) { | 57 TEST_F(DriSurfaceTest, SuccessfulInitialization) { |
| 59 EXPECT_TRUE(surface_->Initialize()); | 58 EXPECT_TRUE(surface_->Initialize()); |
| 60 } | 59 } |
| 61 | 60 |
| 62 TEST_F(DriSurfaceTest, CheckFBIDOnSwap) { | 61 TEST_F(DriSurfaceTest, CheckFBIDOnSwap) { |
| 63 EXPECT_TRUE(surface_->Initialize()); | 62 EXPECT_TRUE(surface_->Initialize()); |
| 64 controller_->BindSurfaceToController(surface_.PassAs<ui::ScanoutSurface>(), | 63 controller_->BindSurfaceToController(surface_.PassAs<ui::ScanoutSurface>(), |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 80 | 79 |
| 81 surface_->SwapBuffers(); | 80 surface_->SwapBuffers(); |
| 82 | 81 |
| 83 void* bitmap_pixels2 = surface_->GetDrawableForWidget()->getDevice() | 82 void* bitmap_pixels2 = surface_->GetDrawableForWidget()->getDevice() |
| 84 ->accessBitmap(false).getPixels(); | 83 ->accessBitmap(false).getPixels(); |
| 85 | 84 |
| 86 // Check that once the buffers have been swapped the drawable's underlying | 85 // Check that once the buffers have been swapped the drawable's underlying |
| 87 // pixels have been changed. | 86 // pixels have been changed. |
| 88 EXPECT_NE(bitmap_pixels1, bitmap_pixels2); | 87 EXPECT_NE(bitmap_pixels1, bitmap_pixels2); |
| 89 } | 88 } |
| 90 | |
| 91 TEST_F(DriSurfaceTest, CheckCorrectBufferSync) { | |
|
dnicoara
2014/07/17 19:50:07
I removed this since it is duplicated in SFO unitt
| |
| 92 EXPECT_TRUE(surface_->Initialize()); | |
| 93 | |
| 94 SkCanvas* canvas = surface_->GetDrawableForWidget(); | |
| 95 SkRect clip; | |
| 96 // Modify part of the canvas. | |
| 97 clip.set(0, 0, | |
| 98 canvas->getDeviceSize().width() / 2, | |
| 99 canvas->getDeviceSize().height() / 2); | |
| 100 canvas->clipRect(clip, SkRegion::kReplace_Op); | |
| 101 | |
| 102 canvas->drawColor(SK_ColorWHITE); | |
| 103 | |
| 104 surface_->SwapBuffers(); | |
| 105 | |
| 106 // Verify that the modified contents have been copied over on swap (make sure | |
| 107 // the 2 buffers have the same content). | |
| 108 for (int i = 0; i < canvas->getDeviceSize().height(); ++i) { | |
| 109 for (int j = 0; j < canvas->getDeviceSize().width(); ++j) { | |
| 110 if (i < clip.height() && j < clip.width()) | |
| 111 EXPECT_EQ(SK_ColorWHITE, | |
| 112 canvas->getDevice()->accessBitmap(false).getColor(j, i)); | |
| 113 else | |
| 114 EXPECT_EQ(SK_ColorBLACK, | |
| 115 canvas->getDevice()->accessBitmap(false).getColor(j, i)); | |
| 116 } | |
| 117 } | |
| 118 } | |
| OLD | NEW |