summaryrefslogtreecommitdiffstats
path: root/mojo/services
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-23 01:20:09 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-23 01:20:09 +0000
commite2a0d62920e054b226ab463735b3e1aa04cbcab2 (patch)
tree1f33af0be210a9199fe0cc889ddca4f621e09f89 /mojo/services
parent219fbb41ce021eabc718822d204feb203bf8eae0 (diff)
downloadchromium_src-e2a0d62920e054b226ab463735b3e1aa04cbcab2.zip
chromium_src-e2a0d62920e054b226ab463735b3e1aa04cbcab2.tar.gz
chromium_src-e2a0d62920e054b226ab463735b3e1aa04cbcab2.tar.bz2
Implement SetViewContents in the client lib.
Updates the view manager sample app too.\ R=sky@chromium.org http://crbug.com/365012 Review URL: https://codereview.chromium.org/292813008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272389 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/services')
-rw-r--r--mojo/services/native_viewport/native_viewport_win.cc9
-rw-r--r--mojo/services/public/cpp/view_manager/lib/DEPS3
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view.cc5
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc79
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h3
-rw-r--r--mojo/services/public/cpp/view_manager/view.h4
-rw-r--r--mojo/services/public/interfaces/view_manager/view_manager.mojom2
-rw-r--r--mojo/services/view_manager/view_manager_connection.cc9
-rw-r--r--mojo/services/view_manager/view_manager_connection.h3
9 files changed, 110 insertions, 7 deletions
diff --git a/mojo/services/native_viewport/native_viewport_win.cc b/mojo/services/native_viewport/native_viewport_win.cc
index 86e7ce9..84bfdc3 100644
--- a/mojo/services/native_viewport/native_viewport_win.cc
+++ b/mojo/services/native_viewport/native_viewport_win.cc
@@ -20,7 +20,14 @@ gfx::Rect GetWindowBoundsForClientBounds(DWORD style, DWORD ex_style,
wr.right = bounds.x() + bounds.width();
wr.bottom = bounds.y() + bounds.height();
AdjustWindowRectEx(&wr, style, FALSE, ex_style);
- return gfx::Rect(wr.left, wr.top, wr.right - wr.left, wr.bottom - wr.top);
+
+ // Make sure to keep the window onscreen, as AdjustWindowRectEx() may have
+ // moved part of it offscreen.
+ gfx::Rect window_bounds(wr.left, wr.top,
+ wr.right - wr.left, wr.bottom - wr.top);
+ window_bounds.set_x(std::max(0, window_bounds.x()));
+ window_bounds.set_y(std::max(0, window_bounds.y()));
+ return window_bounds;
}
}
diff --git a/mojo/services/public/cpp/view_manager/lib/DEPS b/mojo/services/public/cpp/view_manager/lib/DEPS
index a3f6c8f..7ae7fe7 100644
--- a/mojo/services/public/cpp/view_manager/lib/DEPS
+++ b/mojo/services/public/cpp/view_manager/lib/DEPS
@@ -1,6 +1,7 @@
include_rules = [
"+mojo/geometry",
- "+ui/gfx/geometry"
+ "+third_party/skia",
+ "+ui/gfx",
]
specific_include_rules = {
diff --git a/mojo/services/public/cpp/view_manager/lib/view.cc b/mojo/services/public/cpp/view_manager/lib/view.cc
index 1a85ae1..b11929c 100644
--- a/mojo/services/public/cpp/view_manager/lib/view.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view.cc
@@ -56,6 +56,11 @@ void View::RemoveObserver(ViewObserver* observer) {
observers_.RemoveObserver(observer);
}
+void View::SetContents(const SkBitmap& contents) {
+ if (manager_)
+ ViewManagerPrivate(manager_).synchronizer()->SetViewContents(id_, contents);
+}
+
View::View(ViewManager* manager)
: id_(ViewManagerPrivate(manager).synchronizer()->CreateView()),
node_(NULL),
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc
index 76a6b52..495a036 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc
@@ -12,6 +12,8 @@
#include "mojo/services/public/cpp/view_manager/lib/view_private.h"
#include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h"
#include "mojo/services/public/cpp/view_manager/util.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/gfx/codec/png_codec.h"
namespace mojo {
namespace view_manager {
@@ -101,7 +103,9 @@ class ViewManagerTransaction {
// View replacement.
TYPE_SET_ACTIVE_VIEW,
// Node bounds.
- TYPE_SET_BOUNDS
+ TYPE_SET_BOUNDS,
+ // View contents
+ TYPE_SET_VIEW_CONTENTS
};
ViewManagerTransaction(TransactionType transaction_type,
@@ -333,6 +337,71 @@ class SetBoundsTransaction : public ViewManagerTransaction {
DISALLOW_COPY_AND_ASSIGN(SetBoundsTransaction);
};
+class SetViewContentsTransaction : public ViewManagerTransaction {
+ public:
+ SetViewContentsTransaction(TransportViewId view_id,
+ const SkBitmap& contents,
+ ViewManagerSynchronizer* synchronizer)
+ : ViewManagerTransaction(TYPE_SET_VIEW_CONTENTS, synchronizer),
+ view_id_(view_id),
+ contents_(contents) {}
+ virtual ~SetViewContentsTransaction() {}
+
+ private:
+ // Overridden from ViewManagerTransaction:
+ virtual void DoCommit() OVERRIDE {
+ std::vector<unsigned char> data;
+ gfx::PNGCodec::EncodeBGRASkBitmap(contents_, 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());
+
+ AllocationScope scope;
+ service()->SetViewContents(view_id_, duped.Pass(), data.size(),
+ ActionCompletedCallback());
+ }
+ virtual void DoActionCompleted(bool success) OVERRIDE {
+ // TODO(beng): recovery?
+ }
+
+ 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;
+ }
+
+ const TransportViewId view_id_;
+ const SkBitmap contents_;
+ ScopedSharedBufferHandle shared_state_handle_;
+
+ DISALLOW_COPY_AND_ASSIGN(SetViewContentsTransaction);
+};
+
ViewManagerSynchronizer::ViewManagerSynchronizer(ViewManager* view_manager)
: view_manager_(view_manager),
connected_(false),
@@ -435,6 +504,14 @@ void ViewManagerSynchronizer::SetBounds(TransportNodeId node_id,
Sync();
}
+void ViewManagerSynchronizer::SetViewContents(TransportViewId view_id,
+ const SkBitmap& contents) {
+ DCHECK(connected_);
+ pending_transactions_.push_back(
+ new SetViewContentsTransaction(view_id, contents, this));
+ Sync();
+}
+
////////////////////////////////////////////////////////////////////////////////
// ViewManagerSynchronizer, IViewManagerClient implementation:
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h
index 5e5c79f..9330336 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h
@@ -13,6 +13,8 @@
#include "mojo/services/public/cpp/view_manager/view_manager_types.h"
#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
+class SkBitmap;
+
namespace base {
class RunLoop;
}
@@ -50,6 +52,7 @@ class ViewManagerSynchronizer : public IViewManagerClient {
void SetActiveView(TransportNodeId node_id, TransportViewId view_id);
void SetBounds(TransportNodeId node_id, const gfx::Rect& bounds);
+ void SetViewContents(TransportViewId view_id, const SkBitmap& contents);
void set_changes_acked_callback(const base::Callback<void(void)>& callback) {
changes_acked_callback_ = callback;
diff --git a/mojo/services/public/cpp/view_manager/view.h b/mojo/services/public/cpp/view_manager/view.h
index 40d660f..c4e61b8 100644
--- a/mojo/services/public/cpp/view_manager/view.h
+++ b/mojo/services/public/cpp/view_manager/view.h
@@ -9,6 +9,8 @@
#include "base/observer_list.h"
#include "mojo/services/public/cpp/view_manager/view_manager_types.h"
+class SkBitmap;
+
namespace mojo {
namespace view_manager {
@@ -29,6 +31,8 @@ class View {
void AddObserver(ViewObserver* observer);
void RemoveObserver(ViewObserver* observer);
+ void SetContents(const SkBitmap& contents);
+
private:
friend class ViewPrivate;
diff --git a/mojo/services/public/interfaces/view_manager/view_manager.mojom b/mojo/services/public/interfaces/view_manager/view_manager.mojom
index 7e0f9f7..8c9cad32 100644
--- a/mojo/services/public/interfaces/view_manager/view_manager.mojom
+++ b/mojo/services/public/interfaces/view_manager/view_manager.mojom
@@ -85,7 +85,7 @@ interface IViewManager {
// Shows the specified image (png encoded) in the specified view.
SetViewContents(uint32 view_id,
handle<shared_buffer> buffer,
- uint32 buffer_size);
+ uint32 buffer_size) => (bool success);
// Sets the ids of the roots for the specified connection.
// TODO(sky): this is temporary for testing. This needs to be conveyed at
diff --git a/mojo/services/view_manager/view_manager_connection.cc b/mojo/services/view_manager/view_manager_connection.cc
index e8ce02c..76656b6 100644
--- a/mojo/services/view_manager/view_manager_connection.cc
+++ b/mojo/services/view_manager/view_manager_connection.cc
@@ -571,13 +571,17 @@ void ViewManagerConnection::SetView(
void ViewManagerConnection::SetViewContents(
TransportViewId view_id,
ScopedSharedBufferHandle buffer,
- uint32_t buffer_size) {
+ uint32_t buffer_size,
+ const Callback<void(bool)>& callback) {
View* view = GetView(ViewIdFromTransportId(view_id));
- if (!view)
+ if (!view) {
+ callback.Run(false);
return;
+ }
void* handle_data;
if (MapBuffer(buffer.get(), 0, buffer_size, &handle_data,
MOJO_MAP_BUFFER_FLAG_NONE) != MOJO_RESULT_OK) {
+ callback.Run(false);
return;
}
SkBitmap bitmap;
@@ -585,6 +589,7 @@ void ViewManagerConnection::SetViewContents(
buffer_size, &bitmap);
view->SetBitmap(bitmap);
UnmapBuffer(handle_data);
+ callback.Run(true);
}
void ViewManagerConnection::SetRoots(
diff --git a/mojo/services/view_manager/view_manager_connection.h b/mojo/services/view_manager/view_manager_connection.h
index 5653ac5..d0c16ab 100644
--- a/mojo/services/view_manager/view_manager_connection.h
+++ b/mojo/services/view_manager/view_manager_connection.h
@@ -160,7 +160,8 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
const Callback<void(bool)>& callback) OVERRIDE;
virtual void SetViewContents(TransportViewId view_id,
ScopedSharedBufferHandle buffer,
- uint32_t buffer_size) OVERRIDE;
+ uint32_t buffer_size,
+ const Callback<void(bool)>& callback) OVERRIDE;
virtual void SetRoots(
TransportConnectionId connection_id,
const Array<TransportNodeId>& transport_node_ids,