Skip to content

Commit

Permalink
Autogenerate thunk for PPB_ImageData.
Browse files Browse the repository at this point in the history
This changes idl_thunk.py to use functions from ppapi/shared_impl when the
first argument to a function is not PP_Instance or PP_Resource. This pattern
seems to be used in multiple IDL files.

I also needed to clean up the APIs a bit so the function signatures matched up
with what idl_thunk.py emits.

Tested:
  Built chrome and browser_tests.

BUG=

Review URL: https://chromiumcodereview.appspot.com/14060022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196571 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
teravest@chromium.org committed Apr 26, 2013
1 parent 210257b commit 56c49bb
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 59 deletions.
2 changes: 1 addition & 1 deletion chrome/renderer/pepper/pepper_pdf_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ bool PepperPDFHost::CreateImageData(
return false;

PP_Resource resource = enter.functions()->CreateImageData(instance, format,
size, PP_FALSE);
&size, PP_FALSE);
if (!resource)
return false;
result->SetHostResource(instance, resource);
Expand Down
9 changes: 6 additions & 3 deletions ppapi/api/ppb_image_data.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
* a browser handles image data.
*/

label Chrome {
M14 = 1.0
};
[generate_thunk]

label Chrome {
M14 = 1.0
};

/**
* <code>PP_ImageDataFormat</code> is an enumeration of the different types of
Expand Down Expand Up @@ -157,6 +159,7 @@ interface PPB_ImageData {
* <code>PP_FALSE</code>, the <code>desc</code> structure will be filled
* with 0.
*/
[always_set_output_parameters]
PP_Bool Describe(
[in] PP_Resource image_data,
[out] PP_ImageDataDesc desc);
Expand Down
46 changes: 33 additions & 13 deletions ppapi/generators/idl_thunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,33 @@ def _GetThunkFileName(filenode, relpath):
return name


def _AddApiHeader(filenode, meta):
"""Adds an API header for the given file to the ThunkBodyMetadata."""
# The API header matches the file name, not the interface name.
def _StripFileName(filenode):
"""Strips path and dev, trusted, and private suffixes from the file name."""
api_basename = _GetBaseFileName(filenode)
if api_basename.endswith('_dev'):
api_basename = api_basename[:-len('_dev')]
if api_basename.endswith('_trusted'):
api_basename = api_basename[:-len('_trusted')]
if api_basename.endswith('_private'):
api_basename = api_basename[:-len('_private')]
meta.AddApi(api_basename + '_api')
return api_basename


def _MakeEnterLine(filenode, interface, member, arg, handle_errors, callback,
meta):
"""Returns an EnterInstance/EnterResource string for a function."""
api_name = interface.GetName()
def _StripApiName(api_name):
"""Strips Dev, Private, and Trusted suffixes from the API name."""
if api_name.endswith('Trusted'):
api_name = api_name[:-len('Trusted')]
if api_name.endswith('_Dev'):
api_name = api_name[:-len('_Dev')]
if api_name.endswith('_Private'):
api_name = api_name[:-len('_Private')]
api_name += '_API'
return api_name


