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

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_(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(
50 ppapi::host::HostMessageContext* context,
51 PP_Resource image,
52 const PP_Point& top_left) {
53 bool success = ReadImageData(image, &top_left);
54 ppapi::host::ReplyMessageContext reply_context =
55 context->MakeReplyMessageContext();
56 reply_context.params.set_result(success ? PP_OK : PP_ERROR_FAILED);
57 host()->SendReply(reply_context,
58 PpapiMsg_Graphics2D_ReadImageDataAck());
59 return success ? PP_OK : PP_ERROR_FAILED;
60 }
61
62 bool PepperGraphics2DHost::BindToInstance(
63 webkit::ppapi::PluginInstance* new_instance) {
64 if (new_instance && new_instance->pp_instance() != graphics_2d_.pp_instance())
65 return false; // Can't bind other instance's contexts.
66 return graphics_2d_.BindToInstance(new_instance);
67 }
68
69 void PepperGraphics2DHost::Paint(WebKit::WebCanvas* canvas,
70 const gfx::Rect& plugin_rect,
71 const gfx::Rect& paint_rect) {
72 graphics_2d_.Paint(canvas, plugin_rect, paint_rect);
73 }
74
75 void PepperGraphics2DHost::ViewWillInitiatePaint() {
76 graphics_2d_.ViewWillInitiatePaint();
77 }
78
79 void PepperGraphics2DHost::ViewInitiatedPaint() {
80 graphics_2d_.ViewInitiatedPaint();
81 }
82
83 void PepperGraphics2DHost::ViewFlushedPaint() {
84 graphics_2d_.ViewFlushedPaint();
85 }
86
87 int32_t PepperGraphics2DHost::OnResourceMessageReceived(
88 const IPC::Message& msg,
89 ppapi::host::HostMessageContext* context) {
90 IPC_BEGIN_MESSAGE_MAP(PepperGraphics2DHost, msg)
91 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
92 PpapiHostMsg_Graphics2D_PaintImageData,
93 OnHostMsgPaintImageData)
94 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
95 PpapiHostMsg_Graphics2D_Scroll,
96 OnHostMsgScroll)
97 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
98 PpapiHostMsg_Graphics2D_ReplaceContents,
99 OnHostMsgReplaceContents)
100 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
101 PpapiHostMsg_Graphics2D_Flush,
102 OnHostMsgFlush)
103 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
104 PpapiHostMsg_Graphics2D_Dev_SetScale,
105 OnHostMsgSetScale)
106 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
107 PpapiHostMsg_Graphics2D_ReadImageData,
108 OnHostMsgReadImageData)
109 IPC_END_MESSAGE_MAP()
110 return PP_ERROR_FAILED;
111 }
112
113 int32_t PepperGraphics2DHost::OnHostMsgPaintImageData(
114 ppapi::host::HostMessageContext* context,
115 const ppapi::HostResource& image_data,
116 const PP_Point& top_left,
117 bool src_rect_specified,
118 const PP_Rect& src_rect) {
119 graphics_2d_.PaintImageData(image_data.host_resource(), &top_left,
120 src_rect_specified ? &src_rect : NULL);
121 return PP_OK;
122 }
123
124 int32_t PepperGraphics2DHost::OnHostMsgScroll(
125 ppapi::host::HostMessageContext* context,
126 bool clip_specified,
127 const PP_Rect& clip,
128 const PP_Point& amount) {
129 graphics_2d_.Scroll(clip_specified ? &clip : NULL, &amount);
130 return PP_OK;
131 }
132
133 int32_t PepperGraphics2DHost::OnHostMsgReplaceContents(
134 ppapi::host::HostMessageContext* context,
135 const ppapi::HostResource& image_data) {
136 graphics_2d_.ReplaceContents(image_data.host_resource());
137 return PP_OK;
138 }
139
140 int32_t PepperGraphics2DHost::OnHostMsgFlush(
141 ppapi::host::HostMessageContext* context) {
142 PP_Resource old_image_data = 0;
143 reply_context_ = context->MakeReplyMessageContext();
144 scoped_refptr<ppapi::TrackedCallback> callback(new ppapi::TrackedCallback(
145 &graphics_2d_,
146 PP_MakeCompletionCallback(&PepperGraphics2DHost::SendFlushACKToPlugin,
147 AsWeakPtr())));
148 return graphics_2d_.Flush(callback, &old_image_data);
149 }
150
151 int32_t PepperGraphics2DHost::OnHostMsgSetScale(
152 ppapi::host::HostMessageContext* context,
153 float scale) {
154 return graphics_2d_.SetScale(scale) ? PP_OK : PP_ERROR_BADARGUMENT;
155 }
156
157 // static
158 void PepperGraphics2DHost::SendFlushACKToPlugin(void* weak_self,
159 int32_t pp_error) {
160 PepperGraphics2DHost* self = (PepperGraphics2DHost*) weak_self;
161 if (!self) // as weak ptr itself, this will make sure it's still live.
162 return;
163 self->host()->SendReply(self->reply_context_,
164 PpapiMsg_Graphics2D_FlushACK(pp_error));
165 }
166
167 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698