Commit 6641f57b authored by spang@chromium.org's avatar spang@chromium.org

ozone: test: Convert to PlatformWindow

A test window is just a path to write an image file to. Each window has
a unique image path.

BUG=392280
TEST=built with chromeos==1 use_ozone==1 & ran test platform
NOTRY=true

depends on https://codereview.chromium.org/375053002/

Review URL: https://codereview.chromium.org/377973005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283875 0039d316-1c4b-4281-b951-d872f2087c98
parent b083507a
...@@ -8,9 +8,10 @@ ...@@ -8,9 +8,10 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "ui/events/ozone/device/device_manager.h" #include "ui/events/ozone/device/device_manager.h"
#include "ui/events/ozone/evdev/event_factory_evdev.h" #include "ui/events/ozone/evdev/event_factory_evdev.h"
#include "ui/ozone/common/window/platform_window_compat.h"
#include "ui/ozone/platform/test/file_surface_factory.h"
#include "ui/ozone/platform/test/test_cursor_factory.h" #include "ui/ozone/platform/test/test_cursor_factory.h"
#include "ui/ozone/platform/test/test_window.h"
#include "ui/ozone/platform/test/test_window_manager.h"
#include "ui/ozone/public/cursor_factory_ozone.h"
#include "ui/ozone/public/gpu_platform_support.h" #include "ui/ozone/public/gpu_platform_support.h"
#include "ui/ozone/public/gpu_platform_support_host.h" #include "ui/ozone/public/gpu_platform_support_host.h"
#include "ui/ozone/public/ozone_platform.h" #include "ui/ozone/public/ozone_platform.h"
...@@ -35,7 +36,7 @@ class OzonePlatformTest : public OzonePlatform { ...@@ -35,7 +36,7 @@ class OzonePlatformTest : public OzonePlatform {
// OzonePlatform: // OzonePlatform:
virtual ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() OVERRIDE { virtual ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() OVERRIDE {
return surface_factory_ozone_.get(); return window_manager_.get();
} }
virtual EventFactoryOzone* GetEventFactoryOzone() OVERRIDE { virtual EventFactoryOzone* GetEventFactoryOzone() OVERRIDE {
return event_factory_ozone_.get(); return event_factory_ozone_.get();
...@@ -53,7 +54,7 @@ class OzonePlatformTest : public OzonePlatform { ...@@ -53,7 +54,7 @@ class OzonePlatformTest : public OzonePlatform {
PlatformWindowDelegate* delegate, PlatformWindowDelegate* delegate,
const gfx::Rect& bounds) OVERRIDE { const gfx::Rect& bounds) OVERRIDE {
return make_scoped_ptr<PlatformWindow>( return make_scoped_ptr<PlatformWindow>(
new PlatformWindowCompat(delegate, bounds)); new TestWindow(delegate, window_manager_.get(), bounds));
} }
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -70,7 +71,8 @@ class OzonePlatformTest : public OzonePlatform { ...@@ -70,7 +71,8 @@ class OzonePlatformTest : public OzonePlatform {
virtual void InitializeUI() OVERRIDE { virtual void InitializeUI() OVERRIDE {
device_manager_ = CreateDeviceManager(); device_manager_ = CreateDeviceManager();
surface_factory_ozone_.reset(new FileSurfaceFactory(file_path_)); window_manager_.reset(new TestWindowManager(file_path_));
window_manager_->Initialize();
event_factory_ozone_.reset( event_factory_ozone_.reset(
new EventFactoryEvdev(NULL, device_manager_.get())); new EventFactoryEvdev(NULL, device_manager_.get()));
cursor_factory_ozone_.reset(new TestCursorFactory()); cursor_factory_ozone_.reset(new TestCursorFactory());
...@@ -83,7 +85,7 @@ class OzonePlatformTest : public OzonePlatform { ...@@ -83,7 +85,7 @@ class OzonePlatformTest : public OzonePlatform {
private: private:
scoped_ptr<DeviceManager> device_manager_; scoped_ptr<DeviceManager> device_manager_;
scoped_ptr<FileSurfaceFactory> surface_factory_ozone_; scoped_ptr<TestWindowManager> window_manager_;
scoped_ptr<EventFactoryEvdev> event_factory_ozone_; scoped_ptr<EventFactoryEvdev> event_factory_ozone_;
scoped_ptr<CursorFactoryOzone> cursor_factory_ozone_; scoped_ptr<CursorFactoryOzone> cursor_factory_ozone_;
scoped_ptr<GpuPlatformSupport> gpu_platform_support_; scoped_ptr<GpuPlatformSupport> gpu_platform_support_;
......
...@@ -25,12 +25,14 @@ ...@@ -25,12 +25,14 @@
'../gfx/gfx.gyp:gfx', '../gfx/gfx.gyp:gfx',
], ],
'sources': [ 'sources': [
'file_surface_factory.cc',
'file_surface_factory.h',
'ozone_platform_test.cc', 'ozone_platform_test.cc',
'ozone_platform_test.h', 'ozone_platform_test.h',
'test_cursor_factory.cc', 'test_cursor_factory.cc',
'test_cursor_factory.h', 'test_cursor_factory.h',
'test_window.cc',
'test_window.h',
'test_window_manager.cc',
'test_window_manager.h',
], ],
}, },
], ],
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/platform/test/test_window.h"
#include <string>
#include "base/files/file_path.h"
#include "base/strings/string_number_conversions.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/ozone/platform/test/test_window_manager.h"
#include "ui/platform_window/platform_window_delegate.h"
namespace ui {
TestWindow::TestWindow(PlatformWindowDelegate* delegate,
TestWindowManager* manager,
const gfx::Rect& bounds)
: delegate_(delegate), manager_(manager), bounds_(bounds) {
widget_ = manager_->AddWindow(this);
ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
delegate_->OnAcceleratedWidgetAvailable(widget_);
}
TestWindow::~TestWindow() {
ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
manager_->RemoveWindow(widget_, this);
}
base::FilePath TestWindow::path() {
base::FilePath base_path = manager_->base_path();
if (base_path == base::FilePath("/dev/null"))
return base_path;
// Disambiguate multiple window output files with the window id.
return base_path.Append(base::IntToString(widget_));
}
gfx::Rect TestWindow::GetBounds() {
return bounds_;
}
void TestWindow::SetBounds(const gfx::Rect& bounds) {
bounds_ = bounds;
delegate_->OnBoundsChanged(bounds);
}
void TestWindow::Show() {
}
void TestWindow::Hide() {
}
void TestWindow::Close() {
}
void TestWindow::SetCapture() {
}
void TestWindow::ReleaseCapture() {
}
void TestWindow::ToggleFullscreen() {
}
void TestWindow::Maximize() {
}
void TestWindow::Minimize() {
}
void TestWindow::Restore() {
}
bool TestWindow::CanDispatchEvent(const ui::PlatformEvent& ne) {
return true;
}
uint32_t TestWindow::DispatchEvent(const ui::PlatformEvent& ne) {
ui::Event* event = static_cast<ui::Event*>(ne);
delegate_->DispatchEvent(event);
return ui::POST_DISPATCH_STOP_PROPAGATION;
}
} // namespace ui
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_OZONE_PLATFORM_TEST_TEST_WINDOW_H_
#define UI_OZONE_PLATFORM_TEST_TEST_WINDOW_H_
#include "base/files/file_path.h"
#include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/platform_window/platform_window.h"
namespace ui {
class PlatformWindowDelegate;
class TestWindowManager;
class TestWindow : public PlatformWindow, public PlatformEventDispatcher {
public:
TestWindow(PlatformWindowDelegate* delegate,
TestWindowManager* manager,
const gfx::Rect& bounds);
virtual ~TestWindow();
// Path for image file for this window.
base::FilePath path();
// PlatformWindow:
virtual gfx::Rect GetBounds() OVERRIDE;
virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
virtual void Show() OVERRIDE;
virtual void Hide() OVERRIDE;
virtual void Close() OVERRIDE;
virtual void SetCapture() OVERRIDE;
virtual void ReleaseCapture() OVERRIDE;
virtual void ToggleFullscreen() OVERRIDE;
virtual void Maximize() OVERRIDE;
virtual void Minimize() OVERRIDE;
virtual void Restore() OVERRIDE;
// PlatformEventDispatcher:
virtual bool CanDispatchEvent(const PlatformEvent& event) OVERRIDE;
virtual uint32_t DispatchEvent(const PlatformEvent& event) OVERRIDE;
private:
PlatformWindowDelegate* delegate_;
TestWindowManager* manager_;
gfx::Rect bounds_;
gfx::AcceleratedWidget widget_;
DISALLOW_COPY_AND_ASSIGN(TestWindow);
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_TEST_TEST_WINDOW_H_
// Copyright 2013 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/ozone/platform/test/file_surface_factory.h" #include "ui/ozone/platform/test/test_window_manager.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/file_util.h" #include "base/file_util.h"
...@@ -63,33 +63,54 @@ class FileSurface : public SurfaceOzoneCanvas { ...@@ -63,33 +63,54 @@ class FileSurface : public SurfaceOzoneCanvas {
} // namespace } // namespace
FileSurfaceFactory::FileSurfaceFactory(const base::FilePath& dump_location) TestWindowManager::TestWindowManager(const base::FilePath& dump_location)
: location_(dump_location) { : location_(dump_location) {
CHECK(!base::DirectoryExists(location_)) << "Location cannot be a directory ("
<< location_.value() << ")";
CHECK(!base::PathExists(location_) || base::PathIsWritable(location_));
} }
FileSurfaceFactory::~FileSurfaceFactory() { TestWindowManager::~TestWindowManager() {
} }
SurfaceFactoryOzone::HardwareState FileSurfaceFactory::InitializeHardware() { void TestWindowManager::Initialize() {
if (!DirectoryExists(location_) && !base::CreateDirectory(location_) &&
location_ != base::FilePath("/dev/null"))
PLOG(FATAL) << "unable to create output directory";
if (!base::PathIsWritable(location_))
PLOG(FATAL) << "unable to write to output location";
}
int32_t TestWindowManager::AddWindow(TestWindow* window) {
return windows_.Add(window);
}
void TestWindowManager::RemoveWindow(int32_t window_id, TestWindow* window) {
DCHECK_EQ(window, windows_.Lookup(window_id));
windows_.Remove(window_id);
}
base::FilePath TestWindowManager::base_path() const {
return location_;
}
SurfaceFactoryOzone::HardwareState TestWindowManager::InitializeHardware() {
return INITIALIZED; return INITIALIZED;
} }
void FileSurfaceFactory::ShutdownHardware() { void TestWindowManager::ShutdownHardware() {
} }
gfx::AcceleratedWidget FileSurfaceFactory::GetAcceleratedWidget() { gfx::AcceleratedWidget TestWindowManager::GetAcceleratedWidget() {
return 1; NOTREACHED();
return -1;
} }
scoped_ptr<SurfaceOzoneCanvas> FileSurfaceFactory::CreateCanvasForWidget( scoped_ptr<SurfaceOzoneCanvas> TestWindowManager::CreateCanvasForWidget(
gfx::AcceleratedWidget w) { gfx::AcceleratedWidget widget) {
return make_scoped_ptr<SurfaceOzoneCanvas>(new FileSurface(location_)); TestWindow* window = windows_.Lookup(widget);
DCHECK(window);
return make_scoped_ptr<SurfaceOzoneCanvas>(new FileSurface(window->path()));
} }
bool FileSurfaceFactory::LoadEGLGLES2Bindings( bool TestWindowManager::LoadEGLGLES2Bindings(
AddGLLibraryCallback add_gl_library, AddGLLibraryCallback add_gl_library,
SetGLGetProcAddressProcCallback set_gl_get_proc_address) { SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
return false; return false;
......
// Copyright 2013 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -6,18 +6,31 @@ ...@@ -6,18 +6,31 @@
#define UI_OZONE_PLATFORM_TEST_FILE_SURFACE_FACTORY_H_ #define UI_OZONE_PLATFORM_TEST_FILE_SURFACE_FACTORY_H_
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/id_map.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/ozone/platform/test/test_window.h"
#include "ui/ozone/public/surface_factory_ozone.h" #include "ui/ozone/public/surface_factory_ozone.h"
namespace ui { namespace ui {
class OZONE_BASE_EXPORT FileSurfaceFactory : public SurfaceFactoryOzone { class TestWindowManager : public SurfaceFactoryOzone {
public: public:
explicit FileSurfaceFactory(const base::FilePath& dump_location); explicit TestWindowManager(const base::FilePath& dump_location);
virtual ~FileSurfaceFactory(); virtual ~TestWindowManager();
// Initialize (mainly check that we have a place to write output to).
void Initialize();
// Register a new window. Returns the window id.
int32_t AddWindow(TestWindow* window);
// Remove a window.
void RemoveWindow(int32_t window_id, TestWindow* window);
// User-supplied path for images.
base::FilePath base_path() const;
private:
// SurfaceFactoryOzone: // SurfaceFactoryOzone:
virtual HardwareState InitializeHardware() OVERRIDE; virtual HardwareState InitializeHardware() OVERRIDE;
virtual void ShutdownHardware() OVERRIDE; virtual void ShutdownHardware() OVERRIDE;
...@@ -28,9 +41,12 @@ class OZONE_BASE_EXPORT FileSurfaceFactory : public SurfaceFactoryOzone { ...@@ -28,9 +41,12 @@ class OZONE_BASE_EXPORT FileSurfaceFactory : public SurfaceFactoryOzone {
AddGLLibraryCallback add_gl_library, AddGLLibraryCallback add_gl_library,
SetGLGetProcAddressProcCallback set_gl_get_proc_address) OVERRIDE; SetGLGetProcAddressProcCallback set_gl_get_proc_address) OVERRIDE;
private:
base::FilePath location_; base::FilePath location_;
DISALLOW_COPY_AND_ASSIGN(FileSurfaceFactory); IDMap<TestWindow> windows_;
DISALLOW_COPY_AND_ASSIGN(TestWindowManager);
}; };
} // namespace ui } // namespace ui
......
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