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 <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/hardware_display_controller.h" | 16 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
| 17 #include "ui/ozone/platform/dri/screen_manager.h" | 17 #include "ui/ozone/platform/dri/screen_manager.h" |
| 18 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h" | 18 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h" |
| 19 #include "ui/ozone/platform/dri/test/mock_surface_generator.h" | |
| 20 #include "ui/ozone/public/surface_factory_ozone.h" | 19 #include "ui/ozone/public/surface_factory_ozone.h" |
| 21 #include "ui/ozone/public/surface_ozone_canvas.h" | 20 #include "ui/ozone/public/surface_ozone_canvas.h" |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 const drmModeModeInfo kDefaultMode = | 24 const drmModeModeInfo kDefaultMode = |
|
alexst (slow to review)
2014/07/21 20:56:24
So I was trying to understand what the code below
dnicoara
2014/07/21 21:02:12
Done.
alexst (slow to review)
2014/07/22 12:33:16
I meant please annotate all the fields so next per
dnicoara
2014/07/22 13:51:30
Ah, sorry, I misunderstood your comment.
I don't
| |
| 26 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; | 25 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; |
| 27 | 26 |
| 28 class MockScreenManager : public ui::ScreenManager { | 27 class MockScreenManager : public ui::ScreenManager { |
| 29 public: | 28 public: |
| 30 MockScreenManager(ui::DriWrapper* dri, | 29 MockScreenManager(ui::DriWrapper* dri, |
| 31 ui::ScanoutSurfaceGenerator* surface_generator) | 30 ui::ScanoutBufferGenerator* buffer_generator) |
| 32 : ScreenManager(dri, surface_generator), | 31 : ScreenManager(dri, buffer_generator), |
| 33 dri_(dri) {} | 32 dri_(dri) {} |
| 34 virtual ~MockScreenManager() {} | 33 virtual ~MockScreenManager() {} |
| 35 | 34 |
| 36 // Normally we'd use DRM to figure out the controller configuration. But we | 35 // Normally we'd use DRM to figure out the controller configuration. But we |
| 37 // can't use DRM in unit tests, so we just create a fake configuration. | 36 // can't use DRM in unit tests, so we just create a fake configuration. |
| 38 virtual void ForceInitializationOfPrimaryDisplay() OVERRIDE { | 37 virtual void ForceInitializationOfPrimaryDisplay() OVERRIDE { |
| 39 ConfigureDisplayController(1, 2, kDefaultMode); | 38 ConfigureDisplayController(1, 2, kDefaultMode); |
| 40 } | 39 } |
| 41 | 40 |
| 42 private: | 41 private: |
| 43 ui::DriWrapper* dri_; // Not owned. | 42 ui::DriWrapper* dri_; // Not owned. |
| 44 | 43 |
| 45 DISALLOW_COPY_AND_ASSIGN(MockScreenManager); | 44 DISALLOW_COPY_AND_ASSIGN(MockScreenManager); |
| 46 }; | 45 }; |
| 47 | 46 |
| 48 } // namespace | 47 } // namespace |
| 49 | 48 |
| 50 class DriSurfaceFactoryTest : public testing::Test { | 49 class DriSurfaceFactoryTest : public testing::Test { |
| 51 public: | 50 public: |
| 52 DriSurfaceFactoryTest() {} | 51 DriSurfaceFactoryTest() {} |
| 53 | 52 |
| 54 virtual void SetUp() OVERRIDE; | 53 virtual void SetUp() OVERRIDE; |
| 55 virtual void TearDown() OVERRIDE; | 54 virtual void TearDown() OVERRIDE; |
| 56 protected: | 55 protected: |
| 57 scoped_ptr<base::MessageLoop> message_loop_; | 56 scoped_ptr<base::MessageLoop> message_loop_; |
| 58 scoped_ptr<ui::MockDriWrapper> dri_; | 57 scoped_ptr<ui::MockDriWrapper> dri_; |
| 59 scoped_ptr<ui::MockSurfaceGenerator> surface_generator_; | 58 scoped_ptr<ui::DriBufferGenerator> buffer_generator_; |
| 60 scoped_ptr<MockScreenManager> screen_manager_; | 59 scoped_ptr<MockScreenManager> screen_manager_; |
| 61 scoped_ptr<ui::DriSurfaceFactory> factory_; | 60 scoped_ptr<ui::DriSurfaceFactory> factory_; |
| 62 | 61 |
| 63 private: | 62 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(DriSurfaceFactoryTest); | 63 DISALLOW_COPY_AND_ASSIGN(DriSurfaceFactoryTest); |
| 65 }; | 64 }; |
| 66 | 65 |
| 67 void DriSurfaceFactoryTest::SetUp() { | 66 void DriSurfaceFactoryTest::SetUp() { |
| 68 message_loop_.reset(new base::MessageLoopForUI); | 67 message_loop_.reset(new base::MessageLoopForUI); |
| 69 dri_.reset(new ui::MockDriWrapper(3)); | 68 dri_.reset(new ui::MockDriWrapper(3)); |
| 70 surface_generator_.reset(new ui::MockSurfaceGenerator(dri_.get())); | 69 buffer_generator_.reset(new ui::DriBufferGenerator(dri_.get())); |
| 71 screen_manager_.reset(new MockScreenManager(dri_.get(), | 70 screen_manager_.reset(new MockScreenManager(dri_.get(), |
| 72 surface_generator_.get())); | 71 buffer_generator_.get())); |
| 73 factory_.reset(new ui::DriSurfaceFactory(dri_.get(), screen_manager_.get())); | 72 factory_.reset(new ui::DriSurfaceFactory(dri_.get(), screen_manager_.get())); |
| 74 } | 73 } |
| 75 | 74 |
| 76 void DriSurfaceFactoryTest::TearDown() { | 75 void DriSurfaceFactoryTest::TearDown() { |
| 77 factory_.reset(); | 76 factory_.reset(); |
| 78 message_loop_.reset(); | 77 message_loop_.reset(); |
| 79 } | 78 } |
| 80 | 79 |
| 81 TEST_F(DriSurfaceFactoryTest, FailInitialization) { | 80 TEST_F(DriSurfaceFactoryTest, FailInitialization) { |
| 82 dri_->fail_init(); | 81 dri_->fail_init(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 113 | 112 |
| 114 SkPaint paint; | 113 SkPaint paint; |
| 115 paint.setColor(SK_ColorWHITE); | 114 paint.setColor(SK_ColorWHITE); |
| 116 SkRect rect = SkRect::MakeWH(kDefaultMode.hdisplay / 2, | 115 SkRect rect = SkRect::MakeWH(kDefaultMode.hdisplay / 2, |
| 117 kDefaultMode.vdisplay / 2); | 116 kDefaultMode.vdisplay / 2); |
| 118 surface->GetCanvas()->drawRect(rect, paint); | 117 surface->GetCanvas()->drawRect(rect, paint); |
| 119 surface->PresentCanvas( | 118 surface->PresentCanvas( |
| 120 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2)); | 119 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2)); |
| 121 | 120 |
| 122 SkBitmap image; | 121 SkBitmap image; |
| 123 // Buffers 0 and 1 are the cursor buffers and 2 and 3 are the surface buffers. | 122 // Buffers 0 and 1 are the cursor buffers, 2 is the modeset buffer, and |
| 124 // Buffer 3 is the backbuffer we just painted in, so we want to make sure its | 123 // 3 and 4 are the surface buffers. |
| 124 // Buffer 4 is the backbuffer we just painted in, so we want to make sure its | |
| 125 // contents are correct. | 125 // contents are correct. |
| 126 image.setInfo(dri_->buffers()[3]->getCanvas()->imageInfo()); | 126 image.setInfo(dri_->buffers()[4]->getCanvas()->imageInfo()); |
| 127 EXPECT_TRUE(dri_->buffers()[3]->getCanvas()->readPixels(&image, 0, 0)); | 127 EXPECT_TRUE(dri_->buffers()[4]->getCanvas()->readPixels(&image, 0, 0)); |
| 128 | 128 |
| 129 EXPECT_EQ(kDefaultMode.hdisplay, image.width()); | 129 EXPECT_EQ(kDefaultMode.hdisplay, image.width()); |
| 130 EXPECT_EQ(kDefaultMode.vdisplay, image.height()); | 130 EXPECT_EQ(kDefaultMode.vdisplay, image.height()); |
| 131 | 131 |
| 132 // Make sure the updates are correctly propagated to the native surface. | 132 // Make sure the updates are correctly propagated to the native surface. |
| 133 for (int i = 0; i < image.height(); ++i) { | 133 for (int i = 0; i < image.height(); ++i) { |
| 134 for (int j = 0; j < image.width(); ++j) { | 134 for (int j = 0; j < image.width(); ++j) { |
| 135 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2) | 135 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2) |
| 136 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i)); | 136 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i)); |
| 137 else | 137 else |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 167 for (int i = 0; i < cursor.height(); ++i) { | 167 for (int i = 0; i < cursor.height(); ++i) { |
| 168 for (int j = 0; j < cursor.width(); ++j) { | 168 for (int j = 0; j < cursor.width(); ++j) { |
| 169 if (j < info.width() && i < info.height()) | 169 if (j < info.width() && i < info.height()) |
| 170 EXPECT_EQ(SK_ColorWHITE, cursor.getColor(j, i)); | 170 EXPECT_EQ(SK_ColorWHITE, cursor.getColor(j, i)); |
| 171 else | 171 else |
| 172 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), | 172 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), |
| 173 cursor.getColor(j, i)); | 173 cursor.getColor(j, i)); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 } | 176 } |
| OLD | NEW |