Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/pepper/pepper_graphics_2d_host.h" | |
| 6 | |
| 7 #include "content/public/renderer/renderer_ppapi_host.h" | |
| 8 #include "ppapi/host/dispatch_host_message.h" | |
| 9 #include "ppapi/host/host_message_context.h" | |
| 10 #include "ppapi/host/ppapi_host.h" | |
| 11 #include "ppapi/shared_impl/api_id.h" | |
| 12 #include "ppapi/proxy/ppapi_messages.h" | |
| 13 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | |
| 14 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" // TODO: merge to here | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 // static | |
| 19 PepperGraphics2DHost* PepperGraphics2DHost::Create(RendererPpapiHost* host, | |
| 20 PP_Instance instance, | |
| 21 PP_Resource resource, | |
| 22 const PP_Size& size, | |
| 23 PP_Bool is_always_opaque) { | |
| 24 PepperGraphics2DHost* resource_host = | |
| 25 new PepperGraphics2DHost(host, instance, resource); | |
| 26 if (!resource_host->graphics_2d_->Init(size.width, size.height, | |
| 27 is_always_opaque)) { | |
| 28 delete resource_host; | |
| 29 return NULL; | |
| 30 } | |
| 31 return resource_host; | |
| 32 } | |
| 33 | |
| 34 PepperGraphics2DHost::PepperGraphics2DHost(RendererPpapiHost* host, | |
| 35 PP_Instance instance, | |
| 36 PP_Resource resource) | |
| 37 : ResourceHost(host->GetPpapiHost(), instance, resource), | |
| 38 graphics_2d_(new webkit::ppapi::PPB_Graphics2D_Impl(instance)) { | |
| 39 } | |
| 40 | |
| 41 PepperGraphics2DHost::~PepperGraphics2DHost() { | |
| 42 } | |
| 43 | |
| 44 bool PepperGraphics2DHost::ReadImageData(PP_Resource image, | |
| 45 const PP_Point* top_left) { | |
| 46 return graphics_2d_->ReadImageData(image, top_left); | |
| 47 } | |
| 48 | |
| 49 int32_t PepperGraphics2DHost::OnHostMsgReadImageData( | |
|
brettw
2012/10/05 22:38:06
Can you make the order of the functions in the .cc
victorhsieh
2012/10/05 23:26:57
Done, except that constructor is still after Creat
| |
| 50 ppapi::host::HostMessageContext* context, | |
| 51 PP_Resource image, | |
| 52 const PP_Point& top_left) { | |
| 53 context->reply_msg = PpapiMsg_Graphics2D_ReadImageDataAck(); | |
| 54 return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED; | |
| 55 } | |
| 56 | |
| 57 bool PepperGraphics2DHost::BindToInstance( | |
| 58 webkit::ppapi::PluginInstance* new_instance) { | |
| 59 if (new_instance && | |
| 60 new_instance->pp_instance() != graphics_2d_->pp_instance()) | |
| 61 return false; // Can't bind other instance's contexts. | |
| 62 return graphics_2d_->BindToInstance(new_instance); | |
| 63 } | |
| 64 | |
| 65 void PepperGraphics2DHost::Paint(WebKit::WebCanvas* canvas, | |
| 66 const gfx::Rect& plugin_rect, | |
| 67 const gfx::Rect& paint_rect) { | |
| 68 graphics_2d_->Paint(canvas, plugin_rect, paint_rect); | |
| 69 } | |
| 70 | |
| 71 void PepperGraphics2DHost::ViewWillInitiatePaint() { | |
| 72 graphics_2d_->ViewWillInitiatePaint(); | |
| 73 } | |
| 74 | |
| 75 void PepperGraphics2DHost::ViewInitiatedPaint() { | |
| 76 graphics_2d_->ViewInitiatedPaint(); | |
| 77 } | |
| 78 | |
| 79 void PepperGraphics2DHost::ViewFlushedPaint() { | |
| 80 graphics_2d_->ViewFlushedPaint(); | |
| 81 } | |
| 82 | |
| 83 int32_t PepperGraphics2DHost::OnResourceMessageReceived( | |
| 84 const IPC::Message& msg, | |
| 85 ppapi::host::HostMessageContext* context) { | |
| 86 IPC_BEGIN_MESSAGE_MAP(PepperGraphics2DHost, msg) | |
| 87 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | |
| 88 PpapiHostMsg_Graphics2D_PaintImageData, | |
| 89 OnHostMsgPaintImageData) | |
| 90 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | |
| 91 PpapiHostMsg_Graphics2D_Scroll, | |
| 92 OnHostMsgScroll) | |
| 93 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | |
| 94 PpapiHostMsg_Graphics2D_ReplaceContents, | |
| 95 OnHostMsgReplaceContents) | |
| 96 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( | |
| 97 PpapiHostMsg_Graphics2D_Flush, | |
| 98 OnHostMsgFlush) | |
| 99 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | |
| 100 PpapiHostMsg_Graphics2D_Dev_SetScale, | |
| 101 OnHostMsgSetScale) | |
| 102 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | |
| 103 PpapiHostMsg_Graphics2D_ReadImageData, | |
| 104 OnHostMsgReadImageData) | |
| 105 IPC_END_MESSAGE_MAP() | |
| 106 return PP_ERROR_FAILED; | |
| 107 } | |
| 108 | |
| 109 int32_t PepperGraphics2DHost::OnHostMsgPaintImageData( | |
| 110 ppapi::host::HostMessageContext* context, | |
| 111 const ppapi::HostResource& image_data, | |
| 112 const PP_Point& top_left, | |
| 113 bool src_rect_specified, | |
| 114 const PP_Rect& src_rect) { | |
| 115 graphics_2d_->PaintImageData(image_data.host_resource(), &top_left, | |
| 116 src_rect_specified ? &src_rect : NULL); | |
| 117 return PP_OK; | |
| 118 } | |
| 119 | |
| 120 int32_t PepperGraphics2DHost::OnHostMsgScroll( | |
| 121 ppapi::host::HostMessageContext* context, | |
| 122 bool clip_specified, | |
| 123 const PP_Rect& clip, | |
| 124 const PP_Point& amount) { | |
| 125 graphics_2d_->Scroll(clip_specified ? &clip : NULL, &amount); | |
| 126 return PP_OK; | |
| 127 } | |
| 128 | |
| 129 int32_t PepperGraphics2DHost::OnHostMsgReplaceContents( | |
| 130 ppapi::host::HostMessageContext* context, | |
| 131 const ppapi::HostResource& image_data) { | |
| 132 graphics_2d_->ReplaceContents(image_data.host_resource()); | |
| 133 return PP_OK; | |
| 134 } | |
| 135 | |
| 136 int32_t PepperGraphics2DHost::OnHostMsgFlush( | |
| 137 ppapi::host::HostMessageContext* context) { | |
| 138 PP_Resource old_image_data = 0; | |
| 139 reply_context_ = context->MakeReplyMessageContext(); | |
| 140 scoped_refptr<ppapi::TrackedCallback> callback(new ppapi::TrackedCallback( | |
|
brettw
2012/10/05 22:38:06
Were you planning on merging the graphics_2d_impl
victorhsieh
2012/10/05 23:26:57
Done, leaving a TODO.
| |
| 141 graphics_2d_.get(), | |
| 142 PP_MakeCompletionCallback(&PepperGraphics2DHost::SendFlushACKToPlugin, | |
| 143 AsWeakPtr()))); | |
| 144 int32_t result = graphics_2d_->Flush(callback, &old_image_data); | |
| 145 | |
| 146 if (old_image_data) { | |
| 147 // If the Graphics2D has an old image data it's not using any more, send | |
| 148 // it back to the plugin for possible re-use. See ppb_image_data_proxy.cc | |
| 149 // for a description how this process works. | |
| 150 ppapi::HostResource old_image_data_host_resource; | |
| 151 old_image_data_host_resource.SetHostResource(pp_instance(), | |
| 152 old_image_data); | |
| 153 host()->Send(new PpapiMsg_PPBImageData_NotifyUnusedImageData( | |
| 154 ppapi::API_ID_PPB_IMAGE_DATA, old_image_data_host_resource)); | |
| 155 } | |
| 156 | |
| 157 return result; | |
| 158 } | |
| 159 | |
| 160 int32_t PepperGraphics2DHost::OnHostMsgSetScale( | |
| 161 ppapi::host::HostMessageContext* context, | |
| 162 float scale) { | |
| 163 return graphics_2d_->SetScale(scale) ? PP_OK : PP_ERROR_BADARGUMENT; | |
| 164 } | |
| 165 | |
| 166 // static | |
| 167 void PepperGraphics2DHost::SendFlushACKToPlugin(void* data, | |
| 168 int32_t pp_error) { | |
| 169 if (!data || pp_error != PP_OK) | |
| 170 return; | |
| 171 PepperGraphics2DHost* self = (PepperGraphics2DHost*) data; | |
| 172 self->host()->SendReply(self->reply_context_, | |
| 173 PpapiMsg_Graphics2D_FlushACK(pp_error)); | |
| 174 } | |
| 175 | |
| 176 } // namespace content | |
| OLD | NEW |