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

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: rebase Created 8 years 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/proxy/ppapi_messages.h"
13 #include "ppapi/shared_impl/api_id.h"
14 #include "ppapi/thunk/enter.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 #if !defined(OS_NACL)
57 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
58 PpapiHostMsg_Graphics2D_PaintImageData,
59 OnHostMsgPaintImageData)
60 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
61 PpapiHostMsg_Graphics2D_Scroll,
62 OnHostMsgScroll)
63 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
64 PpapiHostMsg_Graphics2D_ReplaceContents,
65 OnHostMsgReplaceContents)
66 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
67 PpapiHostMsg_Graphics2D_Flush,
68 OnHostMsgFlush)
69 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
70 PpapiHostMsg_Graphics2D_Dev_SetScale,
71 OnHostMsgSetScale)
72 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
73 PpapiHostMsg_Graphics2D_ReadImageData,
74 OnHostMsgReadImageData)
75 #endif
76 IPC_END_MESSAGE_MAP()
77 return PP_ERROR_FAILED;
78 }
79
80 bool PepperGraphics2DHost::ReadImageData(PP_Resource image,
81 const PP_Point* top_left) {
82 return graphics_2d_->ReadImageData(image, top_left);
83 }
84
85 bool PepperGraphics2DHost::BindToInstance(
86 webkit::ppapi::PluginInstance* new_instance) {
87 if (new_instance &&
88 new_instance->pp_instance() != graphics_2d_->pp_instance())
89 return false; // Can't bind other instance's contexts.
90 return graphics_2d_->BindToInstance(new_instance);
91 }
92
93 void PepperGraphics2DHost::Paint(WebKit::WebCanvas* canvas,
94 const gfx::Rect& plugin_rect,
95 const gfx::Rect& paint_rect) {
96 graphics_2d_->Paint(canvas, plugin_rect, paint_rect);
97 }
98
99 void PepperGraphics2DHost::ViewWillInitiatePaint() {
100 graphics_2d_->ViewWillInitiatePaint();
101 }
102
103 void PepperGraphics2DHost::ViewInitiatedPaint() {
104 graphics_2d_->ViewInitiatedPaint();
105 }
106
107 void PepperGraphics2DHost::ViewFlushedPaint() {
108 graphics_2d_->ViewFlushedPaint();
109 }
110
111 void PepperGraphics2DHost::SetScale(float scale) {
112 graphics_2d_->scale_ = scale;
113 }
114
115 float PepperGraphics2DHost::GetScale() const {
116 return graphics_2d_->scale_;
117 }
118
119 bool PepperGraphics2DHost::IsAlwaysOpaque() const {
120 return graphics_2d_->is_always_opaque_;
121 }
122
123 webkit::ppapi::PPB_ImageData_Impl* PepperGraphics2DHost::ImageData() {
124 return graphics_2d_->image_data_.get();
125 }
126
127 bool PepperGraphics2DHost::IsGraphics2DHost() const {
128 return true;
129 }
130
131 #if !defined(OS_NACL)
132 int32_t PepperGraphics2DHost::OnHostMsgPaintImageData(
133 ppapi::host::HostMessageContext* context,
134 const ppapi::HostResource& image_data,
135 const PP_Point& top_left,
136 bool src_rect_specified,
137 const PP_Rect& src_rect) {
138 graphics_2d_->PaintImageData(image_data.host_resource(), &top_left,
139 src_rect_specified ? &src_rect : NULL);
140 return PP_OK;
141 }
142
143 int32_t PepperGraphics2DHost::OnHostMsgScroll(
144 ppapi::host::HostMessageContext* context,
145 bool clip_specified,
146 const PP_Rect& clip,
147 const PP_Point& amount) {
148 graphics_2d_->Scroll(clip_specified ? &clip : NULL, &amount);
149 return PP_OK;
150 }
151
152 int32_t PepperGraphics2DHost::OnHostMsgReplaceContents(
153 ppapi::host::HostMessageContext* context,
154 const ppapi::HostResource& image_data) {
155 graphics_2d_->ReplaceContents(image_data.host_resource());
156 return PP_OK;
157 }
158
159 int32_t PepperGraphics2DHost::OnHostMsgFlush(
160 ppapi::host::HostMessageContext* context) {
161 PP_Resource old_image_data = 0;
162 flush_reply_context_ = context->MakeReplyMessageContext();
163 // TODO: when merge PP_Graphics2D_Impl, we won't need this tracked callback.
164 scoped_refptr<ppapi::TrackedCallback> callback(new ppapi::TrackedCallback(
165 graphics_2d_.get(),
166 PP_MakeCompletionCallback(&PepperGraphics2DHost::SendFlushACKToPlugin,
167 AsWeakPtr())));
168 if (is_running_in_process_)
169 return graphics_2d_->Flush(callback, NULL);
170
171 // Reuse image data when running out of process.
172 int32_t result = graphics_2d_->Flush(callback, &old_image_data);
173
174 if (old_image_data) {
175 // If the Graphics2D has an old image data it's not using any more, send
176 // it back to the plugin for possible re-use. See ppb_image_data_proxy.cc
177 // for a description how this process works.
178 ppapi::HostResource old_image_data_host_resource;
179 old_image_data_host_resource.SetHostResource(pp_instance(),
180 old_image_data);
181 host()->Send(new PpapiMsg_PPBImageData_NotifyUnusedImageData(
182 ppapi::API_ID_PPB_IMAGE_DATA, old_image_data_host_resource));
183 }
184
185 return result;
186 }
187
188 int32_t PepperGraphics2DHost::OnHostMsgSetScale(
189 ppapi::host::HostMessageContext* context,
190 float scale) {
191 return graphics_2d_->SetScale(scale) ? PP_OK : PP_ERROR_BADARGUMENT;
192 }
193
194 int32_t PepperGraphics2DHost::OnHostMsgReadImageData(
195 ppapi::host::HostMessageContext* context,
196 PP_Resource image,
197 const PP_Point& top_left) {
198 context->reply_msg = PpapiPluginMsg_Graphics2D_ReadImageDataAck();
199 return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED;
200 }
201
202 // static
203 void PepperGraphics2DHost::SendFlushACKToPlugin(void* data,
204 int32_t pp_error) {
205 if (!data || pp_error != PP_OK)
206 return;
207 PepperGraphics2DHost* self = (PepperGraphics2DHost*) data;
208 self->host()->SendReply(self->flush_reply_context_,
209 PpapiPluginMsg_Graphics2D_FlushAck());
210 }
211 #endif // !defined(OS_NACL)
212
213 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_graphics_2d_host.h ('k') | content/renderer/pepper/pepper_in_process_resource_creation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698