| 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/gfx/ozone/surface_factory_ozone.h" | |
| 14 #include "ui/gfx/ozone/surface_ozone_canvas.h" | |
| 15 #include "ui/ozone/platform/dri/dri_buffer.h" | 13 #include "ui/ozone/platform/dri/dri_buffer.h" |
| 16 #include "ui/ozone/platform/dri/dri_surface.h" | 14 #include "ui/ozone/platform/dri/dri_surface.h" |
| 17 #include "ui/ozone/platform/dri/dri_surface_factory.h" | 15 #include "ui/ozone/platform/dri/dri_surface_factory.h" |
| 18 #include "ui/ozone/platform/dri/hardware_display_controller.h" | 16 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
| 19 #include "ui/ozone/platform/dri/screen_manager.h" | 17 #include "ui/ozone/platform/dri/screen_manager.h" |
| 20 #include "ui/ozone/platform/dri/test/mock_dri_surface.h" | 18 #include "ui/ozone/platform/dri/test/mock_dri_surface.h" |
| 21 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h" | 19 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h" |
| 22 #include "ui/ozone/platform/dri/test/mock_surface_generator.h" | 20 #include "ui/ozone/platform/dri/test/mock_surface_generator.h" |
| 21 #include "ui/ozone/public/surface_factory_ozone.h" |
| 22 #include "ui/ozone/public/surface_ozone_canvas.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const drmModeModeInfo kDefaultMode = | 26 const drmModeModeInfo kDefaultMode = |
| 27 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; | 27 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; |
| 28 | 28 |
| 29 // SSFO would normally allocate DRM resources. We can't rely on having a DRM | 29 // SSFO would normally allocate DRM resources. We can't rely on having a DRM |
| 30 // backend to allocate and display our buffers. Thus, we replace these | 30 // backend to allocate and display our buffers. Thus, we replace these |
| 31 // resources with stubs. For DRM calls, we simply use stubs that do nothing and | 31 // resources with stubs. For DRM calls, we simply use stubs that do nothing and |
| 32 // for buffers we use the default SkBitmap allocator. | 32 // for buffers we use the default SkBitmap allocator. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 factory_.reset(new MockDriSurfaceFactory(dri_.get(), screen_manager_.get())); | 102 factory_.reset(new MockDriSurfaceFactory(dri_.get(), screen_manager_.get())); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void DriSurfaceFactoryTest::TearDown() { | 105 void DriSurfaceFactoryTest::TearDown() { |
| 106 factory_.reset(); | 106 factory_.reset(); |
| 107 message_loop_.reset(); | 107 message_loop_.reset(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 TEST_F(DriSurfaceFactoryTest, FailInitialization) { | 110 TEST_F(DriSurfaceFactoryTest, FailInitialization) { |
| 111 dri_->fail_init(); | 111 dri_->fail_init(); |
| 112 EXPECT_EQ(gfx::SurfaceFactoryOzone::FAILED, factory_->InitializeHardware()); | 112 EXPECT_EQ(ui::SurfaceFactoryOzone::FAILED, factory_->InitializeHardware()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 TEST_F(DriSurfaceFactoryTest, SuccessfulInitialization) { | 115 TEST_F(DriSurfaceFactoryTest, SuccessfulInitialization) { |
| 116 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, | 116 EXPECT_EQ(ui::SurfaceFactoryOzone::INITIALIZED, |
| 117 factory_->InitializeHardware()); | 117 factory_->InitializeHardware()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 TEST_F(DriSurfaceFactoryTest, SuccessfulWidgetRealization) { | 120 TEST_F(DriSurfaceFactoryTest, SuccessfulWidgetRealization) { |
| 121 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, | 121 EXPECT_EQ(ui::SurfaceFactoryOzone::INITIALIZED, |
| 122 factory_->InitializeHardware()); | 122 factory_->InitializeHardware()); |
| 123 | 123 |
| 124 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); | 124 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); |
| 125 EXPECT_EQ(ui::DriSurfaceFactory::kDefaultWidgetHandle, w); | 125 EXPECT_EQ(ui::DriSurfaceFactory::kDefaultWidgetHandle, w); |
| 126 | 126 |
| 127 EXPECT_TRUE(factory_->CreateCanvasForWidget(w)); | 127 EXPECT_TRUE(factory_->CreateCanvasForWidget(w)); |
| 128 } | 128 } |
| 129 | 129 |
| 130 TEST_F(DriSurfaceFactoryTest, CheckNativeSurfaceContents) { | 130 TEST_F(DriSurfaceFactoryTest, CheckNativeSurfaceContents) { |
| 131 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, | 131 EXPECT_EQ(ui::SurfaceFactoryOzone::INITIALIZED, |
| 132 factory_->InitializeHardware()); | 132 factory_->InitializeHardware()); |
| 133 | 133 |
| 134 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); | 134 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); |
| 135 EXPECT_EQ(ui::DriSurfaceFactory::kDefaultWidgetHandle, w); | 135 EXPECT_EQ(ui::DriSurfaceFactory::kDefaultWidgetHandle, w); |
| 136 | 136 |
| 137 scoped_ptr<gfx::SurfaceOzoneCanvas> surface = | 137 scoped_ptr<ui::SurfaceOzoneCanvas> surface = |
| 138 factory_->CreateCanvasForWidget(w); | 138 factory_->CreateCanvasForWidget(w); |
| 139 | 139 |
| 140 surface->ResizeCanvas( | 140 surface->ResizeCanvas( |
| 141 gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay)); | 141 gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay)); |
| 142 surface->GetCanvas()->drawColor(SK_ColorWHITE); | 142 surface->GetCanvas()->drawColor(SK_ColorWHITE); |
| 143 surface->PresentCanvas( | 143 surface->PresentCanvas( |
| 144 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2)); | 144 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2)); |
| 145 | 145 |
| 146 const std::vector<ui::DriBuffer*>& bitmaps = | 146 const std::vector<ui::DriBuffer*>& bitmaps = |
| 147 surface_generator_->surfaces()[0]->bitmaps(); | 147 surface_generator_->surfaces()[0]->bitmaps(); |
| 148 | 148 |
| 149 SkBitmap image; | 149 SkBitmap image; |
| 150 bitmaps[1]->canvas()->readPixels(&image, 0, 0); | 150 bitmaps[1]->canvas()->readPixels(&image, 0, 0); |
| 151 | 151 |
| 152 // Make sure the updates are correctly propagated to the native surface. | 152 // Make sure the updates are correctly propagated to the native surface. |
| 153 for (int i = 0; i < image.height(); ++i) { | 153 for (int i = 0; i < image.height(); ++i) { |
| 154 for (int j = 0; j < image.width(); ++j) { | 154 for (int j = 0; j < image.width(); ++j) { |
| 155 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2) | 155 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2) |
| 156 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i)); | 156 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i)); |
| 157 else | 157 else |
| 158 EXPECT_EQ(SK_ColorBLACK, image.getColor(j, i)); | 158 EXPECT_EQ(SK_ColorBLACK, image.getColor(j, i)); |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 TEST_F(DriSurfaceFactoryTest, SetCursorImage) { | 163 TEST_F(DriSurfaceFactoryTest, SetCursorImage) { |
| 164 EXPECT_EQ(gfx::SurfaceFactoryOzone::INITIALIZED, | 164 EXPECT_EQ(ui::SurfaceFactoryOzone::INITIALIZED, |
| 165 factory_->InitializeHardware()); | 165 factory_->InitializeHardware()); |
| 166 | 166 |
| 167 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); | 167 gfx::AcceleratedWidget w = factory_->GetAcceleratedWidget(); |
| 168 EXPECT_EQ(ui::DriSurfaceFactory::kDefaultWidgetHandle, w); | 168 EXPECT_EQ(ui::DriSurfaceFactory::kDefaultWidgetHandle, w); |
| 169 | 169 |
| 170 scoped_ptr<gfx::SurfaceOzoneCanvas> surf = factory_->CreateCanvasForWidget(w); | 170 scoped_ptr<ui::SurfaceOzoneCanvas> surf = factory_->CreateCanvasForWidget(w); |
| 171 EXPECT_TRUE(surf); | 171 EXPECT_TRUE(surf); |
| 172 | 172 |
| 173 SkBitmap image; | 173 SkBitmap image; |
| 174 SkImageInfo info = SkImageInfo::Make( | 174 SkImageInfo info = SkImageInfo::Make( |
| 175 6, 4, kN32_SkColorType, kPremul_SkAlphaType); | 175 6, 4, kN32_SkColorType, kPremul_SkAlphaType); |
| 176 image.allocPixels(info); | 176 image.allocPixels(info); |
| 177 image.eraseColor(SK_ColorWHITE); | 177 image.eraseColor(SK_ColorWHITE); |
| 178 | 178 |
| 179 factory_->SetHardwareCursor(w, image, gfx::Point(4, 2)); | 179 factory_->SetHardwareCursor(w, image, gfx::Point(4, 2)); |
| 180 const std::vector<ui::MockDriSurface*>& surfaces = factory_->get_surfaces(); | 180 const std::vector<ui::MockDriSurface*>& surfaces = factory_->get_surfaces(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 193 for (int i = 0; i < cursor.height(); ++i) { | 193 for (int i = 0; i < cursor.height(); ++i) { |
| 194 for (int j = 0; j < cursor.width(); ++j) { | 194 for (int j = 0; j < cursor.width(); ++j) { |
| 195 if (j < info.width() && i < info.height()) | 195 if (j < info.width() && i < info.height()) |
| 196 EXPECT_EQ(SK_ColorWHITE, cursor.getColor(j, i)); | 196 EXPECT_EQ(SK_ColorWHITE, cursor.getColor(j, i)); |
| 197 else | 197 else |
| 198 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), | 198 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), |
| 199 cursor.getColor(j, i)); | 199 cursor.getColor(j, i)); |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 } | 202 } |
| OLD | NEW |