Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / content / browser / compositor / software_output_device_ozone_unittest.cc
blob8f3febf7d9f7260d085af1220c2672c6cb4a2333
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 "base/thread_task_runner_handle.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"
23 namespace {
25 class TestPlatformWindowDelegate : public ui::PlatformWindowDelegate {
26 public:
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,
41 float device_pixel_ratio) override {
42 widget_ = widget;
44 void OnActivationChanged(bool active) override {}
46 private:
47 gfx::AcceleratedWidget widget_;
49 DISALLOW_COPY_AND_ASSIGN(TestPlatformWindowDelegate);
52 } // namespace
54 class SoftwareOutputDeviceOzoneTest : public testing::Test {
55 public:
56 SoftwareOutputDeviceOzoneTest();
57 ~SoftwareOutputDeviceOzoneTest() override;
59 void SetUp() override;
60 void TearDown() override;
62 protected:
63 scoped_ptr<content::SoftwareOutputDeviceOzone> output_device_;
64 bool enable_pixel_output_;
66 private:
67 scoped_ptr<ui::Compositor> compositor_;
68 scoped_ptr<base::MessageLoop> message_loop_;
69 TestPlatformWindowDelegate window_delegate_;
70 scoped_ptr<ui::PlatformWindow> window_;
72 DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDeviceOzoneTest);
75 SoftwareOutputDeviceOzoneTest::SoftwareOutputDeviceOzoneTest()
76 : enable_pixel_output_(false) {
77 message_loop_.reset(new base::MessageLoopForUI);
80 SoftwareOutputDeviceOzoneTest::~SoftwareOutputDeviceOzoneTest() {
83 void SoftwareOutputDeviceOzoneTest::SetUp() {
84 ui::ContextFactory* context_factory =
85 ui::InitializeContextFactoryForTests(enable_pixel_output_);
87 const gfx::Size size(500, 400);
88 window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow(
89 &window_delegate_, gfx::Rect(size));
90 compositor_.reset(
91 new ui::Compositor(context_factory, base::ThreadTaskRunnerHandle::Get()));
92 compositor_->SetAcceleratedWidgetAndStartCompositor(
93 window_delegate_.GetAcceleratedWidget());
94 compositor_->SetScaleAndSize(1.0f, size);
96 output_device_.reset(new content::SoftwareOutputDeviceOzone(
97 compositor_.get()));
98 output_device_->Resize(size, 1.f);
101 void SoftwareOutputDeviceOzoneTest::TearDown() {
102 output_device_.reset();
103 compositor_.reset();
104 window_.reset();
105 ui::TerminateContextFactoryForTests();
108 class SoftwareOutputDeviceOzonePixelTest
109 : public SoftwareOutputDeviceOzoneTest {
110 protected:
111 void SetUp() override;
114 void SoftwareOutputDeviceOzonePixelTest::SetUp() {
115 enable_pixel_output_ = true;
116 SoftwareOutputDeviceOzoneTest::SetUp();
119 TEST_F(SoftwareOutputDeviceOzoneTest, CheckCorrectResizeBehavior) {
120 gfx::Rect damage(0, 0, 100, 100);
121 gfx::Size size(200, 100);
122 // Reduce size.
123 output_device_->Resize(size, 1.f);
125 SkCanvas* canvas = output_device_->BeginPaint(damage);
126 gfx::Size canvas_size(canvas->getDeviceSize().width(),
127 canvas->getDeviceSize().height());
128 EXPECT_EQ(size.ToString(), canvas_size.ToString());
130 size.SetSize(1000, 500);
131 // Increase size.
132 output_device_->Resize(size, 1.f);
134 canvas = output_device_->BeginPaint(damage);
135 canvas_size.SetSize(canvas->getDeviceSize().width(),
136 canvas->getDeviceSize().height());
137 EXPECT_EQ(size.ToString(), canvas_size.ToString());