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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "cc/output/software_frame_data.h" | 7 #include "cc/output/software_frame_data.h" |
8 #include "content/browser/compositor/software_output_device_ozone.h" | 8 #include "content/browser/compositor/software_output_device_ozone.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/skia/include/core/SkDevice.h" | 10 #include "third_party/skia/include/core/SkDevice.h" |
11 #include "third_party/skia/include/core/SkSurface.h" | 11 #include "third_party/skia/include/core/SkSurface.h" |
12 #include "ui/compositor/compositor.h" | 12 #include "ui/compositor/compositor.h" |
13 #include "ui/compositor/test/context_factories_for_test.h" | 13 #include "ui/compositor/test/context_factories_for_test.h" |
14 #include "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
15 #include "ui/gfx/skia_util.h" | 15 #include "ui/gfx/skia_util.h" |
16 #include "ui/gfx/vsync_provider.h" | 16 #include "ui/gfx/vsync_provider.h" |
17 #include "ui/gl/gl_implementation.h" | 17 #include "ui/gl/gl_implementation.h" |
18 #include "ui/ozone/public/surface_factory_ozone.h" | 18 #include "ui/ozone/public/ozone_platform.h" |
19 #include "ui/ozone/public/surface_ozone_canvas.h" | 19 #include "ui/ozone/public/surface_ozone_canvas.h" |
| 20 #include "ui/platform_window/platform_window.h" |
| 21 #include "ui/platform_window/platform_window_delegate.h" |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 class MockSurfaceOzone : public ui::SurfaceOzoneCanvas { | 25 class TestPlatformWindowDelegate : public ui::PlatformWindowDelegate { |
24 public: | 26 public: |
25 MockSurfaceOzone() {} | 27 TestPlatformWindowDelegate() : widget_(gfx::kNullAcceleratedWidget) {} |
26 virtual ~MockSurfaceOzone() {} | 28 ~TestPlatformWindowDelegate() override {} |
27 | 29 |
28 // ui::SurfaceOzoneCanvas overrides: | 30 gfx::AcceleratedWidget GetAcceleratedWidget() const { return widget_; } |
29 virtual void ResizeCanvas(const gfx::Size& size) override { | 31 |
30 surface_ = skia::AdoptRef(SkSurface::NewRaster( | 32 // ui::PlatformWindowDelegate: |
31 SkImageInfo::MakeN32Premul(size.width(), size.height()))); | 33 void OnBoundsChanged(const gfx::Rect& new_bounds) override {} |
| 34 void OnDamageRect(const gfx::Rect& damaged_region) override {} |
| 35 void DispatchEvent(ui::Event* event) override {} |
| 36 void OnCloseRequest() override {} |
| 37 void OnClosed() override {} |
| 38 void OnWindowStateChanged(ui::PlatformWindowState new_state) override {} |
| 39 void OnLostCapture() override {} |
| 40 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override { |
| 41 widget_ = widget; |
32 } | 42 } |
33 virtual skia::RefPtr<SkCanvas> GetCanvas() override { | 43 void OnActivationChanged(bool active) override {} |
34 return skia::SharePtr(surface_->getCanvas()); | |
35 } | |
36 virtual void PresentCanvas(const gfx::Rect& damage) override {} | |
37 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() override { | |
38 return scoped_ptr<gfx::VSyncProvider>(); | |
39 } | |
40 | 44 |
41 private: | 45 private: |
42 skia::RefPtr<SkSurface> surface_; | 46 gfx::AcceleratedWidget widget_; |
43 | 47 |
44 DISALLOW_COPY_AND_ASSIGN(MockSurfaceOzone); | 48 DISALLOW_COPY_AND_ASSIGN(TestPlatformWindowDelegate); |
45 }; | |
46 | |
47 class MockSurfaceFactoryOzone : public ui::SurfaceFactoryOzone { | |
48 public: | |
49 MockSurfaceFactoryOzone() {} | |
50 virtual ~MockSurfaceFactoryOzone() {} | |
51 | |
52 virtual bool LoadEGLGLES2Bindings( | |
53 AddGLLibraryCallback add_gl_library, | |
54 SetGLGetProcAddressProcCallback set_gl_get_proc_address) override { | |
55 return false; | |
56 } | |
57 virtual scoped_ptr<ui::SurfaceOzoneCanvas> CreateCanvasForWidget( | |
58 gfx::AcceleratedWidget widget) override { | |
59 return make_scoped_ptr<ui::SurfaceOzoneCanvas>(new MockSurfaceOzone()); | |
60 } | |
61 | |
62 private: | |
63 DISALLOW_COPY_AND_ASSIGN(MockSurfaceFactoryOzone); | |
64 }; | 49 }; |
65 | 50 |
66 } // namespace | 51 } // namespace |
67 | 52 |
68 class SoftwareOutputDeviceOzoneTest : public testing::Test { | 53 class SoftwareOutputDeviceOzoneTest : public testing::Test { |
69 public: | 54 public: |
70 SoftwareOutputDeviceOzoneTest(); | 55 SoftwareOutputDeviceOzoneTest(); |
71 virtual ~SoftwareOutputDeviceOzoneTest(); | 56 virtual ~SoftwareOutputDeviceOzoneTest(); |
72 | 57 |
73 virtual void SetUp() override; | 58 virtual void SetUp() override; |
74 virtual void TearDown() override; | 59 virtual void TearDown() override; |
75 | 60 |
76 protected: | 61 protected: |
77 scoped_ptr<content::SoftwareOutputDeviceOzone> output_device_; | 62 scoped_ptr<content::SoftwareOutputDeviceOzone> output_device_; |
78 bool enable_pixel_output_; | 63 bool enable_pixel_output_; |
79 | 64 |
80 private: | 65 private: |
81 scoped_ptr<ui::Compositor> compositor_; | 66 scoped_ptr<ui::Compositor> compositor_; |
82 scoped_ptr<base::MessageLoop> message_loop_; | 67 scoped_ptr<base::MessageLoop> message_loop_; |
83 scoped_ptr<ui::SurfaceFactoryOzone> surface_factory_; | 68 TestPlatformWindowDelegate window_delegate_; |
| 69 scoped_ptr<ui::PlatformWindow> window_; |
84 | 70 |
85 DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDeviceOzoneTest); | 71 DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDeviceOzoneTest); |
86 }; | 72 }; |
87 | 73 |
88 SoftwareOutputDeviceOzoneTest::SoftwareOutputDeviceOzoneTest() | 74 SoftwareOutputDeviceOzoneTest::SoftwareOutputDeviceOzoneTest() |
89 : enable_pixel_output_(false) { | 75 : enable_pixel_output_(false) { |
90 message_loop_.reset(new base::MessageLoopForUI); | 76 message_loop_.reset(new base::MessageLoopForUI); |
91 } | 77 } |
92 | 78 |
93 SoftwareOutputDeviceOzoneTest::~SoftwareOutputDeviceOzoneTest() { | 79 SoftwareOutputDeviceOzoneTest::~SoftwareOutputDeviceOzoneTest() { |
94 } | 80 } |
95 | 81 |
96 void SoftwareOutputDeviceOzoneTest::SetUp() { | 82 void SoftwareOutputDeviceOzoneTest::SetUp() { |
97 ui::ContextFactory* context_factory = | 83 ui::ContextFactory* context_factory = |
98 ui::InitializeContextFactoryForTests(enable_pixel_output_); | 84 ui::InitializeContextFactoryForTests(enable_pixel_output_); |
99 | 85 |
100 surface_factory_.reset(new MockSurfaceFactoryOzone()); | |
101 | |
102 const gfx::Size size(500, 400); | 86 const gfx::Size size(500, 400); |
103 const gfx::AcceleratedWidget kTestAcceleratedWidget = 1; | 87 window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( |
104 compositor_.reset( | 88 &window_delegate_, gfx::Rect(size)); |
105 new ui::Compositor(kTestAcceleratedWidget, | 89 compositor_.reset(new ui::Compositor(window_delegate_.GetAcceleratedWidget(), |
106 context_factory, | 90 context_factory, |
107 base::MessageLoopProxy::current())); | 91 base::MessageLoopProxy::current())); |
108 compositor_->SetScaleAndSize(1.0f, size); | 92 compositor_->SetScaleAndSize(1.0f, size); |
109 | 93 |
110 output_device_.reset(new content::SoftwareOutputDeviceOzone( | 94 output_device_.reset(new content::SoftwareOutputDeviceOzone( |
111 compositor_.get())); | 95 compositor_.get())); |
112 output_device_->Resize(size, 1.f); | 96 output_device_->Resize(size, 1.f); |
113 } | 97 } |
114 | 98 |
115 void SoftwareOutputDeviceOzoneTest::TearDown() { | 99 void SoftwareOutputDeviceOzoneTest::TearDown() { |
116 output_device_.reset(); | 100 output_device_.reset(); |
117 compositor_.reset(); | 101 compositor_.reset(); |
118 surface_factory_.reset(); | 102 window_.reset(); |
119 ui::TerminateContextFactoryForTests(); | 103 ui::TerminateContextFactoryForTests(); |
120 } | 104 } |
121 | 105 |
122 class SoftwareOutputDeviceOzonePixelTest | 106 class SoftwareOutputDeviceOzonePixelTest |
123 : public SoftwareOutputDeviceOzoneTest { | 107 : public SoftwareOutputDeviceOzoneTest { |
124 protected: | 108 protected: |
125 virtual void SetUp() override; | 109 virtual void SetUp() override; |
126 }; | 110 }; |
127 | 111 |
128 void SoftwareOutputDeviceOzonePixelTest::SetUp() { | 112 void SoftwareOutputDeviceOzonePixelTest::SetUp() { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 const SkPMColor black = SkPreMultiplyColor(SK_ColorBLACK); | 167 const SkPMColor black = SkPreMultiplyColor(SK_ColorBLACK); |
184 for (int i = 0; i < area.height(); ++i) { | 168 for (int i = 0; i < area.height(); ++i) { |
185 for (int j = 0; j < area.width(); ++j) { | 169 for (int j = 0; j < area.width(); ++j) { |
186 if (j < damage.width() && i < damage.height()) | 170 if (j < damage.width() && i < damage.height()) |
187 EXPECT_EQ(white, pixels[i * area.width() + j]); | 171 EXPECT_EQ(white, pixels[i * area.width() + j]); |
188 else | 172 else |
189 EXPECT_EQ(black, pixels[i * area.width() + j]); | 173 EXPECT_EQ(black, pixels[i * area.width() + j]); |
190 } | 174 } |
191 } | 175 } |
192 } | 176 } |
OLD | NEW |