diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-06 22:55:47 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-06 22:55:47 +0000 |
commit | 6239d34076222cbfe1d42770c604822b0ba894f4 (patch) | |
tree | d873cdf138b002bb2d2d4a554ba4fcd210251760 /ppapi/thunk/ppb_graphics_2d_thunk.cc | |
parent | c50a948dd9c07a71524949a28a5347e11d80da47 (diff) | |
download | chromium_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/ppb_graphics_2d_thunk.cc')
-rw-r--r-- | ppapi/thunk/ppb_graphics_2d_thunk.cc | 95 |
1 files changed, 95 insertions, 0 deletions
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 |