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

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

Issue 10382184: [Chromoting] Initial plumbing for cursor shape. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unused vars. Fix Mac Capturer Unittest. Created 8 years, 6 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
« no previous file with comments | « remoting/client/plugin/chromoting_instance.h ('k') | remoting/client/plugin/pepper_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/chromoting_instance.h" 5 #include "remoting/client/plugin/chromoting_instance.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
13 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "base/string_split.h" 17 #include "base/string_split.h"
18 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
19 #include "base/synchronization/waitable_event.h" 19 #include "base/synchronization/waitable_event.h"
20 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
21 #include "base/values.h" 21 #include "base/values.h"
22 #include "jingle/glue/thread_wrapper.h" 22 #include "jingle/glue/thread_wrapper.h"
23 #include "media/base/media.h" 23 #include "media/base/media.h"
24 #include "ppapi/cpp/completion_callback.h" 24 #include "ppapi/cpp/completion_callback.h"
25 #include "ppapi/cpp/input_event.h" 25 #include "ppapi/cpp/input_event.h"
26 #include "ppapi/cpp/mouse_cursor.h"
26 #include "ppapi/cpp/rect.h" 27 #include "ppapi/cpp/rect.h"
27 // TODO(wez): Remove this when crbug.com/86353 is complete. 28 // TODO(wez): Remove this when crbug.com/86353 is complete.
28 #include "ppapi/cpp/private/var_private.h" 29 #include "ppapi/cpp/private/var_private.h"
29 #include "remoting/base/constants.h" 30 #include "remoting/base/constants.h"
30 #include "remoting/base/util.h" 31 #include "remoting/base/util.h"
31 #include "remoting/client/client_config.h" 32 #include "remoting/client/client_config.h"
32 #include "remoting/client/chromoting_client.h" 33 #include "remoting/client/chromoting_client.h"
33 #include "remoting/client/frame_consumer_proxy.h" 34 #include "remoting/client/frame_consumer_proxy.h"
34 #include "remoting/client/plugin/pepper_input_handler.h" 35 #include "remoting/client/plugin/pepper_input_handler.h"
35 #include "remoting/client/plugin/pepper_port_allocator.h" 36 #include "remoting/client/plugin/pepper_port_allocator.h"
36 #include "remoting/client/plugin/pepper_view.h" 37 #include "remoting/client/plugin/pepper_view.h"
37 #include "remoting/client/plugin/pepper_xmpp_proxy.h" 38 #include "remoting/client/plugin/pepper_xmpp_proxy.h"
38 #include "remoting/client/rectangle_update_decoder.h" 39 #include "remoting/client/rectangle_update_decoder.h"
39 #include "remoting/protocol/connection_to_host.h" 40 #include "remoting/protocol/connection_to_host.h"
40 #include "remoting/protocol/host_stub.h" 41 #include "remoting/protocol/host_stub.h"
41 #include "remoting/protocol/input_event_tracker.h" 42 #include "remoting/protocol/input_event_tracker.h"
42 #include "remoting/protocol/libjingle_transport_factory.h" 43 #include "remoting/protocol/libjingle_transport_factory.h"
43 #include "remoting/protocol/mouse_input_filter.h" 44 #include "remoting/protocol/mouse_input_filter.h"
44 45
45 // Windows defines 'PostMessage', so we have to undef it. 46 // Windows defines 'PostMessage', so we have to undef it.
46 #if defined(PostMessage) 47 #if defined(PostMessage)
47 #undef PostMessage 48 #undef PostMessage
48 #endif 49 #endif
49 50
50 namespace remoting { 51 namespace remoting {
51 52
52 namespace { 53 namespace {
53 54
55 // 32-bit BGRA is 4 bytes per pixel.
56 const int kBytesPerPixel = 4;
57
54 const int kPerfStatsIntervalMs = 1000; 58 const int kPerfStatsIntervalMs = 1000;
55 59
56 std::string ConnectionStateToString(ChromotingInstance::ConnectionState state) { 60 std::string ConnectionStateToString(ChromotingInstance::ConnectionState state) {
57 switch (state) { 61 switch (state) {
58 case ChromotingInstance::STATE_CONNECTING: 62 case ChromotingInstance::STATE_CONNECTING:
59 return "CONNECTING"; 63 return "CONNECTING";
60 case ChromotingInstance::STATE_INITIALIZING: 64 case ChromotingInstance::STATE_INITIALIZING:
61 return "INITIALIZING"; 65 return "INITIALIZING";
62 case ChromotingInstance::STATE_CONNECTED: 66 case ChromotingInstance::STATE_CONNECTED:
63 return "CONNECTED"; 67 return "CONNECTED";
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 } 553 }
550 554
551 void ChromotingInstance::InjectClipboardEvent( 555 void ChromotingInstance::InjectClipboardEvent(
552 const protocol::ClipboardEvent& event) { 556 const protocol::ClipboardEvent& event) {
553 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); 557 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
554 data->SetString("mimeType", event.mime_type()); 558 data->SetString("mimeType", event.mime_type());
555 data->SetString("item", event.data()); 559 data->SetString("item", event.data());
556 PostChromotingMessage("injectClipboardItem", data.Pass()); 560 PostChromotingMessage("injectClipboardItem", data.Pass());
557 } 561 }
558 562
563 void ChromotingInstance::SetCursorShape(
564 const protocol::CursorShapeInfo& cursor_shape) {
565 if (!cursor_shape.has_data() ||
566 !cursor_shape.has_width() ||
567 !cursor_shape.has_height() ||
568 !cursor_shape.has_hotspot_x() ||
569 !cursor_shape.has_hotspot_y()) {
570 return;
571 }
572
573 if (pp::ImageData::GetNativeImageDataFormat() !=
574 PP_IMAGEDATAFORMAT_BGRA_PREMUL) {
575 VLOG(2) << "Unable to set cursor shape - non-native image format";
576 return;
577 }
578
579 int width = cursor_shape.width();
580 int height = cursor_shape.height();
581
582 if (width > 32 || height > 32) {
583 VLOG(2) << "Cursor too large for SetCursor: "
584 << width << "x" << height << " > 32x32";
585 return;
586 }
587
588 int hotspot_x = cursor_shape.hotspot_x();
589 int hotspot_y = cursor_shape.hotspot_y();
590
591 pp::ImageData cursor_image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
592 pp::Size(width, height), false);
593
594 int bytes_per_row = width * kBytesPerPixel;
595 const uint8* src_row_data = reinterpret_cast<const uint8*>(
596 cursor_shape.data().data());
597 uint8* dst_row_data = reinterpret_cast<uint8*>(cursor_image.data());
598 for (int row = 0; row < height; row++) {
599 memcpy(dst_row_data, src_row_data, bytes_per_row);
600 src_row_data += bytes_per_row;
601 dst_row_data += cursor_image.stride();
602 }
603
604 pp::MouseCursor::SetCursor(this, PP_MOUSECURSOR_TYPE_CUSTOM,
605 cursor_image,
606 pp::Point(hotspot_x, hotspot_y));
607 }
608
559 // static 609 // static
560 void ChromotingInstance::RegisterLogMessageHandler() { 610 void ChromotingInstance::RegisterLogMessageHandler() {
561 base::AutoLock lock(g_logging_lock.Get()); 611 base::AutoLock lock(g_logging_lock.Get());
562 612
563 VLOG(1) << "Registering global log handler"; 613 VLOG(1) << "Registering global log handler";
564 614
565 // Record previous handler so we can call it in a chain. 615 // Record previous handler so we can call it in a chain.
566 g_logging_old_handler = logging::GetLogMessageHandler(); 616 g_logging_old_handler = logging::GetLogMessageHandler();
567 617
568 // Set up log message handler. 618 // Set up log message handler.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 PostChromotingMessage("logDebugMessage", data.Pass()); 700 PostChromotingMessage("logDebugMessage", data.Pass());
651 g_logging_to_plugin = false; 701 g_logging_to_plugin = false;
652 } 702 }
653 703
654 bool ChromotingInstance::IsConnected() { 704 bool ChromotingInstance::IsConnected() {
655 return host_connection_.get() && 705 return host_connection_.get() &&
656 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED); 706 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED);
657 } 707 }
658 708
659 } // namespace remoting 709 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/plugin/chromoting_instance.h ('k') | remoting/client/plugin/pepper_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698