| Index: ppapi/proxy/graphics_2d_resource.cc
|
| diff --git a/ppapi/proxy/graphics_2d_resource.cc b/ppapi/proxy/graphics_2d_resource.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fca9316667ac42bb29b2e4e7650e903159eeecb4
|
| --- /dev/null
|
| +++ b/ppapi/proxy/graphics_2d_resource.cc
|
| @@ -0,0 +1,156 @@
|
| +// Copyright (c) 2012 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/proxy/graphics_2d_resource.h"
|
| +
|
| +#include "ppapi/c/ppb_graphics_2d.h"
|
| +#include "ppapi/c/pp_bool.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"
|
| +#include "ppapi/proxy/dispatch_reply_message.h"
|
| +#include "ppapi/proxy/ppapi_messages.h"
|
| +#include "ppapi/proxy/ppb_image_data_proxy.h"
|
| +#include "ppapi/shared_impl/ppapi_globals.h"
|
| +#include "ppapi/shared_impl/resource_tracker.h"
|
| +#include "ppapi/shared_impl/tracked_callback.h"
|
| +#include "ppapi/thunk/enter.h"
|
| +
|
| +namespace ppapi {
|
| +namespace proxy {
|
| +
|
| +// static
|
| +Graphics2DResource* Graphics2DResource::Create(Connection connection,
|
| + PP_Instance instance,
|
| + const PP_Size& size,
|
| + PP_Bool is_always_opaque) {
|
| + // These checks are copied from PPB_ImageData_Impl::Init to make tests passed.
|
| + // Let's remove/refactor this when start to refactor ImageData.
|
| + if (size.width <= 0 || size.height <= 0 ||
|
| + static_cast<int64>(size.width) * static_cast<int64>(size.height) * 4 >=
|
| + std::numeric_limits<int32>::max()) {
|
| + return NULL;
|
| + }
|
| +
|
| + return new Graphics2DResource(connection, instance, size, is_always_opaque);
|
| +}
|
| +
|
| +Graphics2DResource::Graphics2DResource(Connection connection,
|
| + PP_Instance instance,
|
| + const PP_Size& size,
|
| + PP_Bool is_always_opaque)
|
| + : PluginResource(connection, instance),
|
| + size_(size),
|
| + is_always_opaque_(is_always_opaque),
|
| + scale_(1.0f) {
|
| + if (!sent_create_to_renderer()) {
|
| + SendCreateToRenderer(
|
| + PpapiHostMsg_Graphics2D_Create(size, is_always_opaque));
|
| + }
|
| +}
|
| +
|
| +Graphics2DResource::~Graphics2DResource() {
|
| +}
|
| +
|
| +PP_Bool Graphics2DResource::Describe(PP_Size* size, PP_Bool* is_always_opaque) {
|
| + *size = size_;
|
| + *is_always_opaque = is_always_opaque_;
|
| + return PP_TRUE;
|
| +}
|
| +
|
| +thunk::PPB_Graphics2D_API* Graphics2DResource::AsPPB_Graphics2D_API() {
|
| + return this;
|
| +}
|
| +
|
| +void Graphics2DResource::PaintImageData(PP_Resource image_data,
|
| + const PP_Point* top_left,
|
| + const PP_Rect* src_rect) {
|
| + Resource* image_object =
|
| + PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data);
|
| + if (!image_object || pp_instance() != image_object->pp_instance()) {
|
| + Log(PP_LOGLEVEL_ERROR,
|
| + "Graphics2DResource.PaintImageData: Bad image resource.");
|
| + return;
|
| + }
|
| +
|
| + PP_Rect dummy;
|
| + memset(&dummy, 0, sizeof(PP_Rect));
|
| + PostToRenderer(PpapiHostMsg_Graphics2D_PaintImageData(
|
| + kApiID, image_object->host_resource(), *top_left,
|
| + !!src_rect, src_rect ? *src_rect : dummy));
|
| +}
|
| +
|
| +void Graphics2DResource::Scroll(const PP_Rect* clip_rect,
|
| + const PP_Point* amount) {
|
| + PP_Rect dummy;
|
| + memset(&dummy, 0, sizeof(PP_Rect));
|
| + PostToRenderer(PpapiHostMsg_Graphics2D_Scroll(
|
| + kApiID, !!clip_rect, clip_rect ? *clip_rect : dummy, *amount));
|
| +}
|
| +
|
| +void Graphics2DResource::ReplaceContents(PP_Resource image_data) {
|
| + thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter_image(
|
| + image_data, true);
|
| + if (enter_image.failed())
|
| + return;
|
| +
|
| + ImageData* image_object = static_cast<ImageData*>(enter_image.object());
|
| + if (pp_instance() != image_object->pp_instance()) {
|
| + Log(PP_LOGLEVEL_ERROR, "Graphics2DResource.ReplaceContents: "
|
| + "Image resource for another instance.");
|
| + return;
|
| + }
|
| + image_object->set_used_in_replace_contents();
|
| +
|
| + PostToRenderer(PpapiHostMsg_Graphics2D_ReplaceContents(
|
| + kApiID, image_object->host_resource()));
|
| +}
|
| +
|
| +bool Graphics2DResource::SetScale(float scale) {
|
| + if (scale <= 0.0f)
|
| + return false;
|
| + PostToRenderer(PpapiHostMsg_Graphics2D_Dev_SetScale(kApiID, scale));
|
| + scale_ = scale;
|
| + return true;
|
| +}
|
| +
|
| +float Graphics2DResource::GetScale() {
|
| + return scale_;
|
| +}
|
| +
|
| +int32_t Graphics2DResource::Flush(scoped_refptr<TrackedCallback> callback,
|
| + PP_Resource* old_image_data) {
|
| + // We don't support this feature, it's for in-renderer only.
|
| + if (old_image_data)
|
| + *old_image_data = 0;
|
| +
|
| + if (TrackedCallback::IsPending(current_flush_callback_))
|
| + return PP_ERROR_INPROGRESS; // Can't have >1 flush pending.
|
| + current_flush_callback_ = callback;
|
| +
|
| + CallRenderer<PpapiPluginMsg_Graphics2D_FlushAck>(
|
| + PpapiHostMsg_Graphics2D_Flush(kApiID),
|
| + base::Bind(&Graphics2DResource::OnPluginMsgFlushACK, this));
|
| + return PP_OK_COMPLETIONPENDING;
|
| +}
|
| +
|
| +bool Graphics2DResource::ReadImageData(PP_Resource image,
|
| + const PP_Point* top_left) {
|
| + if (!top_left)
|
| + return false;
|
| + PpapiPluginMsg_Graphics2D_ReadImageDataAck reply;
|
| + int32_t result = CallRendererSync(
|
| + PpapiHostMsg_Graphics2D_ReadImageData(kApiID, image, *top_left),
|
| + &reply);
|
| + return result == PP_OK;
|
| +}
|
| +
|
| +void Graphics2DResource::OnPluginMsgFlushACK(
|
| + const ResourceMessageReplyParams& params) {
|
| + TrackedCallback::ClearAndRun(¤t_flush_callback_, params.result());
|
| +}
|
| +
|
| +} // namespace proxy
|
| +} // namespace ppapi
|
|
|