| Index: content/renderer/pepper/pepper_graphics_2d_host.cc
|
| diff --git a/content/renderer/pepper/pepper_graphics_2d_host.cc b/content/renderer/pepper/pepper_graphics_2d_host.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a152b59c73e91a60c9218980db63ac2f6c2b7d29
|
| --- /dev/null
|
| +++ b/content/renderer/pepper/pepper_graphics_2d_host.cc
|
| @@ -0,0 +1,167 @@
|
| +// 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 "content/renderer/pepper/pepper_graphics_2d_host.h"
|
| +
|
| +#include "content/public/renderer/renderer_ppapi_host.h"
|
| +#include "ppapi/host/dispatch_host_message.h"
|
| +#include "ppapi/host/host_message_context.h"
|
| +#include "ppapi/host/ppapi_host.h"
|
| +#include "ppapi/shared_impl/api_id.h"
|
| +#include "ppapi/proxy/ppapi_messages.h"
|
| +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
|
| +#include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" // TODO: merge to here
|
| +
|
| +namespace content {
|
| +
|
| +// static
|
| +PepperGraphics2DHost* PepperGraphics2DHost::Create(RendererPpapiHost* host,
|
| + PP_Instance instance,
|
| + PP_Resource resource,
|
| + const PP_Size& size,
|
| + PP_Bool is_always_opaque) {
|
| + PepperGraphics2DHost* resource_host =
|
| + new PepperGraphics2DHost(host, instance, resource);
|
| + if (!resource_host->graphics_2d_.Init(size.width, size.height,
|
| + is_always_opaque)) {
|
| + delete resource_host;
|
| + return NULL;
|
| + }
|
| + return resource_host;
|
| +}
|
| +
|
| +PepperGraphics2DHost::PepperGraphics2DHost(RendererPpapiHost* host,
|
| + PP_Instance instance,
|
| + PP_Resource resource)
|
| + : ResourceHost(host->GetPpapiHost(), instance, resource),
|
| + graphics_2d_(instance) {
|
| +}
|
| +
|
| +PepperGraphics2DHost::~PepperGraphics2DHost() {
|
| +}
|
| +
|
| +bool PepperGraphics2DHost::ReadImageData(PP_Resource image,
|
| + const PP_Point* top_left) {
|
| + return graphics_2d_.ReadImageData(image, top_left);
|
| +}
|
| +
|
| +int32_t PepperGraphics2DHost::OnHostMsgReadImageData(
|
| + ppapi::host::HostMessageContext* context,
|
| + PP_Resource image,
|
| + const PP_Point& top_left) {
|
| + bool success = ReadImageData(image, &top_left);
|
| + ppapi::host::ReplyMessageContext reply_context =
|
| + context->MakeReplyMessageContext();
|
| + reply_context.params.set_result(success ? PP_OK : PP_ERROR_FAILED);
|
| + host()->SendReply(reply_context,
|
| + PpapiMsg_Graphics2D_ReadImageDataAck());
|
| + return success ? PP_OK : PP_ERROR_FAILED;
|
| +}
|
| +
|
| +bool PepperGraphics2DHost::BindToInstance(
|
| + webkit::ppapi::PluginInstance* new_instance) {
|
| + if (new_instance && new_instance->pp_instance() != graphics_2d_.pp_instance())
|
| + return false; // Can't bind other instance's contexts.
|
| + return graphics_2d_.BindToInstance(new_instance);
|
| +}
|
| +
|
| +void PepperGraphics2DHost::Paint(WebKit::WebCanvas* canvas,
|
| + const gfx::Rect& plugin_rect,
|
| + const gfx::Rect& paint_rect) {
|
| + graphics_2d_.Paint(canvas, plugin_rect, paint_rect);
|
| +}
|
| +
|
| +void PepperGraphics2DHost::ViewWillInitiatePaint() {
|
| + graphics_2d_.ViewWillInitiatePaint();
|
| +}
|
| +
|
| +void PepperGraphics2DHost::ViewInitiatedPaint() {
|
| + graphics_2d_.ViewInitiatedPaint();
|
| +}
|
| +
|
| +void PepperGraphics2DHost::ViewFlushedPaint() {
|
| + graphics_2d_.ViewFlushedPaint();
|
| +}
|
| +
|
| +int32_t PepperGraphics2DHost::OnResourceMessageReceived(
|
| + const IPC::Message& msg,
|
| + ppapi::host::HostMessageContext* context) {
|
| + IPC_BEGIN_MESSAGE_MAP(PepperGraphics2DHost, msg)
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL(
|
| + PpapiHostMsg_Graphics2D_PaintImageData,
|
| + OnHostMsgPaintImageData)
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL(
|
| + PpapiHostMsg_Graphics2D_Scroll,
|
| + OnHostMsgScroll)
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL(
|
| + PpapiHostMsg_Graphics2D_ReplaceContents,
|
| + OnHostMsgReplaceContents)
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
|
| + PpapiHostMsg_Graphics2D_Flush,
|
| + OnHostMsgFlush)
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL(
|
| + PpapiHostMsg_Graphics2D_Dev_SetScale,
|
| + OnHostMsgSetScale)
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL(
|
| + PpapiHostMsg_Graphics2D_ReadImageData,
|
| + OnHostMsgReadImageData)
|
| + IPC_END_MESSAGE_MAP()
|
| + return PP_ERROR_FAILED;
|
| +}
|
| +
|
| +int32_t PepperGraphics2DHost::OnHostMsgPaintImageData(
|
| + ppapi::host::HostMessageContext* context,
|
| + const ppapi::HostResource& image_data,
|
| + const PP_Point& top_left,
|
| + bool src_rect_specified,
|
| + const PP_Rect& src_rect) {
|
| + graphics_2d_.PaintImageData(image_data.host_resource(), &top_left,
|
| + src_rect_specified ? &src_rect : NULL);
|
| + return PP_OK;
|
| +}
|
| +
|
| +int32_t PepperGraphics2DHost::OnHostMsgScroll(
|
| + ppapi::host::HostMessageContext* context,
|
| + bool clip_specified,
|
| + const PP_Rect& clip,
|
| + const PP_Point& amount) {
|
| + graphics_2d_.Scroll(clip_specified ? &clip : NULL, &amount);
|
| + return PP_OK;
|
| +}
|
| +
|
| +int32_t PepperGraphics2DHost::OnHostMsgReplaceContents(
|
| + ppapi::host::HostMessageContext* context,
|
| + const ppapi::HostResource& image_data) {
|
| + graphics_2d_.ReplaceContents(image_data.host_resource());
|
| + return PP_OK;
|
| +}
|
| +
|
| +int32_t PepperGraphics2DHost::OnHostMsgFlush(
|
| + ppapi::host::HostMessageContext* context) {
|
| + PP_Resource old_image_data = 0;
|
| + reply_context_ = context->MakeReplyMessageContext();
|
| + scoped_refptr<ppapi::TrackedCallback> callback(new ppapi::TrackedCallback(
|
| + &graphics_2d_,
|
| + PP_MakeCompletionCallback(&PepperGraphics2DHost::SendFlushACKToPlugin,
|
| + AsWeakPtr())));
|
| + return graphics_2d_.Flush(callback, &old_image_data);
|
| +}
|
| +
|
| +int32_t PepperGraphics2DHost::OnHostMsgSetScale(
|
| + ppapi::host::HostMessageContext* context,
|
| + float scale) {
|
| + return graphics_2d_.SetScale(scale) ? PP_OK : PP_ERROR_BADARGUMENT;
|
| +}
|
| +
|
| +// static
|
| +void PepperGraphics2DHost::SendFlushACKToPlugin(void* weak_self,
|
| + int32_t pp_error) {
|
| + PepperGraphics2DHost* self = (PepperGraphics2DHost*) weak_self;
|
| + if (!self) // as weak ptr itself, this will make sure it's still live.
|
| + return;
|
| + self->host()->SendReply(self->reply_context_,
|
| + PpapiMsg_Graphics2D_FlushACK(pp_error));
|
| +}
|
| +
|
| +} // namespace content
|
|
|