Commit 2e047e72 authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

viz: SoftwareOutputDeviceOzoneTest: use test impl of ozone canvas.

The SoftwareOutputDeviceOzoneTest.CheckCorrectResizeBehavior should
only test SoftwareOutputDevice and it doesn't matter if ozone
platforms support that or not. Thus, add a test impl of
ozone canvas so that we don't have to check what platform the
test is run on and we don't have to expose the platform's name.

Change-Id: I3263a0267580df125c0b6ea8348cad6ef3a0461a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2124374Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#754479}
parent 8ca2a9e8
......@@ -6,9 +6,9 @@
#include <memory>
#include "base/macros.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "ui/compositor/compositor.h"
......@@ -29,32 +29,25 @@ namespace viz {
namespace {
class TestPlatformWindowDelegate : public ui::PlatformWindowDelegate {
class TestSurfaceOzoneCanvas : public ui::SurfaceOzoneCanvas {
public:
TestPlatformWindowDelegate() : widget_(gfx::kNullAcceleratedWidget) {}
~TestPlatformWindowDelegate() override {}
gfx::AcceleratedWidget GetAcceleratedWidget() const { return widget_; }
// ui::PlatformWindowDelegate:
void OnBoundsChanged(const gfx::Rect& new_bounds) override {}
void OnDamageRect(const gfx::Rect& damaged_region) override {}
void DispatchEvent(ui::Event* event) override {}
void OnCloseRequest() override {}
void OnClosed() override {}
void OnWindowStateChanged(ui::PlatformWindowState new_state) override {}
void OnLostCapture() override {}
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override {
widget_ = widget;
TestSurfaceOzoneCanvas() = default;
~TestSurfaceOzoneCanvas() override = default;
// ui::SurfaceOzoneCanvas override:
SkCanvas* GetCanvas() override { return surface_->getCanvas(); }
void ResizeCanvas(const gfx::Size& viewport_size) override {
surface_ = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(
viewport_size.width(), viewport_size.height()));
}
std::unique_ptr<gfx::VSyncProvider> CreateVSyncProvider() override {
return nullptr;
}
void OnAcceleratedWidgetDestroyed() override {}
void OnActivationChanged(bool active) override {}
void OnMouseEnter() override {}
private:
gfx::AcceleratedWidget widget_;
MOCK_METHOD1(PresentCanvas, void(const gfx::Rect& damage));
DISALLOW_COPY_AND_ASSIGN(TestPlatformWindowDelegate);
private:
sk_sp<SkSurface> surface_;
};
} // namespace
......@@ -63,6 +56,9 @@ class SoftwareOutputDeviceOzoneTest : public testing::Test {
public:
SoftwareOutputDeviceOzoneTest();
~SoftwareOutputDeviceOzoneTest() override;
SoftwareOutputDeviceOzoneTest(const SoftwareOutputDeviceOzoneTest&) = delete;
SoftwareOutputDeviceOzoneTest& operator=(
const SoftwareOutputDeviceOzoneTest&) = delete;
void SetUp() override;
void TearDown() override;
......@@ -71,95 +67,49 @@ class SoftwareOutputDeviceOzoneTest : public testing::Test {
std::unique_ptr<SoftwareOutputDeviceOzone> output_device_;
bool enable_pixel_output_ = false;
private:
std::unique_ptr<ui::TestContextFactories> context_factories_;
std::unique_ptr<ui::Compositor> compositor_;
TestPlatformWindowDelegate window_delegate_;
DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDeviceOzoneTest);
TestSurfaceOzoneCanvas* surface_ozone_ = nullptr;
};
SoftwareOutputDeviceOzoneTest::SoftwareOutputDeviceOzoneTest() = default;
SoftwareOutputDeviceOzoneTest::~SoftwareOutputDeviceOzoneTest() = default;
void SoftwareOutputDeviceOzoneTest::SetUp() {
ui::OzonePlatform::InitParams params;
params.single_process = true;
ui::OzonePlatform::InitializeForUI(params);
ui::OzonePlatform::InitializeForGPU(params);
ui::PlatformWindowInitProperties properties;
properties.bounds = gfx::Rect(800, 600, 100, 100);
auto platform_window = ui::OzonePlatform::GetInstance()->CreatePlatformWindow(
&window_delegate_, std::move(properties));
platform_window->Show();
context_factories_ =
std::make_unique<ui::TestContextFactories>(enable_pixel_output_);
const gfx::Size size(500, 400);
compositor_ = std::make_unique<ui::Compositor>(
FrameSinkId(1, 1), context_factories_->GetContextFactory(),
base::ThreadTaskRunnerHandle::Get(), false /* enable_pixel_canvas */);
compositor_->SetAcceleratedWidget(window_delegate_.GetAcceleratedWidget());
compositor_->SetScaleAndSize(1.0f, size, LocalSurfaceIdAllocation());
ui::SurfaceFactoryOzone* factory =
ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone();
std::unique_ptr<ui::PlatformWindowSurface> platform_window_surface =
factory->CreatePlatformWindowSurface(compositor_->widget());
std::unique_ptr<ui::SurfaceOzoneCanvas> surface_ozone =
factory->CreateCanvasForWidget(compositor_->widget(), nullptr);
if (!surface_ozone) {
LOG(ERROR) << "SurfaceOzoneCanvas not constructible on this platform";
} else {
output_device_ = std::make_unique<SoftwareOutputDeviceOzone>(
std::move(platform_window_surface), std::move(surface_ozone));
}
if (output_device_)
output_device_->Resize(size, 1.f);
std::unique_ptr<TestSurfaceOzoneCanvas> surface_ozone =
std::make_unique<TestSurfaceOzoneCanvas>();
surface_ozone_ = surface_ozone.get();
output_device_ = std::make_unique<SoftwareOutputDeviceOzone>(
nullptr, std::move(surface_ozone));
}
void SoftwareOutputDeviceOzoneTest::TearDown() {
output_device_.reset();
compositor_.reset();
context_factories_.reset();
}
class SoftwareOutputDeviceOzonePixelTest
: public SoftwareOutputDeviceOzoneTest {
protected:
void SetUp() override;
};
void SoftwareOutputDeviceOzonePixelTest::SetUp() {
enable_pixel_output_ = true;
SoftwareOutputDeviceOzoneTest::SetUp();
}
TEST_F(SoftwareOutputDeviceOzoneTest, CheckCorrectResizeBehavior) {
// Check if software rendering mode is not supported.
if (!output_device_)
return;
gfx::Rect damage(0, 0, 100, 100);
gfx::Size size(200, 100);
constexpr gfx::Size size(200, 100);
// Reduce size.
output_device_->Resize(size, 1.f);
SkCanvas* canvas = output_device_->BeginPaint(damage);
constexpr gfx::Rect damage1(0, 0, 100, 100);
SkCanvas* canvas = output_device_->BeginPaint(damage1);
ASSERT_TRUE(canvas);
gfx::Size canvas_size(canvas->getBaseLayerSize().width(),
canvas->getBaseLayerSize().height());
EXPECT_EQ(size.ToString(), canvas_size.ToString());
EXPECT_EQ(size, canvas_size);
EXPECT_CALL(*surface_ozone_, PresentCanvas(damage1)).Times(1);
output_device_->EndPaint();
size.SetSize(1000, 500);
constexpr gfx::Size size2(1000, 500);
// Increase size.
output_device_->Resize(size, 1.f);
output_device_->Resize(size2, 1.f);
canvas = output_device_->BeginPaint(damage);
constexpr gfx::Rect damage2(0, 0, 50, 60);
canvas = output_device_->BeginPaint(damage2);
canvas_size.SetSize(canvas->getBaseLayerSize().width(),
canvas->getBaseLayerSize().height());
EXPECT_EQ(size.ToString(), canvas_size.ToString());
EXPECT_EQ(size2, canvas_size);
EXPECT_CALL(*surface_ozone_, PresentCanvas(damage2)).Times(1);
output_device_->EndPaint();
}
} // namespace viz
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment