Connect X11 ConfigureNotify events to Mojo

This change plumbs top level window resize notifications from X11 through to the WindowManager and to the GLSurface associated with the top level window. It's an incremental step towards adding support for window manager level layout management (see crbug.com/389785).


BUG=388524

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=281955

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282254 0039d316-1c4b-4281-b951-d872f2087c98
parent 6fc79ea0
......@@ -13,6 +13,7 @@
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/input_events/input_events_type_converters.h"
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/node_observer.h"
#include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/public/cpp/view_manager/view_event_dispatcher.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h"
......@@ -156,6 +157,36 @@ class KeyboardManager : public KeyboardClient {
DISALLOW_COPY_AND_ASSIGN(KeyboardManager);
};
class RootLayoutManager : public NodeObserver {
public:
explicit RootLayoutManager(ViewManager* view_manager,
Node* root,
Id content_node_id)
: root_(root),
view_manager_(view_manager),
content_node_id_(content_node_id) {}
virtual ~RootLayoutManager() {}
private:
// Overridden from NodeObserver:
virtual void OnNodeBoundsChanged(Node* node,
const gfx::Rect& /*old_bounds*/,
const gfx::Rect& new_bounds) OVERRIDE {
DCHECK_EQ(node, root_);
Node* content_node = view_manager_->GetNodeById(content_node_id_);
content_node->SetBounds(new_bounds);
// Force the view's bitmap to be recreated
content_node->active_view()->SetColor(SK_ColorBLUE);
// TODO(hansmuller): Do Layout
}
Node* root_;
ViewManager* view_manager_;
Id content_node_id_;
DISALLOW_COPY_AND_ASSIGN(RootLayoutManager);
};
class WindowManager : public ApplicationDelegate,
public DebugPanel::Delegate,
public ViewObserver,
......@@ -250,10 +281,14 @@ class WindowManager : public ApplicationDelegate,
view_manager_->SetEventDispatcher(this);
Node* node = Node::Create(view_manager);
view_manager->GetRoots().front()->AddChild(node);
node->SetBounds(gfx::Rect(800, 600));
root->AddChild(node);
node->SetBounds(gfx::Rect(root->bounds().size()));
content_node_id_ = node->id();
root_layout_manager_.reset(
new RootLayoutManager(view_manager, root, content_node_id_));
root->AddObserver(root_layout_manager_.get());
View* view = View::Create(view_manager);
node->SetActiveView(view);
view->SetColor(SK_ColorBLUE);
......@@ -395,6 +430,7 @@ class WindowManager : public ApplicationDelegate,
Node* launcher_ui_;
std::vector<Node*> windows_;
ViewManager* view_manager_;
scoped_ptr<RootLayoutManager> root_layout_manager_;
// Id of the node most content is added to. The keyboard is NOT added here.
Id content_node_id_;
......
......@@ -73,18 +73,17 @@ void CommandBufferImpl::Initialize(
bool CommandBufferImpl::DoInitialize(
mojo::ScopedSharedBufferHandle shared_state) {
// TODO(piman): offscreen surface.
scoped_refptr<gfx::GLSurface> surface =
gfx::GLSurface::CreateViewGLSurface(widget_);
if (!surface.get())
surface_ = gfx::GLSurface::CreateViewGLSurface(widget_);
if (!surface_.get())
return false;
// TODO(piman): context sharing, virtual contexts, gpu preference.
scoped_refptr<gfx::GLContext> context = gfx::GLContext::CreateGLContext(
NULL, surface.get(), gfx::PreferIntegratedGpu);
NULL, surface_.get(), gfx::PreferIntegratedGpu);
if (!context.get())
return false;
if (!context->MakeCurrent(surface.get()))
if (!context->MakeCurrent(surface_.get()))
return false;
// TODO(piman): ShaderTranslatorCache is currently per-ContextGroup but
......@@ -106,12 +105,14 @@ bool CommandBufferImpl::DoInitialize(
scheduler_.reset(new gpu::GpuScheduler(
command_buffer_.get(), decoder_.get(), decoder_.get()));
decoder_->set_engine(scheduler_.get());
decoder_->SetResizeCallback(
base::Bind(&CommandBufferImpl::OnResize, base::Unretained(this)));
gpu::gles2::DisallowedFeatures disallowed_features;
// TODO(piman): attributes.
std::vector<int32> attrib_vector;
if (!decoder_->Initialize(surface,
if (!decoder_->Initialize(surface_,
context,
false /* offscreen */,
size_,
......@@ -194,5 +195,9 @@ void CommandBufferImpl::OnParseError() {
void CommandBufferImpl::DrawAnimationFrame() { client()->DrawAnimationFrame(); }
void CommandBufferImpl::OnResize(gfx::Size size, float scale_factor) {
surface_->Resize(size);
}
} // namespace services
} // namespace mojo
......@@ -21,6 +21,10 @@ class GLES2Decoder;
}
}
namespace gfx {
class GLSurface;
}
namespace mojo {
namespace services {
......@@ -49,6 +53,8 @@ class CommandBufferImpl : public InterfaceImpl<CommandBuffer> {
private:
bool DoInitialize(mojo::ScopedSharedBufferHandle shared_state);
void OnResize(gfx::Size size, float scale_factor);
void OnParseError();
void DrawAnimationFrame();
......@@ -61,6 +67,7 @@ class CommandBufferImpl : public InterfaceImpl<CommandBuffer> {
scoped_ptr<gpu::gles2::GLES2Decoder> decoder_;
scoped_ptr<gpu::GpuScheduler> scheduler_;
scoped_ptr<gpu::GpuControlService> gpu_control_;
scoped_refptr<gfx::GLSurface> surface_;
base::RepeatingTimer<CommandBufferImpl> timer_;
DISALLOW_COPY_AND_ASSIGN(CommandBufferImpl);
......
......@@ -7,6 +7,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
......@@ -133,6 +134,7 @@ class NativeViewportX11 : public NativeViewport,
case ButtonPress:
case ButtonRelease:
case MotionNotify:
case ConfigureNotify:
return true;
case ClientMessage:
return event->xclient.message_type == atom_wm_protocols_;
......@@ -159,6 +161,9 @@ class NativeViewportX11 : public NativeViewport,
ui::MouseEvent mouse_event(event);
delegate_->OnEvent(&mouse_event);
}
} else if (event->type == ConfigureNotify) {
bounds_ = gfx::Rect(event->xconfigure.width, event->xconfigure.height);
delegate_->OnBoundsChanged(bounds_);
}
return ui::POST_DISPATCH_NONE;
}
......
......@@ -146,6 +146,7 @@ gfx::Size Node::GetMaximumSize() const {
void Node::OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {
delegate_->OnNodeBoundsChanged(this, old_bounds, new_bounds);
}
gfx::NativeCursor Node::GetCursor(const gfx::Point& point) {
......
......@@ -11,6 +11,10 @@ namespace ui {
class Event;
}
namespace gfx {
class Rect;
}
namespace mojo {
namespace view_manager {
namespace service {
......@@ -25,6 +29,10 @@ class MOJO_VIEW_MANAGER_EXPORT NodeDelegate {
const Node* new_parent,
const Node* old_parent) = 0;
virtual void OnNodeBoundsChanged(const Node* node,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) = 0;
// Invoked when the View associated with a node changes.
virtual void OnNodeViewReplaced(const Node* node,
const View* new_view,
......
......@@ -266,6 +266,12 @@ void RootNodeManager::OnNodeHierarchyChanged(const Node* node,
ProcessNodeHierarchyChanged(node, new_parent, old_parent);
}
void RootNodeManager::OnNodeBoundsChanged(const Node* node,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {
ProcessNodeBoundsChanged(node, old_bounds, new_bounds);
}
void RootNodeManager::OnNodeViewReplaced(const Node* node,
const View* new_view,
const View* old_view) {
......
......@@ -190,6 +190,9 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager
virtual void OnNodeHierarchyChanged(const Node* node,
const Node* new_parent,
const Node* old_parent) OVERRIDE;
virtual void OnNodeBoundsChanged(const Node* node,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnNodeViewReplaced(const Node* node,
const View* new_view,
const View* old_view) OVERRIDE;
......
......@@ -750,8 +750,6 @@ void ViewManagerServiceImpl::SetNodeBounds(
RootNodeManager::CHANGE_TYPE_DONT_ADVANCE_SERVER_CHANGE_ID, false);
gfx::Rect old_bounds = node->window()->bounds();
node->window()->SetBounds(bounds.To<gfx::Rect>());
root_node_manager_->ProcessNodeBoundsChanged(
node, old_bounds, bounds.To<gfx::Rect>());
callback.Run(true);
}
......@@ -810,6 +808,12 @@ void ViewManagerServiceImpl::OnNodeHierarchyChanged(const Node* node,
root_node_manager_->ProcessNodeHierarchyChanged(node, new_parent, old_parent);
}
void ViewManagerServiceImpl::OnNodeBoundsChanged(const Node* node,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {
root_node_manager_->ProcessNodeBoundsChanged(node, old_bounds, new_bounds);
}
void ViewManagerServiceImpl::OnNodeViewReplaced(const Node* node,
const View* new_view,
const View* old_view) {
......
......@@ -220,6 +220,9 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerServiceImpl
virtual void OnNodeHierarchyChanged(const Node* node,
const Node* new_parent,
const Node* old_parent) OVERRIDE;
virtual void OnNodeBoundsChanged(const Node* node,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnNodeViewReplaced(const Node* node,
const View* new_view,
const View* old_view) OVERRIDE;
......
......@@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/services/view_manager/root_node_manager.h"
#include "mojo/services/view_manager/window_tree_host_impl.h"
#include "mojo/public/c/gles2/gles2.h"
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/view_manager/context_factory_impl.h"
#include "ui/aura/env.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/compositor.h"
......@@ -24,6 +25,43 @@ namespace service {
// static
ContextFactoryImpl* WindowTreeHostImpl::context_factory_ = NULL;
////////////////////////////////////////////////////////////////////////////////
// RootLayoutManager, layout management for the root window's (one) child
class RootLayoutManager : public aura::LayoutManager {
public:
RootLayoutManager() : child_(NULL) {}
// Overridden from aura::LayoutManager
virtual void OnWindowResized() OVERRIDE;
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE;
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {}
virtual void OnChildWindowVisibilityChanged(aura::Window* child,
bool visible) OVERRIDE {}
virtual void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) OVERRIDE;
private:
aura::Window* child_;
DISALLOW_COPY_AND_ASSIGN(RootLayoutManager);
};
void RootLayoutManager::OnWindowResized() {
if (child_)
child_->SetBounds(gfx::Rect(child_->parent()->bounds().size()));
}
void RootLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
DCHECK(!child_);
child_ = child;
}
void RootLayoutManager::SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) {
SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size()));
}
////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostImpl, public:
......@@ -48,6 +86,8 @@ WindowTreeHostImpl::WindowTreeHostImpl(
}
context_factory_ = new ContextFactoryImpl(pipe.handle1.Pass());
aura::Env::GetInstance()->set_context_factory(context_factory_);
window()->SetLayoutManager(new RootLayoutManager());
}
WindowTreeHostImpl::~WindowTreeHostImpl() {
......
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