| 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 "base/message_loop/message_loop.h" |
| 5 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "third_party/skia/include/core/SkCanvas.h" | 7 #include "third_party/skia/include/core/SkCanvas.h" |
| 7 #include "third_party/skia/include/core/SkColor.h" | 8 #include "third_party/skia/include/core/SkColor.h" |
| 8 #include "third_party/skia/include/core/SkDevice.h" | 9 #include "third_party/skia/include/core/SkDevice.h" |
| 9 #include "ui/ozone/platform/dri/dri_buffer.h" | 10 #include "ui/ozone/platform/dri/dri_buffer.h" |
| 10 #include "ui/ozone/platform/dri/dri_surface.h" | 11 #include "ui/ozone/platform/dri/dri_surface.h" |
| 11 #include "ui/ozone/platform/dri/hardware_display_controller.h" | 12 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
| 12 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h" | 13 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // Create a basic mode for a 6x4 screen. | 17 // Create a basic mode for a 6x4 screen. |
| 17 const drmModeModeInfo kDefaultMode = | 18 const drmModeModeInfo kDefaultMode = |
| 18 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; | 19 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; |
| 19 | 20 |
| 20 } // namespace | 21 } // namespace |
| 21 | 22 |
| 22 class DriSurfaceTest : public testing::Test { | 23 class DriSurfaceTest : public testing::Test { |
| 23 public: | 24 public: |
| 24 DriSurfaceTest() {} | 25 DriSurfaceTest() {} |
| 25 | 26 |
| 26 virtual void SetUp() OVERRIDE; | 27 virtual void SetUp() OVERRIDE; |
| 27 virtual void TearDown() OVERRIDE; | 28 virtual void TearDown() OVERRIDE; |
| 28 | 29 |
| 29 protected: | 30 protected: |
| 31 scoped_ptr<base::MessageLoop> message_loop_; |
| 30 scoped_ptr<ui::MockDriWrapper> drm_; | 32 scoped_ptr<ui::MockDriWrapper> drm_; |
| 31 scoped_ptr<ui::HardwareDisplayController> controller_; | 33 scoped_ptr<ui::HardwareDisplayController> controller_; |
| 32 scoped_ptr<ui::DriSurface> surface_; | 34 scoped_ptr<ui::DriSurface> surface_; |
| 33 | 35 |
| 34 private: | 36 private: |
| 35 DISALLOW_COPY_AND_ASSIGN(DriSurfaceTest); | 37 DISALLOW_COPY_AND_ASSIGN(DriSurfaceTest); |
| 36 }; | 38 }; |
| 37 | 39 |
| 38 void DriSurfaceTest::SetUp() { | 40 void DriSurfaceTest::SetUp() { |
| 41 message_loop_.reset(new base::MessageLoopForUI); |
| 39 drm_.reset(new ui::MockDriWrapper(3)); | 42 drm_.reset(new ui::MockDriWrapper(3)); |
| 43 |
| 40 controller_.reset(new ui::HardwareDisplayController(drm_.get(), 1, 1)); | 44 controller_.reset(new ui::HardwareDisplayController(drm_.get(), 1, 1)); |
| 45 scoped_refptr<ui::DriBuffer> buffer(new ui::DriBuffer(drm_.get())); |
| 46 SkImageInfo info = SkImageInfo::MakeN32Premul(kDefaultMode.hdisplay, |
| 47 kDefaultMode.vdisplay); |
| 48 EXPECT_TRUE(buffer->Initialize(info)); |
| 49 EXPECT_TRUE(controller_->Modeset(ui::OverlayPlane(buffer), kDefaultMode)); |
| 41 | 50 |
| 42 surface_.reset(new ui::DriSurface( | 51 surface_.reset(new ui::DriSurface(drm_.get(), controller_->AsWeakPtr())); |
| 43 drm_.get(), gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay))); | 52 surface_->ResizeCanvas(gfx::Size(kDefaultMode.hdisplay, |
| 53 kDefaultMode.vdisplay)); |
| 44 } | 54 } |
| 45 | 55 |
| 46 void DriSurfaceTest::TearDown() { | 56 void DriSurfaceTest::TearDown() { |
| 47 surface_.reset(); | 57 surface_.reset(); |
| 48 controller_.reset(); | 58 controller_.reset(); |
| 49 drm_.reset(); | 59 drm_.reset(); |
| 50 } | 60 message_loop_.reset(); |
| 51 | |
| 52 TEST_F(DriSurfaceTest, FailInitialization) { | |
| 53 drm_->set_create_dumb_buffer_expectation(false); | |
| 54 EXPECT_FALSE(surface_->Initialize()); | |
| 55 } | |
| 56 | |
| 57 TEST_F(DriSurfaceTest, SuccessfulInitialization) { | |
| 58 EXPECT_TRUE(surface_->Initialize()); | |
| 59 } | 61 } |
| 60 | 62 |
| 61 TEST_F(DriSurfaceTest, CheckFBIDOnSwap) { | 63 TEST_F(DriSurfaceTest, CheckFBIDOnSwap) { |
| 62 EXPECT_TRUE(surface_->Initialize()); | 64 surface_->PresentCanvas(gfx::Rect()); |
| 63 | 65 // Framebuffer ID 1 is allocated in SetUp for the buffer used to modeset. |
| 64 // Check that the framebuffer ID is correct. | 66 EXPECT_EQ(3u, drm_->current_framebuffer()); |
| 65 EXPECT_EQ(2u, surface_->GetFramebufferId()); | 67 surface_->PresentCanvas(gfx::Rect()); |
| 66 | 68 EXPECT_EQ(2u, drm_->current_framebuffer()); |
| 67 surface_->SwapBuffers(); | |
| 68 | |
| 69 EXPECT_EQ(1u, surface_->GetFramebufferId()); | |
| 70 } | 69 } |
| 71 | 70 |
| 72 TEST_F(DriSurfaceTest, CheckPixelPointerOnSwap) { | 71 TEST_F(DriSurfaceTest, CheckSurfaceContents) { |
| 73 EXPECT_TRUE(surface_->Initialize()); | 72 SkPaint paint; |
| 73 paint.setColor(SK_ColorWHITE); |
| 74 SkRect rect = SkRect::MakeWH(kDefaultMode.hdisplay / 2, |
| 75 kDefaultMode.vdisplay / 2); |
| 76 surface_->GetCanvas()->drawRect(rect, paint); |
| 77 surface_->PresentCanvas( |
| 78 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2)); |
| 74 | 79 |
| 75 void* bitmap_pixels1 = surface_->GetDrawableForWidget()->getDevice() | 80 SkBitmap image; |
| 76 ->accessBitmap(false).getPixels(); | 81 // Buffer 0 is the buffer used in SetUp for modesetting and buffer 1 is the |
| 82 // frontbuffer. |
| 83 // Buffer 2 is the backbuffer we just painted in, so we want to make sure its |
| 84 // contents are correct. |
| 85 image.setInfo(drm_->buffers()[2]->getCanvas()->imageInfo()); |
| 86 EXPECT_TRUE(drm_->buffers()[2]->getCanvas()->readPixels(&image, 0, 0)); |
| 77 | 87 |
| 78 surface_->SwapBuffers(); | 88 EXPECT_EQ(kDefaultMode.hdisplay, image.width()); |
| 89 EXPECT_EQ(kDefaultMode.vdisplay, image.height()); |
| 79 | 90 |
| 80 void* bitmap_pixels2 = surface_->GetDrawableForWidget()->getDevice() | 91 // Make sure the updates are correctly propagated to the native surface. |
| 81 ->accessBitmap(false).getPixels(); | 92 for (int i = 0; i < image.height(); ++i) { |
| 82 | 93 for (int j = 0; j < image.width(); ++j) { |
| 83 // Check that once the buffers have been swapped the drawable's underlying | 94 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2) |
| 84 // pixels have been changed. | 95 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i)); |
| 85 EXPECT_NE(bitmap_pixels1, bitmap_pixels2); | 96 else |
| 97 EXPECT_EQ(SK_ColorBLACK, image.getColor(j, i)); |
| 98 } |
| 99 } |
| 86 } | 100 } |
| OLD | NEW |