Commit aa2a3720 authored by spang's avatar spang Committed by Commit bot

ozone: Add UiThreadGpu for applications that do UI thread GL

The demo does GL on the main thread, which broken since we now depend on
GpuPlatformSupport(Host). Let's deliver these messages directly via a
helper class for those applications.

BUG=409978
TEST=ozone_demo --ozone-platform=gbm on link_freon
NOTRY=true

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

Cr-Commit-Position: refs/heads/master@{#293075}
parent 8b156314
......@@ -98,6 +98,8 @@ component("ozone") {
"public/ozone_platform.h",
"public/ozone_switches.cc",
"public/ozone_switches.h",
"public/ui_thread_gpu.cc",
"public/ui_thread_gpu.h",
"platform_selection.cc",
"platform_selection.h",
]
......
......@@ -16,6 +16,7 @@
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/surface_factory_ozone.h"
#include "ui/ozone/public/surface_ozone_canvas.h"
#include "ui/ozone/public/ui_thread_gpu.h"
#include "ui/platform_window/platform_window.h"
#include "ui/platform_window/platform_window_delegate.h"
......@@ -47,7 +48,8 @@ class DemoWindow : public ui::PlatformWindowDelegate {
void Start() {
if (!CommandLine::ForCurrentProcess()->HasSwitch(kDisableGpu) &&
gfx::GLSurface::InitializeOneOff() && InitializeGLSurface()) {
gfx::GLSurface::InitializeOneOff() && StartInProcessGpu() &&
InitializeGLSurface()) {
StartAnimationGL();
} else if (InitializeSoftwareSurface()) {
StartAnimationSoftware();
......@@ -173,6 +175,8 @@ class DemoWindow : public ui::PlatformWindowDelegate {
software_surface_->PresentCanvas(gfx::Rect(window_size));
}
bool StartInProcessGpu() { return ui_thread_gpu_.Initialize(); }
// Timer for animation.
base::RepeatingTimer<DemoWindow> timer_;
......@@ -187,6 +191,9 @@ class DemoWindow : public ui::PlatformWindowDelegate {
scoped_ptr<ui::PlatformWindow> platform_window_;
gfx::AcceleratedWidget widget_;
// Helper for applications that do GL on main thread.
ui::UiThreadGpu ui_thread_gpu_;
// Animation state.
int iteration_;
......
......@@ -102,6 +102,8 @@
'public/ozone_platform.h',
'public/ozone_switches.cc',
'public/ozone_switches.h',
'public/ui_thread_gpu.cc',
'public/ui_thread_gpu.h',
'platform_selection.cc',
'platform_selection.h',
'<@(external_ozone_platform_files)',
......
// 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/public/ui_thread_gpu.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_sender.h"
#include "ui/ozone/public/gpu_platform_support.h"
#include "ui/ozone/public/gpu_platform_support_host.h"
#include "ui/ozone/public/ozone_platform.h"
namespace ui {
class UiThreadGpuForwardingSender : public IPC::Sender {
public:
explicit UiThreadGpuForwardingSender(IPC::Listener* listener)
: listener_(listener) {}
virtual ~UiThreadGpuForwardingSender() {}
// IPC::Sender:
virtual bool Send(IPC::Message* msg) OVERRIDE {
listener_->OnMessageReceived(*msg);
delete msg;
return true;
}
private:
IPC::Listener* listener_;
};
UiThreadGpu::UiThreadGpu() {
}
UiThreadGpu::~UiThreadGpu() {
}
bool UiThreadGpu::Initialize() {
OzonePlatform* platform = ui::OzonePlatform::GetInstance();
ui_sender_.reset(
new UiThreadGpuForwardingSender(platform->GetGpuPlatformSupportHost()));
gpu_sender_.reset(
new UiThreadGpuForwardingSender(platform->GetGpuPlatformSupport()));
const int kHostId = 1;
platform->GetGpuPlatformSupportHost()->OnChannelEstablished(
kHostId, gpu_sender_.get());
platform->GetGpuPlatformSupport()->OnChannelEstablished(ui_sender_.get());
return true;
}
} // 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_PUBLIC_UI_THREAD_GPU_H_
#define UI_OZONE_PUBLIC_UI_THREAD_GPU_H_
#include "base/memory/scoped_ptr.h"
#include "ui/ozone/ozone_export.h"
namespace IPC {
class Sender;
}
namespace ui {
class UiThreadGpuForwardingSender;
// Helper class for applications that do GL on the UI thead.
//
// This sets up message forwarding between the "gpu" and "ui" threads,
// for applications in which they are both the same thread.
class OZONE_EXPORT UiThreadGpu {
public:
UiThreadGpu();
virtual ~UiThreadGpu();
// Start processing gpu messages.
bool Initialize();
private:
scoped_ptr<UiThreadGpuForwardingSender> ui_sender_;
scoped_ptr<UiThreadGpuForwardingSender> gpu_sender_;
DISALLOW_COPY_AND_ASSIGN(UiThreadGpu);
};
} // namespace ui
#endif // UI_OZONE_PUBLIC_UI_THREAD_GPU_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