Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1778)

Unified Diff: mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc

Issue 292813008: Implement SetViewContents in the client lib (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc
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 76a6b52f9f190419c6438144f3372b0afd399cc5..495a036dacab5bc74100c1a2febe9ed57f5d0c93 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:
« no previous file with comments | « mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h ('k') | mojo/services/public/cpp/view_manager/view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698