Commit 9bae0d9b authored by sadrul's avatar sadrul Committed by Commit bot

mus: Make sure window parenting happens in the window server.

The native window parenting should happen in the window server,
since a sandboxed gpu process won't be able to do it.

BUG=643746

Review-Url: https://codereview.chromium.org/2610783003
Cr-Commit-Position: refs/heads/master@{#442060}
parent 449b31c0
......@@ -144,7 +144,7 @@ void GpuService::StoreShaderToDisk(int client_id,
void GpuService::SendAcceleratedSurfaceCreatedChildWindow(
gpu::SurfaceHandle parent_window,
gpu::SurfaceHandle child_window) {
::SetParent(child_window, parent_window);
gpu_host_->SetChildSurface(parent_window, child_window);
}
#endif
......
......@@ -5,6 +5,7 @@
module ui.mojom;
import "gpu/ipc/common/gpu_info.mojom";
import "gpu/ipc/common/surface_handle.mojom";
import "services/ui/gpu/interfaces/context_lost_reason.mojom";
import "url/mojo/url.mojom";
......@@ -18,5 +19,7 @@ interface GpuHost {
ContextLostReason reason,
url.mojom.Url active_url);
SetChildSurface(gpu.mojom.SurfaceHandle parent,
gpu.mojom.SurfaceHandle child);
StoreShaderToDisk(int32 client_id, string key, string shader);
};
......@@ -63,6 +63,7 @@ void DisplayManager::DestroyDisplay(Display* display) {
DCHECK(displays_.count(display));
displays_.erase(display);
window_server_->OnDisplayDestroyed(display);
}
delete display;
......
......@@ -19,6 +19,10 @@
#include "services/ui/ws/gpu_host_delegate.h"
#include "ui/gfx/buffer_format_util.h"
#if defined(OS_WIN)
#include "ui/gfx/win/rendering_window_manager.h"
#endif
namespace ui {
namespace ws {
......@@ -99,10 +103,10 @@ GpuHost::GpuHost(GpuHostDelegate* delegate)
next_client_id_(kInternalGpuChannelClientId + 1),
main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
gpu_host_binding_(this) {
gpu_main_impl_ = base::MakeUnique<GpuMain>(MakeRequest(&gpu_main_));
gpu_main_impl_->OnStart();
// TODO(sad): Once GPU process is split, this would look like:
// connector->ConnectToInterface("gpu", &gpu_main_);
gpu_main_impl_ = base::MakeUnique<GpuMain>(MakeRequest(&gpu_main_));
gpu_main_impl_->OnStart();
gpu_main_->CreateGpuService(MakeRequest(&gpu_service_),
gpu_host_binding_.CreateInterfacePtrAndBind());
gpu_memory_buffer_manager_ = base::MakeUnique<ServerGpuMemoryBufferManager>(
......@@ -119,12 +123,30 @@ void GpuHost::Add(mojom::GpuRequest request) {
std::move(request));
}
void GpuHost::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) {
#if defined(OS_WIN)
gfx::RenderingWindowManager::GetInstance()->RegisterParent(widget);
#endif
}
void GpuHost::OnAcceleratedWidgetDestroyed(gfx::AcceleratedWidget widget) {
#if defined(OS_WIN)
gfx::RenderingWindowManager::GetInstance()->UnregisterParent(widget);
#endif
}
void GpuHost::CreateDisplayCompositor(
cc::mojom::DisplayCompositorRequest request,
cc::mojom::DisplayCompositorClientPtr client) {
gpu_main_->CreateDisplayCompositor(std::move(request), std::move(client));
}
void GpuHost::OnBadMessageFromGpu() {
// TODO(sad): Received some unexpected message from the gpu process. We
// should kill the process and restart it.
NOTIMPLEMENTED();
}
void GpuHost::DidInitialize(const gpu::GPUInfo& gpu_info) {
gpu_info_ = gpu_info;
delegate_->OnGpuServiceInitialized();
......@@ -140,6 +162,28 @@ void GpuHost::DidLoseContext(bool offscreen,
gpu::error::ContextLostReason reason,
const GURL& active_url) {}
void GpuHost::SetChildSurface(gpu::SurfaceHandle parent,
gpu::SurfaceHandle child) {
#if defined(OS_WIN)
// Verify that |parent| was created by the window server.
DWORD process_id = 0;
DWORD thread_id = GetWindowThreadProcessId(parent, &process_id);
if (!thread_id || process_id != ::GetCurrentProcessId()) {
OnBadMessageFromGpu();
return;
}
// TODO(sad): Also verify that |child| was created by the mus-gpu process.
if (!gfx::RenderingWindowManager::GetInstance()->RegisterChild(parent,
child)) {
OnBadMessageFromGpu();
}
#else
NOTREACHED();
#endif
}
void GpuHost::StoreShaderToDisk(int32_t client_id,
const std::string& key,
const std::string& shader) {}
......
......@@ -34,11 +34,16 @@ class GpuHost : public mojom::GpuHost {
void Add(mojom::GpuRequest request);
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget);
void OnAcceleratedWidgetDestroyed(gfx::AcceleratedWidget widget);
// Requests a cc::mojom::DisplayCompositor interface from mus-gpu.
void CreateDisplayCompositor(cc::mojom::DisplayCompositorRequest request,
cc::mojom::DisplayCompositorClientPtr client);
private:
void OnBadMessageFromGpu();
// mojom::GpuHost:
void DidInitialize(const gpu::GPUInfo& gpu_info) override;
void DidCreateOffscreenContext(const GURL& url) override;
......@@ -47,6 +52,8 @@ class GpuHost : public mojom::GpuHost {
void DidLoseContext(bool offscreen,
gpu::error::ContextLostReason reason,
const GURL& active_url) override;
void SetChildSurface(gpu::SurfaceHandle parent,
gpu::SurfaceHandle child) override;
void StoreShaderToDisk(int32_t client_id,
const std::string& key,
const std::string& shader) override;
......
......@@ -13,6 +13,7 @@
#include "base/strings/string16.h"
#include "services/ui/display/viewport_metrics.h"
#include "services/ui/public/interfaces/cursor.mojom.h"
#include "ui/gfx/native_widget_types.h"
namespace gfx {
class Rect;
......@@ -63,6 +64,10 @@ class PlatformDisplay {
virtual const display::ViewportMetrics& GetViewportMetrics() const = 0;
// Returns the AcceleratedWidget associated with the Display. It can return
// kNullAcceleratedWidget if the accelerated widget is not available yet.
virtual gfx::AcceleratedWidget GetAcceleratedWidget() const = 0;
virtual FrameGenerator* GetFrameGenerator() = 0;
// Overrides factory for testing. Default (NULL) value indicates regular
......
......@@ -36,7 +36,8 @@ PlatformDisplayDefault::PlatformDisplayDefault(
image_cursors_(new ImageCursors),
#endif
frame_generator_(new FrameGenerator(this, init_params.root_window)),
metrics_(init_params.metrics) {
metrics_(init_params.metrics),
widget_(gfx::kNullAcceleratedWidget) {
frame_generator_->set_device_scale_factor(
init_params.metrics.device_scale_factor);
}
......@@ -157,6 +158,10 @@ const display::ViewportMetrics& PlatformDisplayDefault::GetViewportMetrics()
return metrics_;
}
gfx::AcceleratedWidget PlatformDisplayDefault::GetAcceleratedWidget() const {
return widget_;
}
void PlatformDisplayDefault::UpdateEventRootLocation(ui::LocatedEvent* event) {
gfx::Point location = event->location();
location.Offset(metrics_.bounds.x(), metrics_.bounds.y());
......@@ -238,6 +243,8 @@ void PlatformDisplayDefault::OnAcceleratedWidgetAvailable(
// This will get called after Init() is called, either synchronously as part
// of the Init() callstack or async after Init() has returned, depending on
// the platform.
DCHECK_EQ(gfx::kNullAcceleratedWidget, widget_);
widget_ = widget;
delegate_->OnAcceleratedWidgetAvailable();
frame_generator_->OnAcceleratedWidgetAvailable(widget);
}
......
......@@ -44,6 +44,7 @@ class PlatformDisplayDefault : public PlatformDisplay,
gfx::Rect GetBounds() const override;
bool UpdateViewportMetrics(const display::ViewportMetrics& metrics) override;
const display::ViewportMetrics& GetViewportMetrics() const override;
gfx::AcceleratedWidget GetAcceleratedWidget() const override;
FrameGenerator* GetFrameGenerator() override;
private:
......@@ -82,6 +83,7 @@ class PlatformDisplayDefault : public PlatformDisplay,
display::ViewportMetrics metrics_;
std::unique_ptr<ui::PlatformWindow> platform_window_;
gfx::AcceleratedWidget widget_;
DISALLOW_COPY_AND_ASSIGN(PlatformDisplayDefault);
};
......
......@@ -63,6 +63,9 @@ class TestPlatformDisplay : public PlatformDisplay {
const display::ViewportMetrics& GetViewportMetrics() const override {
return display_metrics_;
}
gfx::AcceleratedWidget GetAcceleratedWidget() const override {
return gfx::kNullAcceleratedWidget;
}
FrameGenerator* GetFrameGenerator() override { return nullptr; }
private:
......
......@@ -509,6 +509,13 @@ WindowTree* WindowServer::GetCurrentDragLoopInitiator() {
void WindowServer::OnDisplayReady(Display* display, bool is_first) {
if (is_first)
delegate_->OnFirstDisplayReady();
gpu_host_->OnAcceleratedWidgetAvailable(
display->platform_display()->GetAcceleratedWidget());
}
void WindowServer::OnDisplayDestroyed(Display* display) {
gpu_host_->OnAcceleratedWidgetDestroyed(
display->platform_display()->GetAcceleratedWidget());
}
void WindowServer::OnNoMoreDisplays() {
......
......@@ -223,6 +223,7 @@ class WindowServer : public ServerWindowDelegate,
bool in_drag_loop() const { return !!current_drag_loop_; }
void OnDisplayReady(Display* display, bool is_first);
void OnDisplayDestroyed(Display* display);
void OnNoMoreDisplays();
WindowManagerState* GetWindowManagerStateForUser(const UserId& user_id);
......
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