summaryrefslogtreecommitdiffstats
path: root/ppapi/thunk
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-06 22:55:47 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-06 22:55:47 +0000
commit6239d34076222cbfe1d42770c604822b0ba894f4 (patch)
treed873cdf138b002bb2d2d4a554ba4fcd210251760 /ppapi/thunk
parentc50a948dd9c07a71524949a28a5347e11d80da47 (diff)
downloadchromium_src-6239d34076222cbfe1d42770c604822b0ba894f4.zip
chromium_src-6239d34076222cbfe1d42770c604822b0ba894f4.tar.gz
chromium_src-6239d34076222cbfe1d42770c604822b0ba894f4.tar.bz2
This implements the new system for Graphics2D only.
This works by adding a new thunk layer that will forward to an "API" that's either per-instance (function APIs) or per-resource (resource APIs). The proxying and such is then implemented in terms of this C++ API. Ideally the trackers of the PP_Resource/PP_Instance -> object mapping would be shared between the plugin and renderer processes. To keep this patch under control, I did this as a virtual base class which is implemented by ppapi::proxy::PluginResourceTracker and webkit::ppapi::ResourceTracker. Later, the functionality of these objects should be shared in a common tracker class. Still to do it a lot of cleanup and merging of things. Also, the namespaces are a bit out of control. Review URL: http://codereview.chromium.org/6905088 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84519 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/thunk')
-rw-r--r--ppapi/thunk/enter.h91
-rw-r--r--ppapi/thunk/ppb_graphics_2d_api.h28
-rw-r--r--ppapi/thunk/ppb_graphics_2d_thunk.cc95
-rw-r--r--ppapi/thunk/ppb_image_data_api.h21
-rw-r--r--ppapi/thunk/ppb_image_data_thunk.cc83
-rw-r--r--ppapi/thunk/resource_creation_api.h41
-rw-r--r--ppapi/thunk/thunk.h24
7 files changed, 383 insertions, 0 deletions
diff --git a/ppapi/thunk/enter.h b/ppapi/thunk/enter.h
new file mode 100644
index 0000000..1a18cf6
--- /dev/null
+++ b/ppapi/thunk/enter.h
@@ -0,0 +1,91 @@
+// Copyright (c) 2011 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.
+
+#ifndef PPAPI_THUNK_ENTER_H_
+#define PPAPI_THUNK_ENTER_H_
+
+#include "base/basictypes.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/proxy/interface_id.h"
+#include "ppapi/shared_impl/function_group_base.h"
+#include "ppapi/shared_impl/resource_object_base.h"
+#include "ppapi/shared_impl/tracker_base.h"
+
+namespace ppapi {
+namespace thunk {
+
+// EnterHost* helper objects: These objects wrap a call from the C PPAPI into
+// the internal implementation. They make sure the lock is acquired and will
+// automatically set up some stuff for you.
+//
+// You should always check whether the enter succeeded before using the object.
+// If this fails, then the instance or resource ID supplied was invalid.
+//
+// The |report_error| arguments to the constructor should indicate if errors
+// should be logged to the console. If the calling function expects that the
+// input values are correct (the normal case), this should be set to true. In
+// some case like |IsFoo(PP_Resource)| the caller is quersioning whether their
+// handle is this type, and we don't want to report an error if it's not.
+//
+// Standalone functions: EnterHostFunction
+// Automatically gets the implementation for the function API for the
+// supplied PP_Instance.
+//
+// Resource member functions: EnterHostResource
+// Automatically interprets the given PP_Resource as a resource ID and sets
+// up the resource object for you.
+
+template<typename FunctionsT>
+class EnterFunction {
+ public:
+ EnterFunction(PP_Instance instance, bool report_error)
+ : functions_(NULL) {
+ shared_impl::FunctionGroupBase* base =
+ shared_impl::TrackerBase::Get()->GetFunctionAPI(
+ instance, FunctionsT::interface_id);
+ if (base)
+ functions_ = base->GetAs<FunctionsT>();
+ // TODO(brettw) check error and if report_error is set, do something.
+ }
+ ~EnterFunction() {}
+
+ bool succeeded() const { return !!functions_; }
+ bool failed() const { return !functions_; }
+
+ FunctionsT* functions() { return functions_; }
+
+ private:
+ FunctionsT* functions_;
+
+ DISALLOW_COPY_AND_ASSIGN(EnterFunction);
+};
+
+template<typename ResourceT>
+class EnterResource {
+ public:
+ EnterResource(PP_Resource resource, bool report_error)
+ : object_(NULL) {
+ shared_impl::ResourceObjectBase* base =
+ shared_impl::TrackerBase::Get()->GetResourceAPI(resource);
+ if (base)
+ object_ = base->GetAs<ResourceT>();
+ // TODO(brettw) check error and if report_error is set, do something.
+ }
+ ~EnterResource() {}
+
+ bool succeeded() const { return !!object_; }
+ bool failed() const { return !object_; }
+
+ ResourceT* object() { return object_; }
+
+ private:
+ ResourceT* object_;
+
+ DISALLOW_COPY_AND_ASSIGN(EnterResource);
+};
+
+} // namespace thunk
+} // namespace ppapi
+
+#endif // PPAPI_THUNK_ENTER_H_
diff --git a/ppapi/thunk/ppb_graphics_2d_api.h b/ppapi/thunk/ppb_graphics_2d_api.h
new file mode 100644
index 0000000..ae6dc45
--- /dev/null
+++ b/ppapi/thunk/ppb_graphics_2d_api.h
@@ -0,0 +1,28 @@
+// Copyright (c) 2011 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 "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/pp_point.h"
+#include "ppapi/c/pp_rect.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/pp_size.h"
+
+namespace ppapi {
+namespace thunk {
+
+class PPB_Graphics2D_API {
+ public:
+ virtual PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque) = 0;
+ virtual void PaintImageData(PP_Resource image_data,
+ const PP_Point* top_left,
+ const PP_Rect* src_rect) = 0;
+ virtual void Scroll(const PP_Rect* clip_rect,
+ const PP_Point* amount) = 0;
+ virtual void ReplaceContents(PP_Resource image_data) = 0;
+ virtual int32_t Flush(PP_CompletionCallback callback) = 0;
+};
+
+} // namespace thunk
+} // namespace ppapi
diff --git a/ppapi/thunk/ppb_graphics_2d_thunk.cc b/ppapi/thunk/ppb_graphics_2d_thunk.cc
new file mode 100644
index 0000000..f3ef473
--- /dev/null
+++ b/ppapi/thunk/ppb_graphics_2d_thunk.cc
@@ -0,0 +1,95 @@
+// Copyright (c) 2011 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 "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/c/ppb_graphics_2d.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_graphics_2d_api.h"
+#include "ppapi/thunk/resource_creation_api.h"
+
+namespace ppapi {
+namespace thunk {
+
+namespace {
+
+PP_Resource Create(PP_Instance instance,
+ const PP_Size* size,
+ PP_Bool is_always_opaque) {
+ EnterFunction<ResourceCreationAPI> enter(instance, true);
+ if (enter.failed())
+ return 0;
+ return enter.functions()->CreateGraphics2D(instance, *size, is_always_opaque);
+}
+
+PP_Bool IsGraphics2D(PP_Resource resource) {
+ EnterResource<PPB_Graphics2D_API> enter(resource, false);
+ return enter.succeeded() ? PP_TRUE : PP_FALSE;
+}
+
+PP_Bool Describe(PP_Resource graphics_2d,
+ PP_Size* size,
+ PP_Bool* is_always_opaque) {
+ EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true);
+ if (enter.failed()) {
+ size->width = 0;
+ size->height = 0;
+ *is_always_opaque = PP_FALSE;
+ return PP_FALSE;
+ }
+ return enter.object()->Describe(size, is_always_opaque);
+}
+
+void PaintImageData(PP_Resource graphics_2d,
+ PP_Resource image_data,
+ const PP_Point* top_left,
+ const PP_Rect* src_rect) {
+ EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true);
+ if (enter.failed())
+ return;
+ enter.object()->PaintImageData(image_data, top_left, src_rect);
+}
+
+void Scroll(PP_Resource graphics_2d,
+ const PP_Rect* clip_rect,
+ const PP_Point* amount) {
+ EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true);
+ if (enter.failed())
+ return;
+ enter.object()->Scroll(clip_rect, amount);
+}
+
+void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) {
+ EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true);
+ if (enter.failed())
+ return;
+ enter.object()->ReplaceContents(image_data);
+}
+
+int32_t Flush(PP_Resource graphics_2d,
+ PP_CompletionCallback callback) {
+ EnterResource<PPB_Graphics2D_API> enter(graphics_2d, true);
+ if (enter.failed())
+ return PP_ERROR_BADARGUMENT;
+ return enter.object()->Flush(callback);
+}
+
+const PPB_Graphics2D g_ppb_graphics_2d_thunk = {
+ &Create,
+ &IsGraphics2D,
+ &Describe,
+ &PaintImageData,
+ &Scroll,
+ &ReplaceContents,
+ &Flush
+};
+
+} // namespace
+
+const PPB_Graphics2D* GetPPB_Graphics2D_Thunk() {
+ return &g_ppb_graphics_2d_thunk;
+}
+
+} // namespace thunk
+} // namespace ppapi
diff --git a/ppapi/thunk/ppb_image_data_api.h b/ppapi/thunk/ppb_image_data_api.h
new file mode 100644
index 0000000..a76a331
--- /dev/null
+++ b/ppapi/thunk/ppb_image_data_api.h
@@ -0,0 +1,21 @@
+// Copyright (c) 2011 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 "ppapi/c/pp_bool.h"
+#include "ppapi/c/ppb_image_data.h"
+#include "ppapi/c/pp_point.h"
+#include "ppapi/c/pp_resource.h"
+
+namespace ppapi {
+namespace thunk {
+
+class PPB_ImageData_API {
+ public:
+ virtual PP_Bool Describe(PP_ImageDataDesc* desc) = 0;
+ virtual void* Map() = 0;
+ virtual void Unmap() = 0;
+};
+
+} // namespace thunk
+} // namespace ppapi
diff --git a/ppapi/thunk/ppb_image_data_thunk.cc b/ppapi/thunk/ppb_image_data_thunk.cc
new file mode 100644
index 0000000..6f75d79
--- /dev/null
+++ b/ppapi/thunk/ppb_image_data_thunk.cc
@@ -0,0 +1,83 @@
+// Copyright (c) 2011 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 "ppapi/c/pp_errors.h"
+#include "ppapi/c/ppb_image_data.h"
+#include "ppapi/shared_impl/image_data_impl.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_image_data_api.h"
+#include "ppapi/thunk/resource_creation_api.h"
+
+namespace ppapi {
+namespace thunk {
+
+namespace {
+
+PP_ImageDataFormat GetNativeImageDataFormat() {
+ return pp::shared_impl::ImageDataImpl::GetNativeImageDataFormat();
+}
+
+PP_Bool IsImageDataFormatSupported(PP_ImageDataFormat format) {
+ return pp::shared_impl::ImageDataImpl::IsImageDataFormatSupported(format)
+ ? PP_TRUE : PP_FALSE;
+}
+
+PP_Resource Create(PP_Instance instance,
+ PP_ImageDataFormat format,
+ const PP_Size* size,
+ PP_Bool init_to_zero) {
+ EnterFunction<ResourceCreationAPI> enter(instance, true);
+ if (enter.failed())
+ return 0;
+ return enter.functions()->CreateImageData(instance, format,
+ *size, init_to_zero);
+}
+
+PP_Bool IsImageData(PP_Resource resource) {
+ EnterResource<PPB_ImageData_API> enter(resource, false);
+ return enter.succeeded() ? PP_TRUE : PP_FALSE;
+}
+
+PP_Bool Describe(PP_Resource resource, PP_ImageDataDesc* desc) {
+ // Give predictable values on failure.
+ memset(desc, 0, sizeof(PP_ImageDataDesc));
+
+ EnterResource<PPB_ImageData_API> enter(resource, true);
+ if (enter.failed())
+ return PP_FALSE;
+ return enter.object()->Describe(desc);
+}
+
+void* Map(PP_Resource resource) {
+ EnterResource<PPB_ImageData_API> enter(resource, true);
+ if (enter.failed())
+ return NULL;
+ return enter.object()->Map();
+}
+
+void Unmap(PP_Resource resource) {
+ EnterResource<PPB_ImageData_API> enter(resource, true);
+ if (enter.failed())
+ return;
+ enter.object()->Unmap();
+}
+
+const PPB_ImageData g_ppb_image_data_thunk = {
+ &GetNativeImageDataFormat,
+ &IsImageDataFormatSupported,
+ &Create,
+ &IsImageData,
+ &Describe,
+ &Map,
+ &Unmap,
+};
+
+} // namespace
+
+const PPB_ImageData* GetPPB_ImageData_Thunk() {
+ return &g_ppb_image_data_thunk;
+}
+
+} // namespace thunk
+} // namespace ppapi
diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h
new file mode 100644
index 0000000..bb81776
--- /dev/null
+++ b/ppapi/thunk/resource_creation_api.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2011 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.
+
+#ifndef PPAPI_THUNK_RESOURCE_CREATION_API_H_
+#define PPAPI_THUNK_RESOURCE_CREATION_API_H_
+
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/ppb_image_data.h"
+#include "ppapi/proxy/interface_id.h"
+
+struct PP_Size;
+
+namespace ppapi {
+namespace thunk {
+
+// A functional API for creating resource types. Separating out the creation
+// functions here allows us to implement most resources as a pure "resource
+// API", meaning all calls are routed on a per-resource-object basis. The
+// creationg functions are not per-object (since there's no object during
+// creation) so need functional routing based on the instance ID.
+class ResourceCreationAPI {
+ public:
+ static const ::pp::proxy::InterfaceID interface_id =
+ ::pp::proxy::INTERFACE_ID_RESOURCE_CREATION;
+
+ virtual PP_Resource CreateGraphics2D(PP_Instance instance,
+ const PP_Size& size,
+ PP_Bool is_always_opaque) = 0;
+ virtual PP_Resource CreateImageData(PP_Instance instance,
+ PP_ImageDataFormat format,
+ const PP_Size& size,
+ PP_Bool init_to_zero) = 0;
+};
+
+} // namespace thunk
+} // namespace ppapi
+
+#endif // PPAPI_THUNK_RESOURCE_CREATION_API_H_
diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h
new file mode 100644
index 0000000..39ae8f9
--- /dev/null
+++ b/ppapi/thunk/thunk.h
@@ -0,0 +1,24 @@
+// Copyright (c) 2011 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.
+
+#ifndef PPAPI_THUNK_THUNK_H_
+#define PPAPI_THUNK_THUNK_H_
+
+#include "base/synchronization/lock.h"
+
+struct PPB_Graphics2D;
+struct PPB_ImageData;
+
+namespace ppapi {
+namespace thunk {
+
+const PPB_Graphics2D* GetPPB_Graphics2D_Thunk();
+const PPB_ImageData* GetPPB_ImageData_Thunk();
+
+} // namespace thunk
+} // namespace ppapi
+
+#endif // PPAPI_THUNK_THUNK_H_
+
+