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

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, 1 month 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/c/pp_bool.h"
9 #include "ppapi/host/dispatch_host_message.h"
10 #include "ppapi/host/host_message_context.h"
11 #include "ppapi/host/ppapi_host.h"
12 #include "ppapi/shared_impl/api_id.h"
13 #include "ppapi/thunk/enter.h"
14 #include "ppapi/proxy/ppapi_messages.h"
15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
16 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" // TODO: merge to here
17
18 namespace content {
19
20 // static
21 PepperGraphics2DHost* PepperGraphics2DHost::Create(RendererPpapiHost* host,
22 PP_Instance instance,
23 PP_Resource resource,
24 const PP_Size& size,
25 PP_Bool is_always_opaque) {
26 PepperGraphics2DHost* resource_host =
27 new PepperGraphics2DHost(host, instance, resource);
28 if (!resource_host->graphics_2d_->Init(size.width, size.height,
29 PP_ToBool(is_always_opaque))) {
30 delete resource_host;
31 return NULL;
32 }
33 return resource_host;
34 }
35
36 PepperGraphics2DHost::PepperGraphics2DHost(RendererPpapiHost* host,
37 PP_Instance instance,
38 PP_Resource resource)
39 : ResourceHost(host->GetPpapiHost(), instance, resource),
40 graphics_2d_(new webkit::ppapi::PPB_Graphics2D_Impl(instance)),
41 is_running_in_process_(host->IsRunningInProcess()) {
42 }
43
44 PepperGraphics2DHost::~PepperGraphics2DHost() {
45 // Unbind from the instance when destoryed.
46 PP_Instance instance = graphics_2d_->pp_instance();
47 ppapi::thunk::EnterInstanceNoLock enter(instance);
48 if (enter.succeeded())
49 enter.functions()->BindGraphics(instance, 0);
50 }
51
52 int32_t PepperGraphics2DHost::OnResourceMessageReceived(
53 const IPC::Message& msg,
54 ppapi::host::HostMessageContext* context) {
55 IPC_BEGIN_MESSAGE_MAP(PepperGraphics2DHost, msg)
56 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
57 PpapiHostMsg_Graphics2D_PaintImageData,
58 OnHostMsgPaintImageData)
59 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
60 PpapiHostMsg_Graphics2D_Scroll,
61 OnHostMsgScroll)
62 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
63 PpapiHostMsg_Graphics2D_ReplaceContents,
64 OnHostMsgReplaceContents)
65 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
66 PpapiHostMsg_Graphics2D_Flush,
67 OnHostMsgFlush)
68 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
69 PpapiHostMsg_Graphics2D_Dev_SetScale,
70 OnHostMsgSetScale)
71 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
72 PpapiHostMsg_Graphics2D_ReadImageData,
73 OnHostMsgReadImageData)
74 IPC_END_MESSAGE_MAP()
75 return PP_ERROR_FAILED;
76 }
77
78 bool PepperGraphics2DHost::ReadImageData(PP_Resource image,
79 const PP_Point* top_left) {
80 return graphics_2d_->ReadImageData(image, top_left);
81 }
82
83 bool PepperGraphics2DHost::BindToInstance(
84 webkit::ppapi::PluginInstance* new_instance) {
85 if (new_instance &&
86 new_instance->pp_instance() != graphics_2d_->pp_instance())
87 return false; // Can't bind other instance's contexts.
88 return graphics_2d_->BindToInstance(new_instance);
89 }
90
91 void PepperGraphics2DHost::Paint(WebKit::WebCanvas* canvas,
92 const gfx::Rect& plugin_rect,
93 const gfx::Rect& paint_rect) {
94 graphics_2d_->Paint(canvas, plugin_rect, paint_rect);
95 }
96
97 void PepperGraphics2DHost::ViewWillInitiatePaint() {
98 graphics_2d_->ViewWillInitiatePaint();
99 }
100
101 void PepperGraphics2DHost::ViewInitiatedPaint() {
102 graphics_2d_->ViewInitiatedPaint();
103 }
104
105 void PepperGraphics2DHost::ViewFlushedPaint() {
106 graphics_2d_->ViewFlushedPaint();
107 }
108
109 void PepperGraphics2DHost::SetScale(float scale) {
110 graphics_2d_->scale_ = scale;
111 }
112
113 float PepperGraphics2DHost::GetScale() const {
114 return graphics_2d_->scale_;
115 }
116
117 bool PepperGraphics2DHost::IsAlwaysOpaque() const {
118 return graphics_2d_->is_always_opaque_;
119 }
120
121 webkit::ppapi::PPB_ImageData_Impl* PepperGraphics2DHost::ImageData() {
122 return graphics_2d_->image_data_.get();
123 }
124
125 bool PepperGraphics2DHost::IsGraphics2DHost() const {
126 return true;
127 }
128
129 int32_t PepperGraphics2DHost::OnHostMsgPaintImageData(
130 ppapi::host::HostMessageContext* context,
131 const ppapi::HostResource& image_data,
132 const PP_Point& top_left,
133 bool src_rect_specified,
134 const PP_Rect& src_rect) {
135 graphics_2d_->PaintImageData(image_data.host_resource(), &top_left,
136 src_rect_specified ? &src_rect : NULL);
137 return PP_OK;
138 }
139
140 int32_t PepperGraphics2DHost::OnHostMsgScroll(
141 ppapi::host::HostMessageContext* context,
142 bool clip_specified,
143 const PP_Rect& clip,
144 const PP_Point& amount) {
145 graphics_2d_->Scroll(clip_specified ? &clip : NULL, &amount);
146 return PP_OK;
147 }
148
149 int32_t PepperGraphics2DHost::OnHostMsgReplaceContents(
150 ppapi::host::HostMessageContext* context,
151 const ppapi::HostResource& image_data) {
152 graphics_2d_->ReplaceContents(image_data.host_resource());
153 return PP_OK;
154 }
155
156 int32_t PepperGraphics2DHost::OnHostMsgFlush(
157 ppapi::host::HostMessageContext* context) {
158 PP_Resource old_image_data = 0;
159 flush_reply_context_ = context->MakeReplyMessageContext();
160 // TODO: when merge PP_Graphics2D_Impl, we won't need this tracked callback.
161 scoped_refptr<ppapi::TrackedCallback> callback(new ppapi::TrackedCallback(
162 graphics_2d_.get(),
163 PP_MakeCompletionCallback(&PepperGraphics2DHost::SendFlushACKToPlugin,
164 AsWeakPtr())));
165 if (is_running_in_process_)
166 return graphics_2d_->Flush(callback, NULL);
167
168 // Reuse image data when running out of process.
169 int32_t result = graphics_2d_->Flush(callback, &old_image_data);
170
171 if (old_image_data) {
172 // If the Graphics2D has an old image data it's not using any more, send
173 // it back to the plugin for possible re-use. See ppb_image_data_proxy.cc
174 // for a description how this process works.
175 ppapi::HostResource old_image_data_host_resource;
176 old_image_data_host_resource.SetHostResource(pp_instance(),
177 old_image_data);
178 host()->Send(new PpapiMsg_PPBImageData_NotifyUnusedImageData(
179 ppapi::API_ID_PPB_IMAGE_DATA, old_image_data_host_resource));
180 }
181
182 return result;
183 }
184
185 int32_t PepperGraphics2DHost::OnHostMsgSetScale(
186 ppapi::host::HostMessageContext* context,
187 float scale) {
188 return graphics_2d_->SetScale(scale) ? PP_OK : PP_ERROR_BADARGUMENT;
189 }
190
191 int32_t PepperGraphics2DHost::OnHostMsgReadImageData(
192 ppapi::host::HostMessageContext* context,
193 PP_Resource image,
194 const PP_Point& top_left) {
195 context->reply_msg = PpapiPluginMsg_Graphics2D_ReadImageDataAck();
196 return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED;
197 }
198
199 // static
200 void PepperGraphics2DHost::SendFlushACKToPlugin(void* data,
201 int32_t pp_error) {
202 if (!data || pp_error != PP_OK)
203 return;
204 PepperGraphics2DHost* self = (PepperGraphics2DHost*) data;
205 self->host()->SendReply(self->flush_reply_context_,
206 PpapiPluginMsg_Graphics2D_FlushAck());
207 }
208
209 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698