| 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 <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/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 11 #include "third_party/skia/include/core/SkColor.h" | 11 #include "third_party/skia/include/core/SkColor.h" |
| 12 #include "third_party/skia/include/core/SkImageInfo.h" | 12 #include "third_party/skia/include/core/SkImageInfo.h" |
| 13 #include "ui/ozone/platform/dri/dri_buffer.h" | 13 #include "ui/ozone/platform/dri/dri_buffer.h" |
| 14 #include "ui/ozone/platform/dri/dri_surface.h" | 14 #include "ui/ozone/platform/dri/dri_surface.h" |
| 15 #include "ui/ozone/platform/dri/dri_surface_factory.h" | 15 #include "ui/ozone/platform/dri/dri_surface_factory.h" |
| 16 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h" | 16 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h" |
| 17 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h" | 17 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h" |
| 18 #include "ui/ozone/platform/dri/drm_device_manager.h" | 18 #include "ui/ozone/platform/dri/drm_device_manager.h" |
| 19 #include "ui/ozone/platform/dri/hardware_display_controller.h" | 19 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
| 20 #include "ui/ozone/platform/dri/screen_manager.h" | 20 #include "ui/ozone/platform/dri/screen_manager.h" |
| 21 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h" | 21 #include "ui/ozone/platform/dri/test/mock_drm_device.h" |
| 22 #include "ui/ozone/public/surface_ozone_canvas.h" | 22 #include "ui/ozone/public/surface_ozone_canvas.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // Mode of size 6x4. | 26 // Mode of size 6x4. |
| 27 const drmModeModeInfo kDefaultMode = | 27 const drmModeModeInfo kDefaultMode = |
| 28 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; | 28 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; |
| 29 | 29 |
| 30 const gfx::AcceleratedWidget kDefaultWidgetHandle = 1; | 30 const gfx::AcceleratedWidget kDefaultWidgetHandle = 1; |
| 31 const uint32_t kDefaultCrtc = 1; | 31 const uint32_t kDefaultCrtc = 1; |
| 32 const uint32_t kDefaultConnector = 2; | 32 const uint32_t kDefaultConnector = 2; |
| 33 const int kDefaultCursorSize = 64; | 33 const int kDefaultCursorSize = 64; |
| 34 | 34 |
| 35 std::vector<skia::RefPtr<SkSurface>> GetCursorBuffers( | 35 std::vector<skia::RefPtr<SkSurface>> GetCursorBuffers( |
| 36 const scoped_refptr<ui::MockDriWrapper> drm) { | 36 const scoped_refptr<ui::MockDrmDevice> drm) { |
| 37 std::vector<skia::RefPtr<SkSurface>> cursor_buffers; | 37 std::vector<skia::RefPtr<SkSurface>> cursor_buffers; |
| 38 for (const skia::RefPtr<SkSurface>& cursor_buffer : drm->buffers()) { | 38 for (const skia::RefPtr<SkSurface>& cursor_buffer : drm->buffers()) { |
| 39 if (cursor_buffer->width() == kDefaultCursorSize && | 39 if (cursor_buffer->width() == kDefaultCursorSize && |
| 40 cursor_buffer->height() == kDefaultCursorSize) { | 40 cursor_buffer->height() == kDefaultCursorSize) { |
| 41 cursor_buffers.push_back(cursor_buffer); | 41 cursor_buffers.push_back(cursor_buffer); |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 return cursor_buffers; | 45 return cursor_buffers; |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 class DriWindowDelegateImplTest : public testing::Test { | 50 class DriWindowDelegateImplTest : public testing::Test { |
| 51 public: | 51 public: |
| 52 DriWindowDelegateImplTest() {} | 52 DriWindowDelegateImplTest() {} |
| 53 | 53 |
| 54 void SetUp() override; | 54 void SetUp() override; |
| 55 void TearDown() override; | 55 void TearDown() override; |
| 56 | 56 |
| 57 protected: | 57 protected: |
| 58 scoped_ptr<base::MessageLoop> message_loop_; | 58 scoped_ptr<base::MessageLoop> message_loop_; |
| 59 scoped_refptr<ui::MockDriWrapper> dri_; | 59 scoped_refptr<ui::MockDrmDevice> drm_; |
| 60 scoped_ptr<ui::DriBufferGenerator> buffer_generator_; | 60 scoped_ptr<ui::DriBufferGenerator> buffer_generator_; |
| 61 scoped_ptr<ui::ScreenManager> screen_manager_; | 61 scoped_ptr<ui::ScreenManager> screen_manager_; |
| 62 scoped_ptr<ui::DrmDeviceManager> drm_device_manager_; | 62 scoped_ptr<ui::DrmDeviceManager> drm_device_manager_; |
| 63 scoped_ptr<ui::DriWindowDelegateManager> window_delegate_manager_; | 63 scoped_ptr<ui::DriWindowDelegateManager> window_delegate_manager_; |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 DISALLOW_COPY_AND_ASSIGN(DriWindowDelegateImplTest); | 66 DISALLOW_COPY_AND_ASSIGN(DriWindowDelegateImplTest); |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 void DriWindowDelegateImplTest::SetUp() { | 69 void DriWindowDelegateImplTest::SetUp() { |
| 70 message_loop_.reset(new base::MessageLoopForUI); | 70 message_loop_.reset(new base::MessageLoopForUI); |
| 71 dri_ = new ui::MockDriWrapper(); | 71 drm_ = new ui::MockDrmDevice(); |
| 72 buffer_generator_.reset(new ui::DriBufferGenerator()); | 72 buffer_generator_.reset(new ui::DriBufferGenerator()); |
| 73 screen_manager_.reset(new ui::ScreenManager(buffer_generator_.get())); | 73 screen_manager_.reset(new ui::ScreenManager(buffer_generator_.get())); |
| 74 screen_manager_->AddDisplayController(dri_, kDefaultCrtc, kDefaultConnector); | 74 screen_manager_->AddDisplayController(drm_, kDefaultCrtc, kDefaultConnector); |
| 75 screen_manager_->ConfigureDisplayController( | 75 screen_manager_->ConfigureDisplayController( |
| 76 dri_, kDefaultCrtc, kDefaultConnector, gfx::Point(), kDefaultMode); | 76 drm_, kDefaultCrtc, kDefaultConnector, gfx::Point(), kDefaultMode); |
| 77 | 77 |
| 78 drm_device_manager_.reset(new ui::DrmDeviceManager(dri_)); | 78 drm_device_manager_.reset(new ui::DrmDeviceManager(drm_)); |
| 79 window_delegate_manager_.reset(new ui::DriWindowDelegateManager()); | 79 window_delegate_manager_.reset(new ui::DriWindowDelegateManager()); |
| 80 | 80 |
| 81 scoped_ptr<ui::DriWindowDelegate> window_delegate( | 81 scoped_ptr<ui::DriWindowDelegate> window_delegate( |
| 82 new ui::DriWindowDelegateImpl(kDefaultWidgetHandle, | 82 new ui::DriWindowDelegateImpl(kDefaultWidgetHandle, |
| 83 drm_device_manager_.get(), | 83 drm_device_manager_.get(), |
| 84 screen_manager_.get())); | 84 screen_manager_.get())); |
| 85 window_delegate->Initialize(); | 85 window_delegate->Initialize(); |
| 86 window_delegate->OnBoundsChanged( | 86 window_delegate->OnBoundsChanged( |
| 87 gfx::Rect(gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay))); | 87 gfx::Rect(gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay))); |
| 88 window_delegate_manager_->AddWindowDelegate(kDefaultWidgetHandle, | 88 window_delegate_manager_->AddWindowDelegate(kDefaultWidgetHandle, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 102 SkImageInfo::Make(6, 4, kN32_SkColorType, kPremul_SkAlphaType); | 102 SkImageInfo::Make(6, 4, kN32_SkColorType, kPremul_SkAlphaType); |
| 103 image.allocPixels(info); | 103 image.allocPixels(info); |
| 104 image.eraseColor(SK_ColorWHITE); | 104 image.eraseColor(SK_ColorWHITE); |
| 105 | 105 |
| 106 std::vector<SkBitmap> cursor_bitmaps; | 106 std::vector<SkBitmap> cursor_bitmaps; |
| 107 cursor_bitmaps.push_back(image); | 107 cursor_bitmaps.push_back(image); |
| 108 window_delegate_manager_->GetWindowDelegate(kDefaultWidgetHandle) | 108 window_delegate_manager_->GetWindowDelegate(kDefaultWidgetHandle) |
| 109 ->SetCursor(cursor_bitmaps, gfx::Point(4, 2), 0); | 109 ->SetCursor(cursor_bitmaps, gfx::Point(4, 2), 0); |
| 110 | 110 |
| 111 SkBitmap cursor; | 111 SkBitmap cursor; |
| 112 std::vector<skia::RefPtr<SkSurface>> cursor_buffers = GetCursorBuffers(dri_); | 112 std::vector<skia::RefPtr<SkSurface>> cursor_buffers = GetCursorBuffers(drm_); |
| 113 EXPECT_EQ(2u, cursor_buffers.size()); | 113 EXPECT_EQ(2u, cursor_buffers.size()); |
| 114 | 114 |
| 115 // Buffers 1 is the cursor backbuffer we just drew in. | 115 // Buffers 1 is the cursor backbuffer we just drew in. |
| 116 cursor.setInfo(cursor_buffers[1]->getCanvas()->imageInfo()); | 116 cursor.setInfo(cursor_buffers[1]->getCanvas()->imageInfo()); |
| 117 EXPECT_TRUE(cursor_buffers[1]->getCanvas()->readPixels(&cursor, 0, 0)); | 117 EXPECT_TRUE(cursor_buffers[1]->getCanvas()->readPixels(&cursor, 0, 0)); |
| 118 | 118 |
| 119 // Check that the frontbuffer is displaying the right image as set above. | 119 // Check that the frontbuffer is displaying the right image as set above. |
| 120 for (int i = 0; i < cursor.height(); ++i) { | 120 for (int i = 0; i < cursor.height(); ++i) { |
| 121 for (int j = 0; j < cursor.width(); ++j) { | 121 for (int j = 0; j < cursor.width(); ++j) { |
| 122 if (j < info.width() && i < info.height()) | 122 if (j < info.width() && i < info.height()) |
| 123 EXPECT_EQ(SK_ColorWHITE, cursor.getColor(j, i)); | 123 EXPECT_EQ(SK_ColorWHITE, cursor.getColor(j, i)); |
| 124 else | 124 else |
| 125 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), | 125 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), |
| 126 cursor.getColor(j, i)); | 126 cursor.getColor(j, i)); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 | 130 |
| 131 TEST_F(DriWindowDelegateImplTest, CheckCursorSurfaceAfterChangingDevice) { | 131 TEST_F(DriWindowDelegateImplTest, CheckCursorSurfaceAfterChangingDevice) { |
| 132 // Add another device. | 132 // Add another device. |
| 133 scoped_refptr<ui::MockDriWrapper> drm = new ui::MockDriWrapper(); | 133 scoped_refptr<ui::MockDrmDevice> drm = new ui::MockDrmDevice(); |
| 134 screen_manager_->AddDisplayController(drm, kDefaultCrtc, kDefaultConnector); | 134 screen_manager_->AddDisplayController(drm, kDefaultCrtc, kDefaultConnector); |
| 135 screen_manager_->ConfigureDisplayController( | 135 screen_manager_->ConfigureDisplayController( |
| 136 drm, kDefaultCrtc, kDefaultConnector, | 136 drm, kDefaultCrtc, kDefaultConnector, |
| 137 gfx::Point(0, kDefaultMode.vdisplay), kDefaultMode); | 137 gfx::Point(0, kDefaultMode.vdisplay), kDefaultMode); |
| 138 | 138 |
| 139 // Move window to the display on the new device. | 139 // Move window to the display on the new device. |
| 140 window_delegate_manager_->GetWindowDelegate(kDefaultWidgetHandle) | 140 window_delegate_manager_->GetWindowDelegate(kDefaultWidgetHandle) |
| 141 ->OnBoundsChanged(gfx::Rect(0, kDefaultMode.vdisplay, | 141 ->OnBoundsChanged(gfx::Rect(0, kDefaultMode.vdisplay, |
| 142 kDefaultMode.hdisplay, | 142 kDefaultMode.hdisplay, |
| 143 kDefaultMode.vdisplay)); | 143 kDefaultMode.vdisplay)); |
| 144 | 144 |
| 145 EXPECT_EQ(2u, GetCursorBuffers(drm).size()); | 145 EXPECT_EQ(2u, GetCursorBuffers(drm).size()); |
| 146 } | 146 } |
| OLD | NEW |