Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: ui/ozone/platform/dri/dri_surface_factory_unittest.cc

Issue 106633002: GBM Ozone implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "ui/gfx/ozone/surface_factory_ozone.h" 12 #include "ui/gfx/ozone/surface_factory_ozone.h"
13 #include "ui/gfx/ozone/surface_ozone_canvas.h" 13 #include "ui/gfx/ozone/surface_ozone_canvas.h"
14 #include "ui/ozone/platform/dri/dri_buffer.h" 14 #include "ui/ozone/platform/dri/dri_buffer.h"
15 #include "ui/ozone/platform/dri/dri_surface.h" 15 #include "ui/ozone/platform/dri/dri_surface.h"
16 #include "ui/ozone/platform/dri/dri_surface_factory.h" 16 #include "ui/ozone/platform/dri/dri_surface_factory.h"
17 #include "ui/ozone/platform/dri/hardware_display_controller.h" 17 #include "ui/ozone/platform/dri/hardware_display_controller.h"
18 #include "ui/ozone/platform/dri/screen_manager.h" 18 #include "ui/ozone/platform/dri/screen_manager.h"
19 #include "ui/ozone/platform/dri/test/mock_dri_surface.h" 19 #include "ui/ozone/platform/dri/test/mock_dri_surface.h"
20 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h" 20 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h"
21 #include "ui/ozone/platform/dri/test/mock_surface_generator.h"
21 22
22 namespace { 23 namespace {
23 24
24 const drmModeModeInfo kDefaultMode = 25 const drmModeModeInfo kDefaultMode =
25 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; 26 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}};
26 27
27 // SSFO would normally allocate DRM resources. We can't rely on having a DRM 28 // SSFO would normally allocate DRM resources. We can't rely on having a DRM
28 // backend to allocate and display our buffers. Thus, we replace these 29 // backend to allocate and display our buffers. Thus, we replace these
29 // resources with stubs. For DRM calls, we simply use stubs that do nothing and 30 // resources with stubs. For DRM calls, we simply use stubs that do nothing and
30 // for buffers we use the default SkBitmap allocator. 31 // for buffers we use the default SkBitmap allocator.
(...skipping 15 matching lines...) Expand all
46 } 47 }
47 48
48 ui::DriWrapper* dri_; 49 ui::DriWrapper* dri_;
49 std::vector<ui::MockDriSurface*> surfaces_; // Not owned. 50 std::vector<ui::MockDriSurface*> surfaces_; // Not owned.
50 51
51 DISALLOW_COPY_AND_ASSIGN(MockDriSurfaceFactory); 52 DISALLOW_COPY_AND_ASSIGN(MockDriSurfaceFactory);
52 }; 53 };
53 54
54 class MockScreenManager : public ui::ScreenManager { 55 class MockScreenManager : public ui::ScreenManager {
55 public: 56 public:
56 MockScreenManager(ui::DriWrapper* dri) 57 MockScreenManager(ui::DriWrapper* dri,
57 : ScreenManager(dri), 58 ui::ScanoutSurfaceGenerator* surface_generator)
59 : ScreenManager(dri, surface_generator),
58 dri_(dri) {} 60 dri_(dri) {}
59 virtual ~MockScreenManager() {} 61 virtual ~MockScreenManager() {}
60 62
61 const std::vector<ui::MockDriSurface*>& get_surfaces() const {
62 return surfaces_;
63 }
64
65 // Normally we'd use DRM to figure out the controller configuration. But we 63 // Normally we'd use DRM to figure out the controller configuration. But we
66 // can't use DRM in unit tests, so we just create a fake configuration. 64 // can't use DRM in unit tests, so we just create a fake configuration.
67 virtual void ForceInitializationOfPrimaryDisplay() OVERRIDE { 65 virtual void ForceInitializationOfPrimaryDisplay() OVERRIDE {
68 ConfigureDisplayController(1, 2, kDefaultMode); 66 ConfigureDisplayController(1, 2, kDefaultMode);
69 } 67 }
70 virtual ui::DriSurface* CreateSurface(const gfx::Size& size) OVERRIDE {
71 ui::MockDriSurface* surface = new ui::MockDriSurface(dri_, size);
72 surfaces_.push_back(surface);
73 return surface;
74 }
75 68
76 private: 69 private:
77 ui::DriWrapper* dri_; // Not owned. 70 ui::DriWrapper* dri_; // Not owned.
78 std::vector<ui::MockDriSurface*> surfaces_; // Not owned. 71 std::vector<ui::MockDriSurface*> surfaces_; // Not owned.
79 72
80 DISALLOW_COPY_AND_ASSIGN(MockScreenManager); 73 DISALLOW_COPY_AND_ASSIGN(MockScreenManager);
81 }; 74 };
82 75
83 } // namespace 76 } // namespace
84 77
85 class DriSurfaceFactoryTest : public testing::Test { 78 class DriSurfaceFactoryTest : public testing::Test {
86 public: 79 public:
87 DriSurfaceFactoryTest() {} 80 DriSurfaceFactoryTest() {}
88 81
89 virtual void SetUp() OVERRIDE; 82 virtual void SetUp() OVERRIDE;
90 virtual void TearDown() OVERRIDE; 83 virtual void TearDown() OVERRIDE;
91 protected: 84 protected:
92 scoped_ptr<base::MessageLoop> message_loop_; 85 scoped_ptr<base::MessageLoop> message_loop_;
93 scoped_ptr<ui::MockDriWrapper> dri_; 86 scoped_ptr<ui::MockDriWrapper> dri_;
87 scoped_ptr<ui::MockSurfaceGenerator> surface_generator_;
94 scoped_ptr<MockScreenManager> screen_manager_; 88 scoped_ptr<MockScreenManager> screen_manager_;
95 scoped_ptr<MockDriSurfaceFactory> factory_; 89 scoped_ptr<MockDriSurfaceFactory> factory_;
96 90
97 private: 91 private:
98 DISALLOW_COPY_AND_ASSIGN(DriSurfaceFactoryTest); 92 DISALLOW_COPY_AND_ASSIGN(DriSurfaceFactoryTest);
99 }; 93 };
100 94
101 void DriSurfaceFactoryTest::SetUp() { 95 void DriSurfaceFactoryTest::SetUp() {
102 message_loop_.reset(new base::MessageLoopForUI); 96 message_loop_.reset(new base::MessageLoopForUI);
103 dri_.reset(new ui::MockDriWrapper(3)); 97 dri_.reset(new ui::MockDriWrapper(3));
104 screen_manager_.reset(new MockScreenManager(dri_.get())); 98 surface_generator_.reset(new ui::MockSurfaceGenerator(dri_.get()));
99 screen_manager_.reset(new MockScreenManager(dri_.get(),
100 surface_generator_.get()));
105 factory_.reset(new MockDriSurfaceFactory(dri_.get(), screen_manager_.get())); 101 factory_.reset(new MockDriSurfaceFactory(dri_.get(), screen_manager_.get()));
106 } 102 }
107 103
108 void DriSurfaceFactoryTest::TearDown() { 104 void DriSurfaceFactoryTest::TearDown() {
109 factory_.reset(); 105 factory_.reset();
110 message_loop_.reset(); 106 message_loop_.reset();
111 } 107 }
112 108
113 TEST_F(DriSurfaceFactoryTest, FailInitialization) { 109 TEST_F(DriSurfaceFactoryTest, FailInitialization) {
114 dri_->fail_init(); 110 dri_->fail_init();
(...skipping 25 matching lines...) Expand all
140 scoped_ptr<gfx::SurfaceOzoneCanvas> surface = 136 scoped_ptr<gfx::SurfaceOzoneCanvas> surface =
141 factory_->CreateCanvasForWidget(w); 137 factory_->CreateCanvasForWidget(w);
142 138
143 surface->ResizeCanvas( 139 surface->ResizeCanvas(
144 gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay)); 140 gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay));
145 surface->GetCanvas()->drawColor(SK_ColorWHITE); 141 surface->GetCanvas()->drawColor(SK_ColorWHITE);
146 surface->PresentCanvas( 142 surface->PresentCanvas(
147 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2)); 143 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2));
148 144
149 const std::vector<ui::DriBuffer*>& bitmaps = 145 const std::vector<ui::DriBuffer*>& bitmaps =
150 screen_manager_->get_surfaces()[0]->bitmaps(); 146 surface_generator_->surfaces()[0]->bitmaps();
151 147
152 SkBitmap image; 148 SkBitmap image;
153 bitmaps[1]->canvas()->readPixels(&image, 0, 0); 149 bitmaps[1]->canvas()->readPixels(&image, 0, 0);
154 150
155 // Make sure the updates are correctly propagated to the native surface. 151 // Make sure the updates are correctly propagated to the native surface.
156 for (int i = 0; i < image.height(); ++i) { 152 for (int i = 0; i < image.height(); ++i) {
157 for (int j = 0; j < image.width(); ++j) { 153 for (int j = 0; j < image.width(); ++j) {
158 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2) 154 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2)
159 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i)); 155 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i));
160 else 156 else
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 for (int i = 0; i < cursor.height(); ++i) { 192 for (int i = 0; i < cursor.height(); ++i) {
197 for (int j = 0; j < cursor.width(); ++j) { 193 for (int j = 0; j < cursor.width(); ++j) {
198 if (j < info.width() && i < info.height()) 194 if (j < info.width() && i < info.height())
199 EXPECT_EQ(SK_ColorWHITE, cursor.getColor(j, i)); 195 EXPECT_EQ(SK_ColorWHITE, cursor.getColor(j, i));
200 else 196 else
201 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), 197 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT),
202 cursor.getColor(j, i)); 198 cursor.getColor(j, i));
203 } 199 }
204 } 200 }
205 } 201 }
OLDNEW
« no previous file with comments | « ui/ozone/platform/dri/dri_surface_factory.cc ('k') | ui/ozone/platform/dri/dri_surface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698