Commit 92fe48f2 authored by Mustafa Çamurcu's avatar Mustafa Çamurcu Committed by Commit Bot

[ozone/windows] Windows platform

This cl creates the windows platform for ozone.

These changes are not sufficient for a successful Windows/Ozone build.
See: https://chromium-review.googlesource.com/c/chromium/src/+/974285
and https://swiftshader-review.googlesource.com/c/SwiftShader/+/17968

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: If27cd7b56d5503db6881cf1f2c563826f72f0be0
Reviewed-on: https://chromium-review.googlesource.com/975902Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Commit-Queue: Mustafa Çamurcu <camurcu@google.com>
Cr-Commit-Position: refs/heads/master@{#553300}
parent 664491ff
......@@ -21,6 +21,11 @@ ozone_platform_deps = ozone_external_platform_deps
# Extra dependencies to pull into ozone_unittests for built platforms.
ozone_platform_test_deps = ozone_external_platform_test_deps
if (ozone_platform_windows) {
ozone_platforms += [ "windows" ]
ozone_platform_deps += [ "platform/windows" ]
}
if (ozone_platform_headless) {
ozone_platforms += [ "headless" ]
ozone_platform_deps += [ "platform/headless" ]
......
......@@ -11,6 +11,7 @@
#include "base/run_loop.h"
#include "base/task_scheduler/task_scheduler.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "components/tracing/common/trace_to_console.h"
#include "components/tracing/common/tracing_switches.h"
#include "ui/events/ozone/layout/keyboard_layout_engine.h"
......@@ -28,6 +29,12 @@ int main(int argc, char** argv) {
// Initialize logging so we can enable VLOG messages.
logging::LoggingSettings settings;
// Logs to system debug by default on POSIX.
#if defined(OS_WIN)
settings.log_file = FILE_PATH_LITERAL("ozone_demo.log");
#endif
logging::InitLogging(settings);
if (base::CommandLine::ForCurrentProcess()->HasSwitch(kHelp)) {
......
......@@ -30,6 +30,9 @@ declare_args() {
# Compile the 'wayland' platform.
ozone_platform_wayland = false
# Compile the 'windows' platform.
ozone_platform_windows = false
if (ozone_auto_platforms) {
# Use headless as the default platform unless modified below.
ozone_platform = "headless"
......@@ -59,11 +62,14 @@ declare_args() {
ozone_platform = "x11"
ozone_platform_wayland = true
ozone_platform_x11 = true
} else if (is_win) {
ozone_platform = "windows"
ozone_platform_windows = true
}
}
}
assert(use_ozone || !(ozone_platform_cast || ozone_platform_gbm ||
ozone_platform_headless || ozone_platform_x11 ||
ozone_platform_wayland),
ozone_platform_wayland || ozone_platform_windows),
"Must set use_ozone to select ozone platforms")
......@@ -143,7 +143,13 @@ base::FilePath HeadlessSurfaceFactory::GetPathForWidget(
return base_path_;
// Disambiguate multiple window output files with the window id.
#if defined(OS_WIN)
std::string path = base::IntToString(reinterpret_cast<int>(widget)) + ".png";
std::wstring wpath(path.begin(), path.end());
return base_path_.Append(wpath);
#else
return base_path_.Append(base::IntToString(widget) + ".png");
#endif
}
std::vector<gl::GLImplementation>
......
# Copyright 2018 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.
visibility = [ "//ui/ozone/*" ]
source_set("windows") {
sources = [
"client_native_pixmap_factory_windows.cc",
"client_native_pixmap_factory_windows.h",
"ozone_platform_windows.cc",
"ozone_platform_windows.h",
"windows_surface_factory.cc",
"windows_surface_factory.h",
"windows_window.cc",
"windows_window.h",
"windows_window_manager.cc",
"windows_window_manager.h",
]
defines = [ "OZONE_IMPLEMENTATION" ]
deps = [
"//base",
"//skia",
"//ui/base",
"//ui/display/manager",
"//ui/events",
"//ui/events/ozone:events_ozone_layout",
"//ui/events/platform",
"//ui/gfx/geometry",
"//ui/gl",
"//ui/ozone:ozone_base",
"//ui/ozone/common",
"//ui/platform_window",
"//ui/platform_window/win",
]
}
// Copyright 2018 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/windows/client_native_pixmap_factory_windows.h"
#include "ui/ozone/common/stub_client_native_pixmap_factory.h"
namespace ui {
gfx::ClientNativePixmapFactory* CreateClientNativePixmapFactoryWindows() {
// TODO(camurcu): Implement the better (more performant) way.
return CreateStubClientNativePixmapFactory();
}
} // namespace ui
// Copyright 2018 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_WINDOWS_CLIENT_NATIVE_PIXMAP_FACTORY_WINDOWS_H_
#define UI_OZONE_PLATFORM_WINDOWS_CLIENT_NATIVE_PIXMAP_FACTORY_WINDOWS_H_
namespace gfx {
class ClientNativePixmapFactory;
}
namespace ui {
// Constructor hook for use in constructor_list.cc
gfx::ClientNativePixmapFactory* CreateClientNativePixmapFactoryWindows();
} // namespace ui
#endif // UI_OZONE_PLATFORM_WINDOWS_CLIENT_NATIVE_PIXMAP_FACTORY_WINDOWS_H_
// Copyright 2018 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/windows/ozone_platform_windows.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h"
#include "ui/display/manager/fake_display_delegate.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/events/system_input_injector.h"
#include "ui/ozone/common/stub_overlay_manager.h"
#include "ui/ozone/platform/windows/windows_surface_factory.h"
#include "ui/ozone/platform/windows/windows_window.h"
#include "ui/ozone/platform/windows/windows_window_manager.h"
#include "ui/ozone/public/cursor_factory_ozone.h"
#include "ui/ozone/public/gpu_platform_support_host.h"
#include "ui/ozone/public/input_controller.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/ozone_switches.h"
namespace ui {
namespace {
// dummy class
class WindowsPlatformEventSource : public ui::PlatformEventSource {
public:
WindowsPlatformEventSource() = default;
~WindowsPlatformEventSource() override = default;
private:
DISALLOW_COPY_AND_ASSIGN(WindowsPlatformEventSource);
};
// OzonePlatform for Windows
class OzonePlatformWindows : public OzonePlatform {
public:
OzonePlatformWindows() {}
~OzonePlatformWindows() override {}
// OzonePlatform:
ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override {
return surface_factory_.get();
}
OverlayManagerOzone* GetOverlayManager() override {
return overlay_manager_.get();
}
CursorFactoryOzone* GetCursorFactoryOzone() override {
return cursor_factory_ozone_.get();
}
InputController* GetInputController() override {
return input_controller_.get();
}
GpuPlatformSupportHost* GetGpuPlatformSupportHost() override {
return gpu_platform_support_host_.get();
}
std::unique_ptr<SystemInputInjector> CreateSystemInputInjector() override {
return nullptr; // no input injection support.
}
std::unique_ptr<PlatformWindow> CreatePlatformWindow(
PlatformWindowDelegate* delegate,
const gfx::Rect& bounds) override {
return std::make_unique<WindowsWindow>(delegate, bounds);
}
std::unique_ptr<display::NativeDisplayDelegate> CreateNativeDisplayDelegate()
override {
return std::make_unique<display::FakeDisplayDelegate>();
}
void InitializeUI(const InitParams& params) override {
window_manager_ = std::make_unique<WindowsWindowManager>();
surface_factory_ = std::make_unique<WindowsSurfaceFactory>();
// This unbreaks tests that create their own.
if (!PlatformEventSource::GetInstance())
platform_event_source_ = std::make_unique<WindowsPlatformEventSource>();
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
std::make_unique<StubKeyboardLayoutEngine>());
overlay_manager_ = std::make_unique<StubOverlayManager>();
input_controller_ = CreateStubInputController();
cursor_factory_ozone_ = std::make_unique<BitmapCursorFactoryOzone>();
gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost());
}
void InitializeGPU(const InitParams& params) override {
if (!surface_factory_)
surface_factory_ = std::make_unique<WindowsSurfaceFactory>();
}
private:
std::unique_ptr<WindowsWindowManager> window_manager_;
std::unique_ptr<WindowsSurfaceFactory> surface_factory_;
std::unique_ptr<PlatformEventSource> platform_event_source_;
std::unique_ptr<CursorFactoryOzone> cursor_factory_ozone_;
std::unique_ptr<InputController> input_controller_;
std::unique_ptr<GpuPlatformSupportHost> gpu_platform_support_host_;
std::unique_ptr<OverlayManagerOzone> overlay_manager_;
DISALLOW_COPY_AND_ASSIGN(OzonePlatformWindows);
};
} // namespace
OzonePlatform* CreateOzonePlatformWindows() {
return new OzonePlatformWindows;
}
} // namespace ui
// Copyright 2018 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_WINDOWS_OZONE_PLATFORM_WINDOWS_H_
#define UI_OZONE_PLATFORM_WINDOWS_OZONE_PLATFORM_WINDOWS_H_
namespace ui {
class OzonePlatform;
// Constructor hook for use in ozone_platform_list.cc
OzonePlatform* CreateOzonePlatformWindows();
} // namespace ui
#endif // UI_OZONE_PLATFORM_WINDOWS_OZONE_PLATFORM_WINDOWS_H_
// Copyright 2018 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/windows/windows_surface_factory.h"
#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/location.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/task_scheduler/post_task.h"
#include "build/build_config.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/vsync_provider.h"
#include "ui/gl/gl_surface_egl.h"
#include "ui/gl/gl_surface_osmesa_win.h"
#include "ui/gl/vsync_provider_win.h"
#include "ui/ozone/common/egl_util.h"
#include "ui/ozone/common/gl_ozone_egl.h"
#include "ui/ozone/common/gl_ozone_osmesa.h"
#include "ui/ozone/platform/windows/windows_window.h"
#include "ui/ozone/platform/windows/windows_window_manager.h"
namespace ui {
namespace {
class GLOzoneOSMesaWindows : public GLOzoneOSMesa {
public:
GLOzoneOSMesaWindows() = default;
~GLOzoneOSMesaWindows() override = default;
// GLOzone:
scoped_refptr<gl::GLSurface> CreateViewGLSurface(
gfx::AcceleratedWidget window) override {
return gl::InitializeGLSurface(new gl::GLSurfaceOSMesaWin(window));
}
// TODO(camurcu): Implement CreateOffscreenGLSurface().
DISALLOW_COPY_AND_ASSIGN(GLOzoneOSMesaWindows);
};
class GLOzoneEGLWindows : public GLOzoneEGL {
public:
GLOzoneEGLWindows() = default;
~GLOzoneEGLWindows() override = default;
// GLOzone:
scoped_refptr<gl::GLSurface> CreateViewGLSurface(
gfx::AcceleratedWidget window) override {
std::unique_ptr<gfx::VSyncProvider> sync_provider(
new gl::VSyncProviderWin(window));
return CreateNativeViewGLSurfaceEGL(window, std::move(sync_provider));
}
scoped_refptr<gl::GLSurface> CreateNativeViewGLSurfaceEGL(
gfx::AcceleratedWidget window,
std::unique_ptr<gfx::VSyncProvider> sync_provider) {
DCHECK_EQ(gl::kGLImplementationEGLGLES2, gl::GetGLImplementation());
DCHECK(window != gfx::kNullAcceleratedWidget);
return gl::InitializeGLSurface(
new gl::NativeViewGLSurfaceEGL(window, std::move(sync_provider)));
}
scoped_refptr<gl::GLSurface> CreateOffscreenGLSurface(
const gfx::Size& size) override {
return gl::InitializeGLSurface(new gl::PbufferGLSurfaceEGL(size));
}
protected:
// GLOzoneEGL:
HDC GetNativeDisplay() override {
// TODO(camurcu): Probably won't work with multiple AcceleratedWidgets.
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd144947.aspx
return GetWindowDC(nullptr);
}
bool LoadGLES2Bindings(gl::GLImplementation implementation) override {
return LoadDefaultEGLGLES2Bindings(implementation);
}
private:
DISALLOW_COPY_AND_ASSIGN(GLOzoneEGLWindows);
};
} // namespace
WindowsSurfaceFactory::WindowsSurfaceFactory()
: egl_implementation_(std::make_unique<GLOzoneEGLWindows>()),
osmesa_implementation_(std::make_unique<GLOzoneOSMesaWindows>()) {}
WindowsSurfaceFactory::~WindowsSurfaceFactory() = default;
std::vector<gl::GLImplementation>
WindowsSurfaceFactory::GetAllowedGLImplementations() {
return std::vector<gl::GLImplementation>{gl::kGLImplementationEGLGLES2,
gl::kGLImplementationOSMesaGL};
}
GLOzone* WindowsSurfaceFactory::GetGLOzone(
gl::GLImplementation implementation) {
switch (implementation) {
case gl::kGLImplementationEGLGLES2:
return egl_implementation_.get();
case gl::kGLImplementationOSMesaGL:
return osmesa_implementation_.get();
default:
return nullptr;
}
}
} // namespace ui
// Copyright 2018 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_WINDOWS_WINDOWS_SURFACE_FACTORY_H_
#define UI_OZONE_PLATFORM_WINDOWS_WINDOWS_SURFACE_FACTORY_H_
#include <memory>
#include <vector>
#include "base/files/file_path.h"
#include "base/macros.h"
#include "ui/ozone/public/gl_ozone.h"
#include "ui/ozone/public/surface_factory_ozone.h"
namespace ui {
// Handles GL initialization and surface/context creation for Windows
class WindowsSurfaceFactory : public SurfaceFactoryOzone {
public:
WindowsSurfaceFactory();
~WindowsSurfaceFactory() override;
// SurfaceFactoryOzone:
std::vector<gl::GLImplementation> GetAllowedGLImplementations() override;
GLOzone* GetGLOzone(gl::GLImplementation implementation) override;
private:
std::unique_ptr<GLOzone> egl_implementation_;
// TODO(camurcu): remove osmesa.
std::unique_ptr<GLOzone> osmesa_implementation_;
DISALLOW_COPY_AND_ASSIGN(WindowsSurfaceFactory);
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_WINDOWS_WINDOWS_SURFACE_FACTORY_H_
// Copyright 2018 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/windows/windows_window.h"
#include <string>
#include "build/build_config.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/ozone/platform/windows/windows_window_manager.h"
#include "ui/platform_window/platform_window_delegate.h"
namespace ui {
WindowsWindow::WindowsWindow(PlatformWindowDelegate* delegate,
const gfx::Rect& bounds)
: WinWindow(delegate, bounds) {}
WindowsWindow::~WindowsWindow() {}
} // namespace ui
// Copyright 2018 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_WINDOWS_WINDOWS_WINDOW_H_
#define UI_OZONE_PLATFORM_WINDOWS_WINDOWS_WINDOW_H_
#include "base/macros.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/platform_window/win/win_window.h"
namespace ui {
class PlatformWindowDelegate;
class WindowsWindow : public WinWindow {
public:
WindowsWindow(PlatformWindowDelegate* delegate, const gfx::Rect& bounds);
~WindowsWindow() override;
private:
DISALLOW_COPY_AND_ASSIGN(WindowsWindow);
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_WINDOWS_WINDOWS_WINDOW_H_
// Copyright 2018 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/windows/windows_window_manager.h"
namespace ui {
WindowsWindowManager::WindowsWindowManager() = default;
WindowsWindowManager::~WindowsWindowManager() {}
int32_t WindowsWindowManager::AddWindow(WindowsWindow* window) {
return windows_.Add(window);
}
void WindowsWindowManager::RemoveWindow(int32_t window_id,
WindowsWindow* window) {
DCHECK_EQ(window, windows_.Lookup(window_id));
windows_.Remove(window_id);
}
WindowsWindow* WindowsWindowManager::GetWindow(int32_t window_id) {
return windows_.Lookup(window_id);
}
} // namespace ui
// Copyright 2018 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_WINDOWS_WINDOWS_WINDOW_MANAGER_H_
#define UI_OZONE_PLATFORM_WINDOWS_WINDOWS_WINDOW_MANAGER_H_
#include <stdint.h>
#include <memory>
#include "base/containers/id_map.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/threading/thread_checker.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/ozone/public/surface_factory_ozone.h"
namespace ui {
class WindowsWindow;
class WindowsWindowManager {
public:
WindowsWindowManager();
~WindowsWindowManager();
// Register a new window. Returns the window id.
int32_t AddWindow(WindowsWindow* window);
// Remove a window.
void RemoveWindow(int32_t window_id, WindowsWindow* window);
// Find a window object by id;
WindowsWindow* GetWindow(int32_t window_id);
private:
base::IDMap<WindowsWindow*> windows_;
DISALLOW_COPY_AND_ASSIGN(WindowsWindowManager);
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_WINDOWS_WINDOWS_WINDOW_MANAGER_H_
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