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

Side by Side Diff: remoting/client/plugin/pepper_view.cc

Issue 10382184: [Chromoting] Initial plumbing for cursor shape. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Call SetCursor only for native format images Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/client/plugin/pepper_view.h" 5 #include "remoting/client/plugin/pepper_view.h"
6 6
7 #include <functional> 7 #include <functional>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
12 #include "ppapi/cpp/completion_callback.h" 12 #include "ppapi/cpp/completion_callback.h"
13 #include "ppapi/cpp/graphics_2d.h" 13 #include "ppapi/cpp/graphics_2d.h"
14 #include "ppapi/cpp/image_data.h" 14 #include "ppapi/cpp/image_data.h"
15 #include "ppapi/cpp/mouse_cursor.h"
15 #include "ppapi/cpp/point.h" 16 #include "ppapi/cpp/point.h"
16 #include "ppapi/cpp/rect.h" 17 #include "ppapi/cpp/rect.h"
17 #include "ppapi/cpp/size.h" 18 #include "ppapi/cpp/size.h"
18 #include "remoting/base/util.h" 19 #include "remoting/base/util.h"
19 #include "remoting/client/chromoting_stats.h" 20 #include "remoting/client/chromoting_stats.h"
20 #include "remoting/client/client_context.h" 21 #include "remoting/client/client_context.h"
21 #include "remoting/client/frame_producer.h" 22 #include "remoting/client/frame_producer.h"
22 #include "remoting/client/plugin/chromoting_instance.h" 23 #include "remoting/client/plugin/chromoting_instance.h"
23 #include "remoting/client/plugin/pepper_util.h" 24 #include "remoting/client/plugin/pepper_util.h"
24 25
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 ChromotingInstance::STATE_FAILED, 143 ChromotingInstance::STATE_FAILED,
143 ConvertConnectionError(error)); 144 ConvertConnectionError(error));
144 break; 145 break;
145 } 146 }
146 } 147 }
147 148
148 protocol::ClipboardStub* PepperView::GetClipboardStub() { 149 protocol::ClipboardStub* PepperView::GetClipboardStub() {
149 return instance_; 150 return instance_;
150 } 151 }
151 152
153 void PepperView::SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) {
154 if (!cursor_shape.has_data() ||
155 !cursor_shape.has_width() ||
156 !cursor_shape.has_height() ||
157 !cursor_shape.has_hotspot_x() ||
158 !cursor_shape.has_hotspot_y()) {
159 return;
160 }
161
162 if (pp::ImageData::GetNativeImageDataFormat() !=
163 PP_IMAGEDATAFORMAT_BGRA_PREMUL) {
164 LOG(WARNING) << "Unable to set cursor shape - non-native image format";
165 return;
166 }
167
168 int width = cursor_shape.width();
169 int height = cursor_shape.height();
170
171 if (width > 32 || height > 32) {
172 LOG(WARNING) << "Cursor too large for SetCursor: "
173 << width << "x" << height << " > 32x32";
174 return;
175 }
176
177 int hotspot_x = cursor_shape.hotspot_x();
178 int hotspot_y = cursor_shape.hotspot_y();
179
180 pp::ImageData cursor_image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
181 pp::Size(width, height), false);
182
183 int bytes_per_row = width * 4;
184 const uint8* src_row_data = reinterpret_cast<const uint8*>(
185 cursor_shape.data().data());
186 uint8* dst_row_data = reinterpret_cast<uint8*>(cursor_image.data());
187 for (int row = 0; row < height; row++) {
188 memcpy(dst_row_data, src_row_data, bytes_per_row);
189 src_row_data += bytes_per_row;
190 dst_row_data += cursor_image.stride();
191 }
192
193 pp::MouseCursor::SetCursor(instance_, PP_MOUSECURSOR_TYPE_CUSTOM,
194 cursor_image,
195 pp::Point(hotspot_x, hotspot_y));
196 }
197
152 void PepperView::SetView(const SkISize& view_size, const SkIRect& clip_area) { 198 void PepperView::SetView(const SkISize& view_size, const SkIRect& clip_area) {
153 bool view_changed = false; 199 bool view_changed = false;
154 200
155 if (view_size_ != view_size) { 201 if (view_size_ != view_size) {
156 view_changed = true; 202 view_changed = true;
157 view_size_ = view_size; 203 view_size_ = view_size;
158 204
159 pp::Size pp_size = pp::Size(view_size_.width(), view_size_.height()); 205 pp::Size pp_size = pp::Size(view_size_.width(), view_size_.height());
160 graphics2d_ = pp::Graphics2D(instance_, pp_size, true); 206 graphics2d_ = pp::Graphics2D(instance_, pp_size, true);
161 bool result = instance_->BindGraphics(graphics2d_); 207 bool result = instance_->BindGraphics(graphics2d_);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 385
340 // If there is a buffer queued for rendering then render it now. 386 // If there is a buffer queued for rendering then render it now.
341 if (merge_buffer_ != NULL) { 387 if (merge_buffer_ != NULL) {
342 buffer = merge_buffer_; 388 buffer = merge_buffer_;
343 merge_buffer_ = NULL; 389 merge_buffer_ = NULL;
344 FlushBuffer(merge_clip_area_, buffer, merge_region_); 390 FlushBuffer(merge_clip_area_, buffer, merge_region_);
345 } 391 }
346 } 392 }
347 393
348 } // namespace remoting 394 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698