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

Unified Diff: ppapi/proxy/ppb_image_data_proxy.cc

Issue 8790009: Regularize how ImageData and Graphics2D are created. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment Created 9 years 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: ppapi/proxy/ppb_image_data_proxy.cc
diff --git a/ppapi/proxy/ppb_image_data_proxy.cc b/ppapi/proxy/ppb_image_data_proxy.cc
index 32c24a942314f11ceb2415dcad0faac491cc9b05..20f8f62069b453dc211c70eb2e6dc2a85c59ddc9 100644
--- a/ppapi/proxy/ppb_image_data_proxy.cc
+++ b/ppapi/proxy/ppb_image_data_proxy.cc
@@ -18,6 +18,7 @@
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/shared_impl/host_resource.h"
#include "ppapi/shared_impl/resource.h"
+#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "skia/ext/platform_canvas.h"
#include "ui/gfx/surface/transport_dib.h"
@@ -94,5 +95,88 @@ ImageHandle ImageData::HandleFromInt(int32_t i) {
#endif
}
+PPB_ImageData_Proxy::PPB_ImageData_Proxy(Dispatcher* dispatcher)
+ : InterfaceProxy(dispatcher) {
+}
+
+PPB_ImageData_Proxy::~PPB_ImageData_Proxy() {
+}
+
+// static
+PP_Resource PPB_ImageData_Proxy::CreateProxyResource(PP_Instance instance,
+ PP_ImageDataFormat format,
+ const PP_Size& size,
+ PP_Bool init_to_zero) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return 0;
+
+ HostResource result;
+ std::string image_data_desc;
+ ImageHandle image_handle = ImageData::NullHandle;
+ dispatcher->Send(new PpapiHostMsg_PPBImageData_Create(
+ kApiID, instance, format, size, init_to_zero,
+ &result, &image_data_desc, &image_handle));
+
+ if (result.is_null() || image_data_desc.size() != sizeof(PP_ImageDataDesc))
+ return 0;
+
+ // We serialize the PP_ImageDataDesc just by copying to a string.
+ PP_ImageDataDesc desc;
+ memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc));
+
+ return (new ImageData(result, desc, image_handle))->GetReference();
+}
+
+bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(PPB_ImageData_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_Create, OnHostMsgCreate)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance,
+ int32_t format,
+ const PP_Size& size,
+ PP_Bool init_to_zero,
+ HostResource* result,
+ std::string* image_data_desc,
+ ImageHandle* result_image_handle) {
+ *result_image_handle = ImageData::NullHandle;
+
+ thunk::EnterResourceCreation enter(instance);
+ if (enter.failed())
+ return;
+
+ PP_Resource resource = enter.functions()->CreateImageData(
+ instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero);
+ if (!resource)
+ return;
+ result->SetHostResource(instance, resource);
+
+ // Get the description, it's just serialized as a string.
+ thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter_resource(
+ resource, false);
+ PP_ImageDataDesc desc;
+ if (enter_resource.object()->Describe(&desc) == PP_TRUE) {
+ image_data_desc->resize(sizeof(PP_ImageDataDesc));
+ memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc));
+ }
+
+ // Get the shared memory handle.
+ uint32_t byte_count = 0;
+ int32_t handle = 0;
+ if (enter_resource.object()->GetSharedMemory(&handle, &byte_count) == PP_OK) {
+#if defined(OS_WIN)
+ ImageHandle ih = ImageData::HandleFromInt(handle);
+ *result_image_handle = dispatcher()->ShareHandleWithRemote(ih, false);
+#else
+ *result_image_handle = ImageData::HandleFromInt(handle);
+#endif
+ }
+}
+
} // namespace proxy
} // namespace ppapi

Powered by Google App Engine
This is Rietveld 408576698