diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-20 05:23:50 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-20 05:23:50 +0000 |
commit | cce694a7b16fa819443ae18b7958ad41a8112d6a (patch) | |
tree | 1f0ec1d7040c7e523ad1603ed2278d1fb15739af /mojo/examples/aura_demo | |
parent | 60cbaaa10f673e8e85b1a7515d2353785538b136 (diff) | |
download | chromium_src-cce694a7b16fa819443ae18b7958ad41a8112d6a.zip chromium_src-cce694a7b16fa819443ae18b7958ad41a8112d6a.tar.gz chromium_src-cce694a7b16fa819443ae18b7958ad41a8112d6a.tar.bz2 |
Clean up WTH creation
WTHMojo was unable to observe bounds changes from its associated Node. Instead WTHMojo is now bound to a Node & derives bounds from it.
R=sky@chromium.org
BUG=none
Review URL: https://codereview.chromium.org/341953002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278614 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/examples/aura_demo')
-rw-r--r-- | mojo/examples/aura_demo/aura_demo.cc | 176 |
1 files changed, 26 insertions, 150 deletions
diff --git a/mojo/examples/aura_demo/aura_demo.cc b/mojo/examples/aura_demo/aura_demo.cc index b246484..de005a7 100644 --- a/mojo/examples/aura_demo/aura_demo.cc +++ b/mojo/examples/aura_demo/aura_demo.cc @@ -13,8 +13,11 @@ #include "mojo/public/cpp/application/application.h" #include "mojo/public/cpp/system/core.h" #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" +#include "mojo/services/public/cpp/view_manager/node.h" +#include "mojo/services/public/cpp/view_manager/view.h" +#include "mojo/services/public/cpp/view_manager/view_manager.h" +#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h" -#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" #include "ui/aura/client/default_capture_client.h" #include "ui/aura/client/window_tree_client.h" #include "ui/aura/env.h" @@ -27,34 +30,6 @@ namespace mojo { namespace examples { -void OnSetViewContentsDone(bool value) { - VLOG(1) << "OnSetViewContentsDone " << value; - DCHECK(value); -} - -bool CreateMapAndDupSharedBuffer(size_t size, - void** memory, - ScopedSharedBufferHandle* handle, - ScopedSharedBufferHandle* duped) { - MojoResult result = CreateSharedBuffer(NULL, size, handle); - if (result != MOJO_RESULT_OK) - return false; - DCHECK(handle->is_valid()); - - result = DuplicateBuffer(handle->get(), NULL, duped); - if (result != MOJO_RESULT_OK) - return false; - DCHECK(duped->is_valid()); - - result = MapBuffer( - handle->get(), 0, size, memory, MOJO_MAP_BUFFER_FLAG_NONE); - if (result != MOJO_RESULT_OK) - return false; - DCHECK(*memory); - - return true; -} - // Trivial WindowDelegate implementation that draws a colored background. class DemoWindowDelegate : public aura::WindowDelegate { public: @@ -128,97 +103,28 @@ class DemoWindowTreeClient : public aura::client::WindowTreeClient { DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient); }; -class AuraDemo; - -// Trivial ViewManagerClient implementation. Forwards to AuraDemo when -// connection established. -class ViewManagerClientImpl - : public InterfaceImpl<view_manager::ViewManagerClient> { - public: - explicit ViewManagerClientImpl(AuraDemo* aura_demo) - : aura_demo_(aura_demo) {} - virtual ~ViewManagerClientImpl() {} - - private: - void OnResult(bool result) { - VLOG(1) << "ViewManagerClientImpl::::OnResult result=" << result; - DCHECK(result); - } - - // ViewManagerClient: - virtual void OnViewManagerConnectionEstablished( - uint16_t connection_id, - const String& creator_url, - uint32_t next_server_change_id, - mojo::Array<view_manager::NodeDataPtr> nodes) OVERRIDE; - virtual void OnRootsAdded(Array<view_manager::NodeDataPtr> nodes) OVERRIDE { - NOTREACHED(); - } - virtual void OnServerChangeIdAdvanced( - uint32_t next_server_change_id) OVERRIDE { - } - virtual void OnNodeBoundsChanged(uint32_t node, - mojo::RectPtr old_bounds, - mojo::RectPtr new_bounds) OVERRIDE { - } - virtual void OnNodeHierarchyChanged( - uint32_t node, - uint32_t new_parent, - uint32_t old_parent, - uint32_t server_change_id, - mojo::Array<view_manager::NodeDataPtr> nodes) OVERRIDE { - } - virtual void OnNodeReordered( - uint32_t node_id, - uint32_t relative_node_id, - view_manager::OrderDirection direction, - uint32_t server_change_id) OVERRIDE { - } - virtual void OnNodeDeleted(uint32_t node, uint32_t server_change_id) - OVERRIDE { - } - virtual void OnNodeViewReplaced(uint32_t node, - uint32_t new_view_id, - uint32_t old_view_id) OVERRIDE { - } - virtual void OnViewDeleted(uint32_t view) OVERRIDE { - } - virtual void OnViewInputEvent(uint32_t view_id, - EventPtr event, - const Callback<void()>& callback) OVERRIDE { - } - virtual void DispatchOnViewInputEvent(uint32_t view_id, - EventPtr event) OVERRIDE { - } - - AuraDemo* aura_demo_; - - DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); -}; - -class AuraDemo : public Application, public WindowTreeHostMojoDelegate { +class AuraDemo : public Application, + public WindowTreeHostMojoDelegate, + public view_manager::ViewManagerDelegate { public: AuraDemo() - : view_manager_(NULL), - window1_(NULL), + : window1_(NULL), window2_(NULL), window21_(NULL), - view_id_(0) { - AddService<ViewManagerClientImpl>(this); + view_(NULL) { + view_manager::ViewManager::Create(this, this); } virtual ~AuraDemo() {} - void SetRoot(view_manager::ViewManagerService* view_manager, - uint32_t view_id) { - aura::Env::CreateInstance(true); - view_manager_ = view_manager; - view_id_ = view_id; - context_factory_.reset(new ContextFactoryMojo); - aura::Env::GetInstance()->set_context_factory(context_factory_.get()); - screen_.reset(ScreenMojo::Create()); - gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); - - window_tree_host_.reset(new WindowTreeHostMojo(gfx::Rect(800, 600), this)); + private: + // Overridden from view_manager::ViewManagerDelegate: + virtual void OnRootAdded(view_manager::ViewManager* view_manager, + view_manager::Node* root) OVERRIDE { + // TODO(beng): this function could be called multiple times! + view_ = view_manager::View::Create(view_manager); + root->SetActiveView(view_); + + window_tree_host_.reset(new WindowTreeHostMojo(root, this)); window_tree_host_->InitHost(); window_tree_client_.reset( @@ -250,26 +156,15 @@ class AuraDemo : public Application, public WindowTreeHostMojoDelegate { // WindowTreeHostMojoDelegate: virtual void CompositorContentsChanged(const SkBitmap& bitmap) OVERRIDE { - std::vector<unsigned char> data; - gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &data); - - void* memory = NULL; - ScopedSharedBufferHandle duped; - bool result = CreateMapAndDupSharedBuffer(data.size(), - &memory, - &shared_state_handle_, - &duped); - if (!result) - return; - - memcpy(memory, &data[0], data.size()); - - view_manager_->SetViewContents( - view_id_, duped.Pass(), static_cast<uint32_t>(data.size()), - base::Bind(&OnSetViewContentsDone)); + view_->SetContents(bitmap); } virtual void Initialize() OVERRIDE { + aura::Env::CreateInstance(true); + context_factory_.reset(new ContextFactoryMojo); + aura::Env::GetInstance()->set_context_factory(context_factory_.get()); + screen_.reset(ScreenMojo::Create()); + gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); } scoped_ptr<DemoWindowTreeClient> window_tree_client_; @@ -282,36 +177,17 @@ class AuraDemo : public Application, public WindowTreeHostMojoDelegate { scoped_ptr<DemoWindowDelegate> delegate2_; scoped_ptr<DemoWindowDelegate> delegate21_; - view_manager::ViewManagerService* view_manager_; - aura::Window* window1_; aura::Window* window2_; aura::Window* window21_; - uint32_t view_id_; + view_manager::View* view_; scoped_ptr<aura::WindowTreeHost> window_tree_host_; - ScopedSharedBufferHandle shared_state_handle_; - DISALLOW_COPY_AND_ASSIGN(AuraDemo); }; -void ViewManagerClientImpl::OnViewManagerConnectionEstablished( - uint16_t connection_id, - const String& creator_url, - uint32_t next_server_change_id, - mojo::Array<view_manager::NodeDataPtr> nodes) { - const uint32_t view_id = connection_id << 16 | 1; - client()->CreateView(view_id, base::Bind(&ViewManagerClientImpl::OnResult, - base::Unretained(this))); - client()->SetView(nodes[0]->node_id, view_id, - base::Bind(&ViewManagerClientImpl::OnResult, - base::Unretained(this))); - - aura_demo_->SetRoot(client(), view_id); -} - } // namespace examples // static |