| 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" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 class DriSurfaceFactoryTest : public testing::Test { | 56 class DriSurfaceFactoryTest : public testing::Test { |
| 57 public: | 57 public: |
| 58 DriSurfaceFactoryTest() {} | 58 DriSurfaceFactoryTest() {} |
| 59 | 59 |
| 60 virtual void SetUp() override; | 60 virtual void SetUp() override; |
| 61 virtual void TearDown() override; | 61 virtual void TearDown() override; |
| 62 |
| 62 protected: | 63 protected: |
| 63 scoped_ptr<base::MessageLoop> message_loop_; | 64 scoped_ptr<base::MessageLoop> message_loop_; |
| 64 scoped_ptr<ui::MockDriWrapper> dri_; | 65 scoped_ptr<ui::MockDriWrapper> dri_; |
| 65 scoped_ptr<ui::DriBufferGenerator> buffer_generator_; | 66 scoped_ptr<ui::DriBufferGenerator> buffer_generator_; |
| 66 scoped_ptr<MockScreenManager> screen_manager_; | 67 scoped_ptr<MockScreenManager> screen_manager_; |
| 67 scoped_ptr<ui::DriSurfaceFactory> factory_; | 68 scoped_ptr<ui::DriSurfaceFactory> factory_; |
| 68 scoped_ptr<ui::DriWindowDelegateManager> window_delegate_manager_; | 69 scoped_ptr<ui::DriWindowDelegateManager> window_delegate_manager_; |
| 69 | 70 |
| 70 private: | 71 private: |
| 71 DISALLOW_COPY_AND_ASSIGN(DriSurfaceFactoryTest); | 72 DISALLOW_COPY_AND_ASSIGN(DriSurfaceFactoryTest); |
| 72 }; | 73 }; |
| 73 | 74 |
| 74 void DriSurfaceFactoryTest::SetUp() { | 75 void DriSurfaceFactoryTest::SetUp() { |
| 75 message_loop_.reset(new base::MessageLoopForUI); | 76 message_loop_.reset(new base::MessageLoopForUI); |
| 76 dri_.reset(new ui::MockDriWrapper(3)); | 77 dri_.reset(new ui::MockDriWrapper(3)); |
| 77 buffer_generator_.reset(new ui::DriBufferGenerator(dri_.get())); | 78 buffer_generator_.reset(new ui::DriBufferGenerator(dri_.get())); |
| 78 screen_manager_.reset(new MockScreenManager(dri_.get(), | 79 screen_manager_.reset(new MockScreenManager(dri_.get(), |
| 79 buffer_generator_.get())); | 80 buffer_generator_.get())); |
| 80 window_delegate_manager_.reset(new ui::DriWindowDelegateManager()); | 81 window_delegate_manager_.reset(new ui::DriWindowDelegateManager()); |
| 81 factory_.reset(new ui::DriSurfaceFactory( | 82 factory_.reset(new ui::DriSurfaceFactory(dri_.get(), screen_manager_.get(), |
| 82 dri_.get(), screen_manager_.get(), window_delegate_manager_.get())); | 83 window_delegate_manager_.get())); |
| 83 | 84 |
| 84 scoped_ptr<ui::DriWindowDelegate> window_delegate( | 85 scoped_ptr<ui::DriWindowDelegate> window_delegate( |
| 85 new ui::DriWindowDelegateImpl(ui::DriSurfaceFactory::kDefaultWidgetHandle, | 86 new ui::DriWindowDelegateImpl(ui::DriSurfaceFactory::kDefaultWidgetHandle, |
| 86 screen_manager_.get())); | 87 screen_manager_.get())); |
| 87 window_delegate->Initialize(); | 88 window_delegate->Initialize(); |
| 88 window_delegate_manager_->AddWindowDelegate( | 89 window_delegate_manager_->AddWindowDelegate( |
| 89 ui::DriSurfaceFactory::kDefaultWidgetHandle, window_delegate.Pass()); | 90 ui::DriSurfaceFactory::kDefaultWidgetHandle, window_delegate.Pass()); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void DriSurfaceFactoryTest::TearDown() { | 93 void DriSurfaceFactoryTest::TearDown() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 127 |
| 127 SkBitmap image; | 128 SkBitmap image; |
| 128 SkImageInfo info = SkImageInfo::Make( | 129 SkImageInfo info = SkImageInfo::Make( |
| 129 6, 4, kN32_SkColorType, kPremul_SkAlphaType); | 130 6, 4, kN32_SkColorType, kPremul_SkAlphaType); |
| 130 image.allocPixels(info); | 131 image.allocPixels(info); |
| 131 image.eraseColor(SK_ColorWHITE); | 132 image.eraseColor(SK_ColorWHITE); |
| 132 | 133 |
| 133 std::vector<SkBitmap> cursor_bitmaps; | 134 std::vector<SkBitmap> cursor_bitmaps; |
| 134 cursor_bitmaps.push_back(image); | 135 cursor_bitmaps.push_back(image); |
| 135 factory_->SetHardwareCursor(ui::DriSurfaceFactory::kDefaultWidgetHandle, | 136 factory_->SetHardwareCursor(ui::DriSurfaceFactory::kDefaultWidgetHandle, |
| 136 cursor_bitmaps, | 137 cursor_bitmaps, gfx::Point(4, 2), 0); |
| 137 gfx::Point(4, 2), | |
| 138 0); | |
| 139 | 138 |
| 140 SkBitmap cursor; | 139 SkBitmap cursor; |
| 141 // Buffers 0 and 1 are the cursor buffers. | 140 // Buffers 0 and 1 are the cursor buffers. |
| 142 cursor.setInfo(dri_->buffers()[1]->getCanvas()->imageInfo()); | 141 cursor.setInfo(dri_->buffers()[1]->getCanvas()->imageInfo()); |
| 143 EXPECT_TRUE(dri_->buffers()[1]->getCanvas()->readPixels(&cursor, 0, 0)); | 142 EXPECT_TRUE(dri_->buffers()[1]->getCanvas()->readPixels(&cursor, 0, 0)); |
| 144 | 143 |
| 145 // Check that the frontbuffer is displaying the right image as set above. | 144 // Check that the frontbuffer is displaying the right image as set above. |
| 146 for (int i = 0; i < cursor.height(); ++i) { | 145 for (int i = 0; i < cursor.height(); ++i) { |
| 147 for (int j = 0; j < cursor.width(); ++j) { | 146 for (int j = 0; j < cursor.width(); ++j) { |
| 148 if (j < info.width() && i < info.height()) | 147 if (j < info.width() && i < info.height()) |
| 149 EXPECT_EQ(SK_ColorWHITE, cursor.getColor(j, i)); | 148 EXPECT_EQ(SK_ColorWHITE, cursor.getColor(j, i)); |
| 150 else | 149 else |
| 151 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), | 150 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), |
| 152 cursor.getColor(j, i)); | 151 cursor.getColor(j, i)); |
| 153 } | 152 } |
| 154 } | 153 } |
| 155 } | 154 } |
| OLD | NEW |