Commit f3bc59bc authored by ben@chromium.org's avatar ben@chromium.org

Revert 274322 "Implement a demo that shows one app embedding ren..."

> Implement a demo that shows one app embedding rendering in another.
> 
> launcher inits the view manager, running the "window manager" app @ root.
> window manager embeds another app.
> 
> R=sky@chromium.org
> TEST=mojo_shell --origin=http://127.0.0.1:4444 --disable-cache mojo:mojo_demo_launcher
> http://crbug.com/365012
> 
> Review URL: https://codereview.chromium.org/303163005

TBR=ben@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274328 0039d316-1c4b-4281-b951-d872f2087c98
parent 8811093d
// 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 "base/basictypes.h"
#include "base/bind.h"
#include "base/run_loop.h"
#include "mojo/public/cpp/application/application.h"
#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
namespace mojo {
namespace examples {
class DemoLauncher : public Application {
public:
DemoLauncher() {}
virtual ~DemoLauncher() {}
private:
// Overridden from Application:
virtual void Initialize() MOJO_OVERRIDE {
ConnectTo<view_manager::IViewManagerInit>("mojo:mojo_view_manager",
&view_manager_init_);
view_manager_init_->Connect("mojo:mojo_window_manager",
base::Bind(&DemoLauncher::OnConnect,
base::Unretained(this)));
}
void OnConnect(bool success) {}
view_manager::IViewManagerInitPtr view_manager_init_;
DISALLOW_COPY_AND_ASSIGN(DemoLauncher);
};
} // namespace examples
// static
Application* Application::Create() {
return new examples::DemoLauncher;
}
} // namespace mojo
// 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 "base/basictypes.h"
#include "mojo/public/cpp/application/application.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_tree_node.h"
namespace mojo {
namespace examples {
class EmbeddedApp : public Application {
public:
EmbeddedApp() {}
virtual ~EmbeddedApp() {}
private:
// Overridden from Application:
virtual void Initialize() MOJO_OVERRIDE {
view_manager_ = new view_manager::ViewManager(this);
view_manager::View* view = view_manager::View::Create(view_manager_);
view_manager_->tree()->SetActiveView(view);
view->SetColor(SK_ColorYELLOW);
}
view_manager::ViewManager* view_manager_;
DISALLOW_COPY_AND_ASSIGN(EmbeddedApp);
};
} // namespace examples
// static
Application* Application::Create() {
return new examples::EmbeddedApp;
}
} // namespace mojo
\ No newline at end of file
......@@ -36,7 +36,10 @@ class SampleApp : public Application {
view_manager_->tree()->AddChild(node1);
node1->AddChild(node11);
view11->SetColor(SK_ColorRED);
gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true);
canvas.DrawColor(SK_ColorRED);
view11->SetContents(
skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(true));
}
private:
......
// 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 "base/basictypes.h"
#include "mojo/public/cpp/application/application.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_tree_node.h"
namespace mojo {
namespace examples {
class WindowManager : public Application {
public:
WindowManager() {}
virtual ~WindowManager() {}
private:
// Overridden from Application:
virtual void Initialize() MOJO_OVERRIDE {
view_manager_ = new view_manager::ViewManager(this);
view_manager::ViewTreeNode* node =
view_manager::ViewTreeNode::Create(view_manager_);
view_manager_->tree()->AddChild(node);
node->SetBounds(gfx::Rect(800, 600));
view_manager::View* view = view_manager::View::Create(view_manager_);
node->SetActiveView(view);
view->SetColor(SK_ColorBLUE);
view_manager::ViewTreeNode* embedded =
view_manager::ViewTreeNode::Create(view_manager_);
node->AddChild(embedded);
embedded->SetBounds(gfx::Rect(50, 50, 200, 200));
view_manager_->Embed("mojo:mojo_embedded_app", embedded);
}
view_manager::ViewManager* view_manager_;
DISALLOW_COPY_AND_ASSIGN(WindowManager);
};
} // namespace examples
// static
Application* Application::Create() {
return new examples::WindowManager;
}
} // namespace mojo
\ No newline at end of file
......@@ -63,9 +63,7 @@
'dependencies': [
'mojo_aura_demo',
'mojo_launcher',
'mojo_demo_launcher',
'mojo_embedded_app',
'mojo_window_manager',
'mojo_sample_view_manager_app',
'mojo_view_manager',
'mojo_view_manager_unittests',
],
......
......@@ -246,7 +246,7 @@
'includes': [ 'build/package_app.gypi' ],
},
{
'target_name': 'mojo_demo_launcher',
'target_name': 'mojo_sample_view_manager_app',
'type': 'shared_library',
'dependencies': [
'../base/base.gyp:base',
......@@ -254,60 +254,17 @@
'../ui/gfx/gfx.gyp:gfx',
'../ui/gfx/gfx.gyp:gfx_geometry',
'../ui/gl/gl.gyp:gl',
'mojo_application',
'mojo_cpp_bindings',
'mojo_environment_chromium',
'mojo_geometry_bindings',
'mojo_gles2',
'mojo_view_manager_bindings',
'mojo_system_impl',
'mojo_utility',
],
'sources': [
'examples/demo_launcher/demo_launcher.cc',
'public/cpp/application/lib/mojo_main_chromium.cc',
],
},
{
'target_name': 'mojo_window_manager',
'type': 'shared_library',
'dependencies': [
'../base/base.gyp:base',
'../ui/gfx/gfx.gyp:gfx_geometry',
'../ui/gl/gl.gyp:gl',
'mojo_application',
'mojo_cpp_bindings',
'mojo_environment_chromium',
'mojo_geometry_bindings',
'mojo_gles2',
'mojo_view_manager_lib',
'mojo_system_impl',
'mojo_utility',
],
'sources': [
'examples/window_manager/window_manager.cc',
'public/cpp/application/lib/mojo_main_chromium.cc',
],
},
{
'target_name': 'mojo_embedded_app',
'type': 'shared_library',
'dependencies': [
'../base/base.gyp:base',
'../ui/gfx/gfx.gyp:gfx_geometry',
'../ui/gl/gl.gyp:gl',
'mojo_application',
'mojo_cpp_bindings',
'mojo_environment_chromium',
'mojo_geometry_bindings',
'mojo_gles2',
'mojo_main_chromium',
'mojo_view_manager_lib',
'mojo_system_impl',
'mojo_utility',
],
'sources': [
'examples/embedded_app/embedded_app.cc',
'public/cpp/application/lib/mojo_main_chromium.cc',
'examples/sample_view_manager_app/sample_view_manager_app.cc',
],
},
],
......
include_rules = [
"+third_party/skia/include/core",
"+ui/gfx/geometry"
]
......@@ -7,7 +7,6 @@
#include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h"
#include "mojo/services/public/cpp/view_manager/lib/view_private.h"
#include "mojo/services/public/cpp/view_manager/view_observer.h"
#include "ui/gfx/canvas.h"
namespace mojo {
namespace view_manager {
......@@ -62,12 +61,6 @@ void View::SetContents(const SkBitmap& contents) {
ViewManagerPrivate(manager_).synchronizer()->SetViewContents(id_, contents);
}
void View::SetColor(SkColor color) {
gfx::Canvas canvas(node_->bounds().size(), 1.0f, true);
canvas.DrawColor(color);
SetContents(skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(true));
}
View::View(ViewManager* manager)
: id_(ViewManagerPrivate(manager).synchronizer()->CreateView()),
node_(NULL),
......
......@@ -4,8 +4,6 @@
#include "mojo/services/public/cpp/view_manager/view_manager.h"
#include "base/message_loop/message_loop.h"
#include "mojo/public/cpp/application/application.h"
#include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h"
#include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h"
#include "mojo/services/public/cpp/view_manager/view.h"
......@@ -13,13 +11,8 @@
namespace mojo {
namespace view_manager {
ViewManager::ViewManager(Application* application)
: synchronizer_(NULL),
tree_(NULL) {
application->AddService<ViewManagerSynchronizer>(this);
// Block in a nested message loop until the ViewManagerSynchronizer is set up.
base::MessageLoop::current()->Run();
}
ViewManager::ViewManager(ServiceProvider* service_provider)
: service_provider_(service_provider) {}
ViewManager::~ViewManager() {
while (!nodes_.empty()) {
......@@ -38,6 +31,10 @@ ViewManager::~ViewManager() {
}
}
void ViewManager::Init() {
synchronizer_.reset(new ViewManagerSynchronizer(this));
}
ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) {
IdToNodeMap::const_iterator it = nodes_.find(id);
return it != nodes_.end() ? it->second : NULL;
......@@ -48,9 +45,5 @@ View* ViewManager::GetViewById(TransportViewId id) {
return it != views_.end() ? it->second : NULL;
}
void ViewManager::Embed(const String& url, ViewTreeNode* node) {
synchronizer_->Embed(url, node->id());
}
} // namespace view_manager
} // namespace mojo
......@@ -20,11 +20,9 @@ class ViewManagerPrivate {
~ViewManagerPrivate();
ViewManagerSynchronizer* synchronizer() {
return manager_->synchronizer_;
}
void set_synchronizer(ViewManagerSynchronizer* synchronizer) {
manager_->synchronizer_ = synchronizer;
return manager_->synchronizer_.get();
}
ServiceProvider* service_provider() { return manager_->service_provider_; }
void set_root(ViewTreeNode* root) { manager_->tree_ = root; }
......
......@@ -5,7 +5,7 @@
#include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h"
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h"
......@@ -108,9 +108,7 @@ class ViewManagerTransaction {
// Node bounds.
TYPE_SET_BOUNDS,
// View contents
TYPE_SET_VIEW_CONTENTS,
// Embed.
TYPE_EMBED
TYPE_SET_VIEW_CONTENTS
};
ViewManagerTransaction(TransactionType transaction_type,
......@@ -127,7 +125,7 @@ class ViewManagerTransaction {
// service.
virtual void DoActionCompleted(bool success) = 0;
IViewManager* service() { return synchronizer_->service_; }
IViewManager* service() { return synchronizer_->service_.get(); }
TransportChangeId GetAndAdvanceNextServerChangeId() {
return synchronizer_->next_server_change_id_++;
......@@ -407,42 +405,26 @@ class SetViewContentsTransaction : public ViewManagerTransaction {
DISALLOW_COPY_AND_ASSIGN(SetViewContentsTransaction);
};
class EmbedTransaction : public ViewManagerTransaction {
public:
EmbedTransaction(const String& url,
TransportNodeId node_id,
ViewManagerSynchronizer* synchronizer)
: ViewManagerTransaction(TYPE_EMBED, synchronizer),
url_(url),
node_id_(node_id) {}
virtual ~EmbedTransaction() {}
private:
// Overridden from ViewManagerTransaction:
virtual void DoCommit() OVERRIDE {
std::vector<TransportNodeId> ids;
ids.push_back(node_id_);
service()->Connect(url_, Array<TransportNodeId>::From(ids),
ActionCompletedCallback());
}
virtual void DoActionCompleted(bool success) OVERRIDE {
// TODO(beng): recovery?
}
const String url_;
const TransportNodeId node_id_;
DISALLOW_COPY_AND_ASSIGN(EmbedTransaction);
};
ViewManagerSynchronizer::ViewManagerSynchronizer(ViewManager* view_manager)
: view_manager_(view_manager),
connected_(false),
connection_id_(0),
next_id_(1),
next_server_change_id_(0),
sync_factory_(this) {
ViewManagerPrivate(view_manager).set_synchronizer(this);
sync_factory_(this),
init_loop_(NULL) {
ConnectToService(
ViewManagerPrivate(view_manager_).service_provider(),
"mojo:mojo_view_manager",
&service_);
service_.set_client(this);
// Start a runloop. This loop is quit when the server tells us about the
// connection (OnConnectionEstablished()).
base::RunLoop loop;
init_loop_ = &loop;
init_loop_->Run();
init_loop_ = NULL;
}
ViewManagerSynchronizer::~ViewManagerSynchronizer() {
......@@ -535,20 +517,6 @@ void ViewManagerSynchronizer::SetViewContents(TransportViewId view_id,
Sync();
}
void ViewManagerSynchronizer::Embed(const String& url,
TransportNodeId node_id) {
DCHECK(connected_);
pending_transactions_.push_back(new EmbedTransaction(url, node_id, this));
Sync();
}
////////////////////////////////////////////////////////////////////////////////
// ViewManagerSynchronizer, InterfaceImpl overrides:
void ViewManagerSynchronizer::OnConnectionEstablished() {
service_ = client();
}
////////////////////////////////////////////////////////////////////////////////
// ViewManagerSynchronizer, IViewManagerClient implementation:
......@@ -560,12 +528,12 @@ void ViewManagerSynchronizer::OnViewManagerConnectionEstablished(
connection_id_ = connection_id;
next_server_change_id_ = next_server_change_id;
ViewManagerPrivate(view_manager()).set_root(
BuildNodeTree(view_manager(), nodes));
ViewManagerPrivate(view_manager_).set_root(
BuildNodeTree(view_manager_, nodes));
if (init_loop_)
init_loop_->Quit();
Sync();
base::MessageLoop::current()->Quit();
}
void ViewManagerSynchronizer::OnServerChangeIdAdvanced(
......@@ -576,7 +544,7 @@ void ViewManagerSynchronizer::OnServerChangeIdAdvanced(
void ViewManagerSynchronizer::OnNodeBoundsChanged(uint32 node_id,
RectPtr old_bounds,
RectPtr new_bounds) {
ViewTreeNode* node = view_manager()->GetNodeById(node_id);
ViewTreeNode* node = view_manager_->GetNodeById(node_id);
ViewTreeNodePrivate(node).LocalSetBounds(old_bounds.To<gfx::Rect>(),
new_bounds.To<gfx::Rect>());
}
......@@ -590,11 +558,11 @@ void ViewManagerSynchronizer::OnNodeHierarchyChanged(
// TODO: deal with |nodes|.
next_server_change_id_ = server_change_id + 1;
BuildNodeTree(view_manager(), nodes);
BuildNodeTree(view_manager_, nodes);
ViewTreeNode* new_parent = view_manager()->GetNodeById(new_parent_id);
ViewTreeNode* old_parent = view_manager()->GetNodeById(old_parent_id);
ViewTreeNode* node = view_manager()->GetNodeById(node_id);
ViewTreeNode* new_parent = view_manager_->GetNodeById(new_parent_id);
ViewTreeNode* old_parent = view_manager_->GetNodeById(old_parent_id);
ViewTreeNode* node = view_manager_->GetNodeById(node_id);
if (new_parent)
ViewTreeNodePrivate(new_parent).LocalAddChild(node);
else
......@@ -605,7 +573,7 @@ void ViewManagerSynchronizer::OnNodeDeleted(uint32_t node_id,
uint32_t server_change_id) {
next_server_change_id_ = server_change_id + 1;
ViewTreeNode* node = view_manager()->GetNodeById(node_id);
ViewTreeNode* node = view_manager_->GetNodeById(node_id);
if (node)
ViewTreeNodePrivate(node).LocalDestroy();
}
......@@ -613,24 +581,24 @@ void ViewManagerSynchronizer::OnNodeDeleted(uint32_t node_id,
void ViewManagerSynchronizer::OnNodeViewReplaced(uint32_t node_id,
uint32_t new_view_id,
uint32_t old_view_id) {
ViewTreeNode* node = view_manager()->GetNodeById(node_id);
View* new_view = view_manager()->GetViewById(new_view_id);
ViewTreeNode* node = view_manager_->GetNodeById(node_id);
View* new_view = view_manager_->GetViewById(new_view_id);
if (!new_view && new_view_id != 0) {
// This client wasn't aware of this View until now.
new_view = ViewPrivate::LocalCreate();
ViewPrivate private_view(new_view);
private_view.set_view_manager(view_manager());
private_view.set_view_manager(view_manager_);
private_view.set_id(new_view_id);
private_view.set_node(node);
ViewManagerPrivate(view_manager()).AddView(new_view->id(), new_view);
ViewManagerPrivate(view_manager_).AddView(new_view->id(), new_view);
}
View* old_view = view_manager()->GetViewById(old_view_id);
View* old_view = view_manager_->GetViewById(old_view_id);
DCHECK_EQ(old_view, node->active_view());
ViewTreeNodePrivate(node).LocalSetActiveView(new_view);
}
void ViewManagerSynchronizer::OnViewDeleted(uint32_t view_id) {
View* view = view_manager()->GetViewById(view_id);
View* view = view_manager_->GetViewById(view_id);
if (view)
ViewPrivate(view).LocalDestroy();
}
......
......@@ -15,6 +15,10 @@
class SkBitmap;
namespace base {
class RunLoop;
}
namespace mojo {
namespace view_manager {
......@@ -22,7 +26,7 @@ class ViewManager;
class ViewManagerTransaction;
// Manages the connection with the View Manager service.
class ViewManagerSynchronizer : public InterfaceImpl<IViewManagerClient> {
class ViewManagerSynchronizer : public IViewManagerClient {
public:
explicit ViewManagerSynchronizer(ViewManager* view_manager);
virtual ~ViewManagerSynchronizer();
......@@ -50,8 +54,6 @@ class ViewManagerSynchronizer : public InterfaceImpl<IViewManagerClient> {
void SetBounds(TransportNodeId node_id, const gfx::Rect& bounds);
void SetViewContents(TransportViewId view_id, const SkBitmap& contents);
void Embed(const String& url, TransportNodeId node_id);
void set_changes_acked_callback(const base::Callback<void(void)>& callback) {
changes_acked_callback_ = callback;
}
......@@ -63,9 +65,6 @@ class ViewManagerSynchronizer : public InterfaceImpl<IViewManagerClient> {
friend class ViewManagerTransaction;
typedef ScopedVector<ViewManagerTransaction> Transactions;
// Overridden from InterfaceImpl:
virtual void OnConnectionEstablished() OVERRIDE;
// Overridden from IViewManagerClient:
virtual void OnViewManagerConnectionEstablished(
TransportConnectionId connection_id,
......@@ -97,9 +96,7 @@ class ViewManagerSynchronizer : public InterfaceImpl<IViewManagerClient> {
// front of the queue.
void RemoveFromPendingQueue(ViewManagerTransaction* transaction);
ViewManager* view_manager() { return view_manager_.get(); }
scoped_ptr<ViewManager> view_manager_;
ViewManager* view_manager_;
bool connected_;
TransportConnectionId connection_id_;
uint16_t next_id_;
......@@ -109,9 +106,13 @@ class ViewManagerSynchronizer : public InterfaceImpl<IViewManagerClient> {
base::WeakPtrFactory<ViewManagerSynchronizer> sync_factory_;
// Non-NULL while blocking on the connection to |service_| during
// construction.
base::RunLoop* init_loop_;
base::Callback<void(void)> changes_acked_callback_;
IViewManager* service_;
IViewManagerPtr service_;
DISALLOW_COPY_AND_ASSIGN(ViewManagerSynchronizer);
};
......
......@@ -258,8 +258,8 @@ class ViewManagerTest : public testing::Test {
ViewManagerTest() : commit_count_(0) {}
protected:
ViewManager* view_manager_1() { return view_manager_1_; }
ViewManager* view_manager_2() { return view_manager_2_; }
ViewManager* view_manager_1() { return view_manager_1_.get(); }
ViewManager* view_manager_2() { return view_manager_2_.get(); }
ViewTreeNode* CreateNodeInParent(ViewTreeNode* parent) {
ViewManager* parent_manager = ViewTreeNodePrivate(parent).view_manager();
......@@ -269,19 +269,23 @@ class ViewManagerTest : public testing::Test {
}
void DestroyViewManager1() {
// view_manager_1_.reset();
view_manager_1_.reset();
}
private:
// Overridden from testing::Test:
virtual void SetUp() OVERRIDE {
test_helper_.Init();
view_manager_1_.reset(new ViewManager(test_helper_.service_provider()));
view_manager_2_.reset(new ViewManager(test_helper_.service_provider()));
view_manager_1_->Init();
view_manager_2_->Init();
}
base::MessageLoop loop_;
shell::ShellTestHelper test_helper_;
ViewManager* view_manager_1_;
ViewManager* view_manager_2_;
scoped_ptr<ViewManager> view_manager_1_;
scoped_ptr<ViewManager> view_manager_2_;
int commit_count_;
DISALLOW_COPY_AND_ASSIGN(ViewManagerTest);
......
......@@ -8,7 +8,6 @@
#include "base/basictypes.h"
#include "base/observer_list.h"
#include "mojo/services/public/cpp/view_manager/view_manager_types.h"
#include "third_party/skia/include/core/SkColor.h"
class SkBitmap;
......@@ -32,9 +31,7 @@ class View {
void AddObserver(ViewObserver* observer);
void RemoveObserver(ViewObserver* observer);
// TODO(beng): temporary only.
void SetContents(const SkBitmap& contents);
void SetColor(SkColor color);
private:
friend class ViewPrivate;
......
......@@ -13,7 +13,7 @@
#include "mojo/services/public/cpp/view_manager/view_tree_node.h"
namespace mojo {
class Application;
class ServiceProvider;
namespace view_manager {
class View;
......@@ -21,12 +21,17 @@ class ViewManagerSynchronizer;
class ViewTreeNode;
// Approximately encapsulates the View Manager service.
// Has a synchronizer that keeps a client model in sync with the service.
// Owned by the connection.
// Owns a synchronizer that keeps a client model in sync with the service.
// Owned by the creator.
//
// TODO: displays
class ViewManager {
public:
explicit ViewManager(ServiceProvider* service_provider);
~ViewManager();
// Connects to the View Manager service. This method must be called before
// using any other View Manager lib class or function.
// Blocks on establishing the connection and subsequently receiving a node
// tree from the service.
// TODO(beng): blocking is currently achieved by running a nested runloop,
......@@ -34,22 +39,20 @@ class ViewManager {
// we should instead wait on the client pipe receiving a
// connection established message.
// TODO(beng): this method could optionally not block if supplied a callback.
explicit ViewManager(Application* application);
~ViewManager();
void Init();
ViewTreeNode* tree() { return tree_; }
ViewTreeNode* GetNodeById(TransportNodeId id);
View* GetViewById(TransportViewId id);
void Embed(const String& url, ViewTreeNode* node);
private:
friend class ViewManagerPrivate;
typedef std::map<TransportNodeId, ViewTreeNode*> IdToNodeMap;
typedef std::map<TransportViewId, View*> IdToViewMap;
ViewManagerSynchronizer* synchronizer_;
ServiceProvider* service_provider_;
scoped_ptr<ViewManagerSynchronizer> synchronizer_;
ViewTreeNode* tree_;
IdToNodeMap nodes_;
......
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