def _MakeEnterLine(filenode, interface, member, arg, handle_errors, callback,
meta):
"""Returns an EnterInstance/EnterResource string for a function."""
api_name = _StripApiName(interface.GetName()) + '_API'
if member.GetProperty('api'): # Override API name.
manually_provided_api = True
# TODO(teravest): Automatically guess the API header file.
Expand All @@ -128,14 +131,14 @@ def _MakeEnterLine(filenode, interface, member, arg, handle_errors, callback,
arg_string = '%s, %s' % (arg[1], callback)
if interface.GetProperty('singleton') or member.GetProperty('singleton'):
if not manually_provided_api:
_AddApiHeader(filenode, meta)
meta.AddApi('ppapi/thunk/%s_api.h' % _StripFileName(filenode))
return 'EnterInstanceAPI<%s> enter(%s);' % (api_name, arg_string)
else:
return 'EnterInstance enter(%s);' % arg_string
elif arg[0] == 'PP_Resource':
enter_type = 'EnterResource<%s>' % api_name
if not manually_provided_api:
_AddApiHeader(filenode, meta)
meta.AddApi('ppapi/thunk/%s_api.h' % _StripFileName(filenode))
if callback is None:
return '%s enter(%s, %s);' % (enter_type, arg[1],
str(handle_errors).lower())
Expand Down Expand Up @@ -180,6 +183,7 @@ def _GetDefaultFailureValue(t):
'uint16_t': '0',
'uint32_t': '0',
'uint64_t': '0',
'void*': 'NULL'
}
if t in values:
return values[t]
Expand Down Expand Up @@ -256,6 +260,14 @@ def _MakeNormalMemberBody(filenode, release, node, member, rtype, args,
include_version - whether to include the version in the invocation
meta - ThunkBodyMetadata for header hints
"""
if len(args) == 0:
# Calling into the "Shared" code for the interface seems like a reasonable
# heuristic when we don't have any arguments; some thunk code follows this
# convention today.
meta.AddApi('ppapi/shared_impl/%s_shared.h' % _StripFileName(filenode))
return 'return %s::%s();' % (_StripApiName(node.GetName()) + '_Shared',
member.GetName())

is_callback_func = args[len(args) - 1][0] == 'struct PP_CompletionCallback'

if is_callback_func:
Expand All @@ -267,9 +279,17 @@ def _MakeNormalMemberBody(filenode, release, node, member, rtype, args,
if args[0][0] == 'PP_Instance':
call_arglist = ', '.join(a[1] for a in call_args)
function_container = 'functions'
else:
elif args[0][0] == 'PP_Resource':
call_arglist = ', '.join(a[1] for a in call_args[1:])
function_container = 'object'
else:
# Calling into the "Shared" code for the interface seems like a reasonable
# heuristic when the first argument isn't a PP_Instance or a PP_Resource;
# some thunk code follows this convention today.
meta.AddApi('ppapi/shared_impl/%s_shared.h' % _StripFileName(filenode))
return 'return %s::%s(%s);' % (_StripApiName(node.GetName()) + '_Shared',
member.GetName(),
', '.join(a[1] for a in args))

function_name = member.GetName()
if include_version:
Expand Down Expand Up @@ -443,7 +463,7 @@ def WriteHead(self, out, filenode, releases, options, meta):
'ppapi/thunk/thunk.h']
includes.append(_GetHeaderFileName(filenode))
for api in meta.Apis():
includes.append('ppapi/thunk/%s.h' % api.lower())
includes.append('%s' % api.lower())
for i in meta.Includes():
includes.append(i)
for include in sorted(includes):
Expand Down
4 changes: 2 additions & 2 deletions ppapi/proxy/ppb_image_data_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance,
return;

PP_Resource resource = enter.functions()->CreateImageData(
instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero);
instance, static_cast<PP_ImageDataFormat>(format), &size, init_to_zero);
if (!resource)
return;
result->SetHostResource(instance, resource);
Expand Down Expand Up @@ -577,7 +577,7 @@ void PPB_ImageData_Proxy::OnHostMsgCreateNaCl(
return;

PP_Resource resource = enter.functions()->CreateImageDataNaCl(
instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero);
instance, static_cast<PP_ImageDataFormat>(format), &size, init_to_zero);
if (!resource)
return;
result->SetHostResource(instance, resource);
Expand Down
6 changes: 3 additions & 3 deletions ppapi/proxy/resource_creation_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,16 @@ PP_Resource ResourceCreationProxy::CreateHostResolverPrivate(

PP_Resource ResourceCreationProxy::CreateImageData(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
const PP_Size* size,
PP_Bool init_to_zero) {
return PPB_ImageData_Proxy::CreateProxyResource(instance, format, size,
return PPB_ImageData_Proxy::CreateProxyResource(instance, format, *size,
init_to_zero);
}

PP_Resource ResourceCreationProxy::CreateImageDataNaCl(
PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
const PP_Size* size,
PP_Bool init_to_zero) {
// These really only are different on the host side. On the plugin side, we
// always request a "platform" ImageData if we're trusted, or a "NaCl" one
Expand Down
4 changes: 2 additions & 2 deletions ppapi/proxy/resource_creation_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ class ResourceCreationProxy : public InterfaceProxy,
virtual PP_Resource CreateHostResolverPrivate(PP_Instance instance) OVERRIDE;
virtual PP_Resource CreateImageData(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
const PP_Size* size,
PP_Bool init_to_zero) OVERRIDE;
virtual PP_Resource CreateImageDataNaCl(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
const PP_Size* size,
PP_Bool init_to_zero) OVERRIDE;
virtual PP_Resource CreateNetworkMonitor(
PP_Instance instance,
Expand Down
6 changes: 3 additions & 3 deletions ppapi/shared_impl/ppb_image_data_shared.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ PP_ImageDataFormat PPB_ImageData_Shared::GetNativeImageDataFormat() {
}

// static
bool PPB_ImageData_Shared::IsImageDataFormatSupported(
PP_Bool PPB_ImageData_Shared::IsImageDataFormatSupported(
PP_ImageDataFormat format) {
return format == PP_IMAGEDATAFORMAT_BGRA_PREMUL ||
format == PP_IMAGEDATAFORMAT_RGBA_PREMUL;
return PP_FromBool(format == PP_IMAGEDATAFORMAT_BGRA_PREMUL ||
format == PP_IMAGEDATAFORMAT_RGBA_PREMUL);
}

} // namespace ppapi
2 changes: 1 addition & 1 deletion ppapi/shared_impl/ppb_image_data_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace ppapi {
class PPAPI_SHARED_EXPORT PPB_ImageData_Shared {
public:
static PP_ImageDataFormat GetNativeImageDataFormat();
static bool IsImageDataFormatSupported(PP_ImageDataFormat format);
static PP_Bool IsImageDataFormatSupported(PP_ImageDataFormat format);
};

} // namespace ppapi
Expand Down
59 changes: 36 additions & 23 deletions ppapi/thunk/ppb_image_data_thunk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// From ppb_image_data.idl modified Thu Apr 25 14:42:27 2013.

#include <string.h>

#include "ppapi/c/pp_errors.h"
#include "ppapi/c/ppb_image_data.h"
#include "ppapi/shared_impl/ppb_image_data_shared.h"
#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_image_data_api.h"
#include "ppapi/thunk/ppb_instance_api.h"
#include "ppapi/thunk/resource_creation_api.h"
#include "ppapi/thunk/thunk.h"

Expand All @@ -15,69 +21,76 @@ namespace thunk {

namespace {

PP_ImageDataFormat GetNativeImageDataFormat() {
return ppapi::PPB_ImageData_Shared::GetNativeImageDataFormat();
PP_ImageDataFormat GetNativeImageDataFormat(void) {
VLOG(4) << "PPB_ImageData::GetNativeImageDataFormat()";
return PPB_ImageData_Shared::GetNativeImageDataFormat();
}

PP_Bool IsImageDataFormatSupported(PP_ImageDataFormat format) {
return ppapi::PPB_ImageData_Shared::IsImageDataFormatSupported(format)
? PP_TRUE : PP_FALSE;
VLOG(4) << "PPB_ImageData::IsImageDataFormatSupported()";
return PPB_ImageData_Shared::IsImageDataFormatSupported(format);
}

PP_Resource Create(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size* size,
const struct PP_Size* size,
PP_Bool init_to_zero) {
VLOG(4) << "PPB_ImageData::Create()";
EnterResourceCreation enter(instance);
if (enter.failed())
return 0;
return enter.functions()->CreateImageData(instance, format,
*size, init_to_zero);
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 IsImageData(PP_Resource image_data) {
VLOG(4) << "PPB_ImageData::IsImageData()";
EnterResource<PPB_ImageData_API> enter(image_data, false);
return PP_FromBool(enter.succeeded());
}

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())
PP_Bool Describe(PP_Resource image_data, struct PP_ImageDataDesc* desc) {
VLOG(4) << "PPB_ImageData::Describe()";
EnterResource<PPB_ImageData_API> enter(image_data, true);
if (enter.failed()) {
memset(desc, 0, sizeof(*desc));
return PP_FALSE;
}
return enter.object()->Describe(desc);
}

void* Map(PP_Resource resource) {
EnterResource<PPB_ImageData_API> enter(resource, true);
void* Map(PP_Resource image_data) {
VLOG(4) << "PPB_ImageData::Map()";
EnterResource<PPB_ImageData_API> enter(image_data, true);
if (enter.failed())
return NULL;
return enter.object()->Map();
}

void Unmap(PP_Resource resource) {
EnterResource<PPB_ImageData_API> enter(resource, true);
void Unmap(PP_Resource image_data) {
VLOG(4) << "PPB_ImageData::Unmap()";
EnterResource<PPB_ImageData_API> enter(image_data, true);
if (enter.failed())
return;
enter.object()->Unmap();
}

const PPB_ImageData g_ppb_image_data_thunk = {
const PPB_ImageData_1_0 g_ppb_imagedata_thunk_1_0 = {
&GetNativeImageDataFormat,
&IsImageDataFormatSupported,
&Create,
&IsImageData,
&Describe,
&Map,
&Unmap,
&Unmap
};

} // namespace

const PPB_ImageData_1_0* GetPPB_ImageData_1_0_Thunk() {
return &g_ppb_image_data_thunk;
return &g_ppb_imagedata_thunk_1_0;
}

} // namespace thunk
Expand Down
4 changes: 2 additions & 2 deletions ppapi/thunk/resource_creation_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ class ResourceCreationAPI {
virtual PP_Resource CreateHostResolverPrivate(PP_Instance instance) = 0;
virtual PP_Resource CreateImageData(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
const PP_Size* size,
PP_Bool init_to_zero) = 0;
virtual PP_Resource CreateImageDataNaCl(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
const PP_Size* size,
PP_Bool init_to_zero) = 0;
virtual PP_Resource CreateNetworkMonitor(
PP_Instance instance,
Expand Down
8 changes: 4 additions & 4 deletions webkit/plugins/ppapi/resource_creation_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,17 @@ PP_Resource ResourceCreationImpl::CreateHostResolverPrivate(

PP_Resource ResourceCreationImpl::CreateImageData(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
const PP_Size* size,
PP_Bool init_to_zero) {
return PPB_ImageData_Impl::CreatePlatform(instance, format, size,
return PPB_ImageData_Impl::CreatePlatform(instance, format, *size,
init_to_zero);
}

PP_Resource ResourceCreationImpl::CreateImageDataNaCl(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
const PP_Size* size,
PP_Bool init_to_zero) {
return PPB_ImageData_Impl::CreateNaCl(instance, format, size, init_to_zero);
return PPB_ImageData_Impl::CreateNaCl(instance, format, *size, init_to_zero);
}

PP_Resource ResourceCreationImpl::CreateIMEInputEvent(
Expand Down
4 changes: 2 additions & 2 deletions webkit/plugins/ppapi/resource_creation_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class WEBKIT_PLUGINS_EXPORT ResourceCreationImpl
virtual PP_Resource CreateHostResolverPrivate(PP_Instance instance) OVERRIDE;
virtual PP_Resource CreateImageData(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
const PP_Size* size,
PP_Bool init_to_zero) OVERRIDE;
virtual PP_Resource CreateImageDataNaCl(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
const PP_Size* size,
PP_Bool init_to_zero) OVERRIDE;
virtual PP_Resource CreateIMEInputEvent(PP_Instance instance,
PP_InputEvent_Type type,
Expand Down

0 comments on commit 56c49bb

Please sign in to comment.