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

Side by Side Diff: ppapi/proxy/graphics_2d_resource.cc

Issue 11414171: Migrate Graphics2D to new design. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/graphics_2d_resource.h ('k') | ppapi/proxy/interface_list.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ppapi/proxy/graphics_2d_resource.h"
6
7 #include "ppapi/c/pp_bool.h"
8 #include "ppapi/c/pp_point.h"
9 #include "ppapi/c/pp_rect.h"
10 #include "ppapi/c/pp_resource.h"
11 #include "ppapi/c/pp_size.h"
12 #include "ppapi/c/ppb_graphics_2d.h"
13 #include "ppapi/proxy/dispatch_reply_message.h"
14 #include "ppapi/proxy/ppapi_messages.h"
15 #include "ppapi/shared_impl/ppapi_globals.h"
16 #include "ppapi/shared_impl/resource_tracker.h"
17 #include "ppapi/shared_impl/tracked_callback.h"
18 #include "ppapi/thunk/enter.h"
19 #include "ppapi/thunk/ppb_image_data_api.h"
20
21 namespace ppapi {
22 namespace proxy {
23
24 Graphics2DResource::Graphics2DResource(Connection connection,
25 PP_Instance instance,
26 const PP_Size& size,
27 PP_Bool is_always_opaque)
28 : PluginResource(connection, instance),
29 size_(size),
30 is_always_opaque_(is_always_opaque),
31 scale_(1.0f) {
32 // These checks are copied from PPB_ImageData_Impl::Init to make tests passed.
33 // Let's remove/refactor this when start to refactor ImageData.
34 bool bad_args = size.width <= 0 || size.height <= 0 ||
35 static_cast<int64>(size.width) * static_cast<int64>(size.height) >=
36 std::numeric_limits<int32>::max() / 4;
37 if (!bad_args && !sent_create_to_renderer()) {
38 SendCreate(RENDERER,
39 PpapiHostMsg_Graphics2D_Create(size, is_always_opaque));
40 }
41 }
42
43 Graphics2DResource::~Graphics2DResource() {
44 }
45
46 PP_Bool Graphics2DResource::Describe(PP_Size* size, PP_Bool* is_always_opaque) {
47 *size = size_;
48 *is_always_opaque = is_always_opaque_;
49 return PP_TRUE;
50 }
51
52 thunk::PPB_Graphics2D_API* Graphics2DResource::AsPPB_Graphics2D_API() {
53 return this;
54 }
55
56 void Graphics2DResource::PaintImageData(PP_Resource image_data,
57 const PP_Point* top_left,
58 const PP_Rect* src_rect) {
59 Resource* image_object =
60 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data);
61 if (!image_object || pp_instance() != image_object->pp_instance()) {
62 Log(PP_LOGLEVEL_ERROR,
63 "Graphics2DResource.PaintImageData: Bad image resource.");
64 return;
65 }
66
67 PP_Rect dummy;
68 memset(&dummy, 0, sizeof(PP_Rect));
69 Post(RENDERER, PpapiHostMsg_Graphics2D_PaintImageData(
70 image_object->host_resource(), *top_left,
71 !!src_rect, src_rect ? *src_rect : dummy));
72 }
73
74 void Graphics2DResource::Scroll(const PP_Rect* clip_rect,
75 const PP_Point* amount) {
76 PP_Rect dummy;
77 memset(&dummy, 0, sizeof(PP_Rect));
78 Post(RENDERER, PpapiHostMsg_Graphics2D_Scroll(
79 !!clip_rect, clip_rect ? *clip_rect : dummy, *amount));
80 }
81
82 void Graphics2DResource::ReplaceContents(PP_Resource image_data) {
83 thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter_image(
84 image_data, true);
85 if (enter_image.failed())
86 return;
87
88 // Check that the PP_Instance matches.
89 Resource* image_object =
90 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data);
91 if (!image_object || pp_instance() != image_object->pp_instance()) {
92 Log(PP_LOGLEVEL_ERROR,
93 "Graphics2DResource.PaintImageData: Bad image resource.");
94 return;
95 }
96 enter_image.object()->SetUsedInReplaceContents();
97
98 Post(RENDERER, PpapiHostMsg_Graphics2D_ReplaceContents(
99 image_object->host_resource()));
100 }
101
102 bool Graphics2DResource::SetScale(float scale) {
103 if (scale <= 0.0f)
104 return false;
105 Post(RENDERER, PpapiHostMsg_Graphics2D_Dev_SetScale(scale));
106 scale_ = scale;
107 return true;
108 }
109
110 float Graphics2DResource::GetScale() {
111 return scale_;
112 }
113
114 int32_t Graphics2DResource::Flush(scoped_refptr<TrackedCallback> callback,
115 PP_Resource* old_image_data) {
116 // If host is not even created, return failure immediately. This can happen
117 // when failed to initialize (in constructor).
118 if (!sent_create_to_renderer())
119 return PP_ERROR_FAILED;
120
121 // We don't support this feature, it's for in-renderer only.
122 if (old_image_data)
123 *old_image_data = 0;
124
125 if (TrackedCallback::IsPending(current_flush_callback_))
126 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending.
127 current_flush_callback_ = callback;
128
129 Call<PpapiPluginMsg_Graphics2D_FlushAck>(
130 RENDERER,
131 PpapiHostMsg_Graphics2D_Flush(),
132 base::Bind(&Graphics2DResource::OnPluginMsgFlushACK, this));
133 return PP_OK_COMPLETIONPENDING;
134 }
135
136 bool Graphics2DResource::ReadImageData(PP_Resource image,
137 const PP_Point* top_left) {
138 if (!top_left)
139 return false;
140 int32_t result = SyncCall<PpapiPluginMsg_Graphics2D_ReadImageDataAck>(
141 RENDERER,
142 PpapiHostMsg_Graphics2D_ReadImageData(image, *top_left));
143 return result == PP_OK;
144 }
145
146 void Graphics2DResource::OnPluginMsgFlushACK(
147 const ResourceMessageReplyParams& params) {
148 current_flush_callback_->Run(params.result());
149 }
150
151 } // namespace proxy
152 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/graphics_2d_resource.h ('k') | ppapi/proxy/interface_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698