OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <vector> |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 11 #include "third_party/skia/include/core/SkColor.h" |
| 12 #include "third_party/skia/include/core/SkImageInfo.h" |
| 13 #include "ui/ozone/platform/drm/gpu/drm_buffer.h" |
| 14 #include "ui/ozone/platform/drm/gpu/drm_device_generator.h" |
| 15 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h" |
| 16 #include "ui/ozone/platform/drm/gpu/drm_surface.h" |
| 17 #include "ui/ozone/platform/drm/gpu/drm_surface_factory.h" |
| 18 #include "ui/ozone/platform/drm/gpu/drm_window.h" |
| 19 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h" |
| 20 #include "ui/ozone/platform/drm/gpu/screen_manager.h" |
| 21 #include "ui/ozone/platform/drm/test/mock_drm_device.h" |
| 22 #include "ui/ozone/public/surface_ozone_canvas.h" |
| 23 |
| 24 namespace { |
| 25 |
| 26 // Mode of size 6x4. |
| 27 const drmModeModeInfo kDefaultMode = |
| 28 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; |
| 29 |
| 30 const gfx::AcceleratedWidget kDefaultWidgetHandle = 1; |
| 31 const uint32_t kDefaultCrtc = 1; |
| 32 const uint32_t kDefaultConnector = 2; |
| 33 const int kDefaultCursorSize = 64; |
| 34 |
| 35 std::vector<skia::RefPtr<SkSurface>> GetCursorBuffers( |
| 36 const scoped_refptr<ui::MockDrmDevice> drm) { |
| 37 std::vector<skia::RefPtr<SkSurface>> cursor_buffers; |
| 38 for (const skia::RefPtr<SkSurface>& cursor_buffer : drm->buffers()) { |
| 39 if (cursor_buffer->width() == kDefaultCursorSize && |
| 40 cursor_buffer->height() == kDefaultCursorSize) { |
| 41 cursor_buffers.push_back(cursor_buffer); |
| 42 } |
| 43 } |
| 44 |
| 45 return cursor_buffers; |
| 46 } |
| 47 |
| 48 SkBitmap AllocateBitmap(const gfx::Size& size) { |
| 49 SkBitmap image; |
| 50 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), |
| 51 kN32_SkColorType, kPremul_SkAlphaType); |
| 52 image.allocPixels(info); |
| 53 image.eraseColor(SK_ColorWHITE); |
| 54 return image; |
| 55 } |
| 56 |
| 57 } // namespace |
| 58 |
| 59 class DrmWindowTest : public testing::Test { |
| 60 public: |
| 61 DrmWindowTest() {} |
| 62 |
| 63 void SetUp() override; |
| 64 void TearDown() override; |
| 65 |
| 66 protected: |
| 67 scoped_ptr<base::MessageLoop> message_loop_; |
| 68 scoped_refptr<ui::MockDrmDevice> drm_; |
| 69 scoped_ptr<ui::DrmBufferGenerator> buffer_generator_; |
| 70 scoped_ptr<ui::ScreenManager> screen_manager_; |
| 71 scoped_ptr<ui::DrmDeviceManager> drm_device_manager_; |
| 72 |
| 73 private: |
| 74 DISALLOW_COPY_AND_ASSIGN(DrmWindowTest); |
| 75 }; |
| 76 |
| 77 void DrmWindowTest::SetUp() { |
| 78 message_loop_.reset(new base::MessageLoopForUI); |
| 79 drm_ = new ui::MockDrmDevice(); |
| 80 buffer_generator_.reset(new ui::DrmBufferGenerator()); |
| 81 screen_manager_.reset(new ui::ScreenManager(buffer_generator_.get())); |
| 82 screen_manager_->AddDisplayController(drm_, kDefaultCrtc, kDefaultConnector); |
| 83 screen_manager_->ConfigureDisplayController( |
| 84 drm_, kDefaultCrtc, kDefaultConnector, gfx::Point(), kDefaultMode); |
| 85 |
| 86 drm_device_manager_.reset(new ui::DrmDeviceManager(nullptr)); |
| 87 |
| 88 scoped_ptr<ui::DrmWindow> window_delegate(new ui::DrmWindow( |
| 89 kDefaultWidgetHandle, drm_device_manager_.get(), screen_manager_.get())); |
| 90 window_delegate->Initialize(); |
| 91 window_delegate->OnBoundsChanged( |
| 92 gfx::Rect(gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay))); |
| 93 screen_manager_->AddWindow(kDefaultWidgetHandle, window_delegate.Pass()); |
| 94 } |
| 95 |
| 96 void DrmWindowTest::TearDown() { |
| 97 scoped_ptr<ui::DrmWindow> delegate = |
| 98 screen_manager_->RemoveWindow(kDefaultWidgetHandle); |
| 99 delegate->Shutdown(); |
| 100 message_loop_.reset(); |
| 101 } |
| 102 |
| 103 TEST_F(DrmWindowTest, SetCursorImage) { |
| 104 const gfx::Size cursor_size(6, 4); |
| 105 screen_manager_->GetWindow(kDefaultWidgetHandle) |
| 106 ->SetCursor(std::vector<SkBitmap>(1, AllocateBitmap(cursor_size)), |
| 107 gfx::Point(4, 2), 0); |
| 108 |
| 109 SkBitmap cursor; |
| 110 std::vector<skia::RefPtr<SkSurface>> cursor_buffers = GetCursorBuffers(drm_); |
| 111 EXPECT_EQ(2u, cursor_buffers.size()); |
| 112 |
| 113 // Buffers 1 is the cursor backbuffer we just drew in. |
| 114 cursor.setInfo(cursor_buffers[1]->getCanvas()->imageInfo()); |
| 115 EXPECT_TRUE(cursor_buffers[1]->getCanvas()->readPixels(&cursor, 0, 0)); |
| 116 |
| 117 // Check that the frontbuffer is displaying the right image as set above. |
| 118 for (int i = 0; i < cursor.height(); ++i) { |
| 119 for (int j = 0; j < cursor.width(); ++j) { |
| 120 if (j < cursor_size.width() && i < cursor_size.height()) |
| 121 EXPECT_EQ(SK_ColorWHITE, cursor.getColor(j, i)); |
| 122 else |
| 123 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), |
| 124 cursor.getColor(j, i)); |
| 125 } |
| 126 } |
| 127 } |
| 128 |
| 129 TEST_F(DrmWindowTest, CheckCursorSurfaceAfterChangingDevice) { |
| 130 const gfx::Size cursor_size(6, 4); |
| 131 screen_manager_->GetWindow(kDefaultWidgetHandle) |
| 132 ->SetCursor(std::vector<SkBitmap>(1, AllocateBitmap(cursor_size)), |
| 133 gfx::Point(4, 2), 0); |
| 134 |
| 135 // Add another device. |
| 136 scoped_refptr<ui::MockDrmDevice> drm = new ui::MockDrmDevice(); |
| 137 screen_manager_->AddDisplayController(drm, kDefaultCrtc, kDefaultConnector); |
| 138 screen_manager_->ConfigureDisplayController( |
| 139 drm, kDefaultCrtc, kDefaultConnector, |
| 140 gfx::Point(0, kDefaultMode.vdisplay), kDefaultMode); |
| 141 |
| 142 // Move window to the display on the new device. |
| 143 screen_manager_->GetWindow(kDefaultWidgetHandle) |
| 144 ->OnBoundsChanged(gfx::Rect(0, kDefaultMode.vdisplay, |
| 145 kDefaultMode.hdisplay, |
| 146 kDefaultMode.vdisplay)); |
| 147 |
| 148 EXPECT_EQ(2u, GetCursorBuffers(drm).size()); |
| 149 // Make sure the cursor is showing on the new display. |
| 150 EXPECT_NE(0u, drm->get_cursor_handle_for_crtc(kDefaultCrtc)); |
| 151 } |
OLD | NEW |