Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: content/renderer/pepper/pepper_graphics_2d_host.cc

Issue 11053003: Migrate Graphics2D to new design. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 int32_t PepperGraphics2DHost::OnResourceMessageReceived(
45 const IPC::Message& msg,
46 ppapi::host::HostMessageContext* context) {
47 IPC_BEGIN_MESSAGE_MAP(PepperGraphics2DHost, msg)
48 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
49 PpapiHostMsg_Graphics2D_PaintImageData,
50 OnHostMsgPaintImageData)
51 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
52 PpapiHostMsg_Graphics2D_Scroll,
53 OnHostMsgScroll)
54 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
55 PpapiHostMsg_Graphics2D_ReplaceContents,
56 OnHostMsgReplaceContents)
57 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
58 PpapiHostMsg_Graphics2D_Flush,
59 OnHostMsgFlush)
60 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
61 PpapiHostMsg_Graphics2D_Dev_SetScale,
62 OnHostMsgSetScale)
63 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
64 PpapiHostMsg_Graphics2D_ReadImageData,
65 OnHostMsgReadImageData)
66 IPC_END_MESSAGE_MAP()
67 return PP_ERROR_FAILED;
68 }
69
70 bool PepperGraphics2DHost::ReadImageData(PP_Resource image,
71 const PP_Point* top_left) {
72 return graphics_2d_->ReadImageData(image, top_left);
73 }
74
75 bool PepperGraphics2DHost::BindToInstance(
76 webkit::ppapi::PluginInstance* new_instance) {
77 if (new_instance &&
78 new_instance->pp_instance() != graphics_2d_->pp_instance())
79 return false; // Can't bind other instance's contexts.
80 return graphics_2d_->BindToInstance(new_instance);
81 }
82
83 void PepperGraphics2DHost::Paint(WebKit::WebCanvas* canvas,
84 const gfx::Rect& plugin_rect,
85 const gfx::Rect& paint_rect) {
86 graphics_2d_->Paint(canvas, plugin_rect, paint_rect);
87 }
88
89 void PepperGraphics2DHost::ViewWillInitiatePaint() {
90 graphics_2d_->ViewWillInitiatePaint();
91 }
92
93 void PepperGraphics2DHost::ViewInitiatedPaint() {
94 graphics_2d_->ViewInitiatedPaint();
95 }
96
97 void PepperGraphics2DHost::ViewFlushedPaint() {
98 graphics_2d_->ViewFlushedPaint();
99 }
100
101 int32_t PepperGraphics2DHost::OnHostMsgPaintImageData(
102 ppapi::host::HostMessageContext* context,
103 const ppapi::HostResource& image_data,
104 const PP_Point& top_left,
105 bool src_rect_specified,
106 const PP_Rect& src_rect) {
107 graphics_2d_->PaintImageData(image_data.host_resource(), &top_left,
108 src_rect_specified ? &src_rect : NULL);
109 return PP_OK;
110 }
111
112 int32_t PepperGraphics2DHost::OnHostMsgScroll(
113 ppapi::host::HostMessageContext* context,
114 bool clip_specified,
115 const PP_Rect& clip,
116 const PP_Point& amount) {
117 graphics_2d_->Scroll(clip_specified ? &clip : NULL, &amount);
118 return PP_OK;
119 }
120
121 int32_t PepperGraphics2DHost::OnHostMsgReplaceContents(
122 ppapi::host::HostMessageContext* context,
123 const ppapi::HostResource& image_data) {
124 graphics_2d_->ReplaceContents(image_data.host_resource());
125 return PP_OK;
126 }
127
128 int32_t PepperGraphics2DHost::OnHostMsgFlush(
129 ppapi::host::HostMessageContext* context) {
130 PP_Resource old_image_data = 0;
131 flush_reply_context_ = context->MakeReplyMessageContext();
132 // TODO: when merge PP_Graphics2D_Impl, we won't need this tracked callback.
133 scoped_refptr<ppapi::TrackedCallback> callback(new ppapi::TrackedCallback(
134 graphics_2d_.get(),
135 PP_MakeCompletionCallback(&PepperGraphics2DHost::SendFlushACKToPlugin,
136 AsWeakPtr())));
137 int32_t result = graphics_2d_->Flush(callback, &old_image_data);
138
139 if (old_image_data) {
140 // If the Graphics2D has an old image data it's not using any more, send
141 // it back to the plugin for possible re-use. See ppb_image_data_proxy.cc
142 // for a description how this process works.
143 ppapi::HostResource old_image_data_host_resource;
144 old_image_data_host_resource.SetHostResource(pp_instance(),
145 old_image_data);
146 host()->Send(new PpapiMsg_PPBImageData_NotifyUnusedImageData(
147 ppapi::API_ID_PPB_IMAGE_DATA, old_image_data_host_resource));
148 }
149
150 return result;
151 }
152
153 int32_t PepperGraphics2DHost::OnHostMsgSetScale(
154 ppapi::host::HostMessageContext* context,
155 float scale) {
156 return graphics_2d_->SetScale(scale) ? PP_OK : PP_ERROR_BADARGUMENT;
157 }
158
159 int32_t PepperGraphics2DHost::OnHostMsgReadImageData(
160 ppapi::host::HostMessageContext* context,
161 PP_Resource image,
162 const PP_Point& top_left) {
163 context->reply_msg = PpapiPluginMsg_Graphics2D_ReadImageDataAck();
164 return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED;
165 }
166
167 // static
168 void PepperGraphics2DHost::SendFlushACKToPlugin(void* data,
169 int32_t pp_error) {
170 if (!data || pp_error != PP_OK)
171 return;
172 PepperGraphics2DHost* self = (PepperGraphics2DHost*) data;
173 self->host()->SendReply(self->flush_reply_context_,
174 PpapiPluginMsg_Graphics2D_FlushAck());
175 }
176
177 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698