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
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop/message_loop.h"
7 #include "cc/output/software_frame_data.h"
8 #include "content/browser/compositor/software_output_device_ozone.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/skia/include/core/SkDevice.h"
11 #include "third_party/skia/include/core/SkSurface.h"
12 #include "ui/compositor/compositor.h"
13 #include "ui/compositor/test/context_factories_for_test.h"
14 #include "ui/gfx/geometry/size.h"
15 #include "ui/gfx/skia_util.h"
16 #include "ui/gfx/vsync_provider.h"
17 #include "ui/gl/gl_implementation.h"
18 #include "ui/ozone/public/ozone_platform.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"
25 class TestPlatformWindowDelegate
: public ui::PlatformWindowDelegate
{
27 TestPlatformWindowDelegate() : widget_(gfx::kNullAcceleratedWidget
) {}
28 ~TestPlatformWindowDelegate() override
{}
30 gfx::AcceleratedWidget
GetAcceleratedWidget() const { return widget_
; }
32 // ui::PlatformWindowDelegate:
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
{
43 void OnActivationChanged(bool active
) override
{}
46 gfx::AcceleratedWidget widget_
;
48 DISALLOW_COPY_AND_ASSIGN(TestPlatformWindowDelegate
);
53 class SoftwareOutputDeviceOzoneTest
: public testing::Test
{
55 SoftwareOutputDeviceOzoneTest();
56 ~SoftwareOutputDeviceOzoneTest() override
;
58 void SetUp() override
;
59 void TearDown() override
;
62 scoped_ptr
<content::SoftwareOutputDeviceOzone
> output_device_
;
63 bool enable_pixel_output_
;
66 scoped_ptr
<ui::Compositor
> compositor_
;
67 scoped_ptr
<base::MessageLoop
> message_loop_
;
68 TestPlatformWindowDelegate window_delegate_
;
69 scoped_ptr
<ui::PlatformWindow
> window_
;
71 DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDeviceOzoneTest
);
74 SoftwareOutputDeviceOzoneTest::SoftwareOutputDeviceOzoneTest()
75 : enable_pixel_output_(false) {
76 message_loop_
.reset(new base::MessageLoopForUI
);
79 SoftwareOutputDeviceOzoneTest::~SoftwareOutputDeviceOzoneTest() {
82 void SoftwareOutputDeviceOzoneTest::SetUp() {
83 ui::ContextFactory
* context_factory
=
84 ui::InitializeContextFactoryForTests(enable_pixel_output_
);
86 const gfx::Size
size(500, 400);
87 window_
= ui::OzonePlatform::GetInstance()->CreatePlatformWindow(
88 &window_delegate_
, gfx::Rect(size
));
89 compositor_
.reset(new ui::Compositor(window_delegate_
.GetAcceleratedWidget(),
91 base::MessageLoopProxy::current()));
92 compositor_
->SetScaleAndSize(1.0f
, size
);
94 output_device_
.reset(new content::SoftwareOutputDeviceOzone(
96 output_device_
->Resize(size
, 1.f
);
99 void SoftwareOutputDeviceOzoneTest::TearDown() {
100 output_device_
.reset();
103 ui::TerminateContextFactoryForTests();
106 class SoftwareOutputDeviceOzonePixelTest
107 : public SoftwareOutputDeviceOzoneTest
{
109 void SetUp() override
;
112 void SoftwareOutputDeviceOzonePixelTest::SetUp() {
113 enable_pixel_output_
= true;
114 SoftwareOutputDeviceOzoneTest::SetUp();
117 TEST_F(SoftwareOutputDeviceOzoneTest
, CheckCorrectResizeBehavior
) {
118 gfx::Rect
damage(0, 0, 100, 100);
119 gfx::Size
size(200, 100);
121 output_device_
->Resize(size
, 1.f
);
123 SkCanvas
* canvas
= output_device_
->BeginPaint(damage
);
124 gfx::Size
canvas_size(canvas
->getDeviceSize().width(),
125 canvas
->getDeviceSize().height());
126 EXPECT_EQ(size
.ToString(), canvas_size
.ToString());
128 size
.SetSize(1000, 500);
130 output_device_
->Resize(size
, 1.f
);
132 canvas
= output_device_
->BeginPaint(damage
);
133 canvas_size
.SetSize(canvas
->getDeviceSize().width(),
134 canvas
->getDeviceSize().height());
135 EXPECT_EQ(size
.ToString(), canvas_size
.ToString());