OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/display/gl_cursor.h" | 5 #include "remoting/client/display/gl_cursor.h" |
6 | 6 |
7 #include "remoting/base/util.h" | 7 #include "remoting/base/util.h" |
8 #include "remoting/client/display/gl_canvas.h" | 8 #include "remoting/client/display/gl_canvas.h" |
9 #include "remoting/client/display/gl_math.h" | 9 #include "remoting/client/display/gl_math.h" |
10 #include "remoting/client/display/gl_render_layer.h" | 10 #include "remoting/client/display/gl_render_layer.h" |
11 #include "remoting/client/display/gl_texture_ids.h" | 11 #include "remoting/client/display/gl_texture_ids.h" |
12 #include "remoting/proto/control.pb.h" | 12 #include "remoting/proto/control.pb.h" |
13 #include "third_party/libyuv/include/libyuv/convert_argb.h" | 13 #include "third_party/libyuv/include/libyuv/convert_argb.h" |
14 | 14 |
15 namespace remoting { | 15 namespace remoting { |
16 | 16 |
17 namespace { | 17 namespace { |
18 const int kDefaultCursorDataSize = 32 * 32 * GlRenderLayer::kBytesPerPixel; | 18 const int kDefaultCursorDataSize = 32 * 32 * GlRenderLayer::kBytesPerPixel; |
19 } // namespace | 19 } // namespace |
20 | 20 |
21 GlCursor::GlCursor() {} | 21 GlCursor::GlCursor() : weak_factory_(this) { |
22 SetZIndex(DrawableZIndex::CURSOR); | |
23 } | |
22 | 24 |
23 GlCursor::~GlCursor() {} | 25 GlCursor::~GlCursor() {} |
24 | 26 |
25 void GlCursor::SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) { | 27 void GlCursor::SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) { |
26 int data_size = cursor_shape.width() * cursor_shape.height() * | 28 int data_size = cursor_shape.width() * cursor_shape.height() * |
27 GlRenderLayer::kBytesPerPixel; | 29 GlRenderLayer::kBytesPerPixel; |
28 if (current_cursor_data_size_ < data_size) { | 30 if (current_cursor_data_size_ < data_size) { |
29 current_cursor_data_size_ = | 31 current_cursor_data_size_ = |
30 kDefaultCursorDataSize > data_size ? kDefaultCursorDataSize : data_size; | 32 kDefaultCursorDataSize > data_size ? kDefaultCursorDataSize : data_size; |
31 current_cursor_data_.reset(new uint8_t[current_cursor_data_size_]); | 33 current_cursor_data_.reset(new uint8_t[current_cursor_data_size_]); |
(...skipping 29 matching lines...) Expand all Loading... | |
61 current_cursor_width_, current_cursor_height_, &positions); | 63 current_cursor_width_, current_cursor_height_, &positions); |
62 if (layer_) { | 64 if (layer_) { |
63 layer_->SetVertexPositions(positions); | 65 layer_->SetVertexPositions(positions); |
64 } | 66 } |
65 } | 67 } |
66 | 68 |
67 void GlCursor::SetCursorVisible(bool visible) { | 69 void GlCursor::SetCursorVisible(bool visible) { |
68 visible_ = visible; | 70 visible_ = visible; |
69 } | 71 } |
70 | 72 |
71 void GlCursor::SetCanvas(GlCanvas* canvas) { | 73 void GlCursor::SetCanvas(base::WeakPtr<Canvas> canvas) { |
72 if (!canvas) { | 74 if (!canvas) { |
73 layer_.reset(); | 75 layer_.reset(); |
74 return; | 76 return; |
75 } | 77 } |
76 layer_.reset(new GlRenderLayer(kGlCursorTextureId, canvas)); | 78 layer_.reset(new GlRenderLayer(kGlCursorTextureId, canvas->GetWeakPtr())); |
Yuwei
2017/01/10 22:09:53
Just pass canvas. No need to call GetWeakPtr()
| |
77 if (current_cursor_data_) { | 79 if (current_cursor_data_) { |
78 SetCurrentCursorShape(true); | 80 SetCurrentCursorShape(true); |
79 } | 81 } |
80 SetCursorPosition(cursor_x_, cursor_y_); | 82 SetCursorPosition(cursor_x_, cursor_y_); |
81 } | 83 } |
82 | 84 |
83 void GlCursor::Draw() { | 85 bool GlCursor::Draw() { |
86 DCHECK(thread_checker_.CalledOnValidThread()); | |
84 if (layer_ && current_cursor_data_ && visible_) { | 87 if (layer_ && current_cursor_data_ && visible_) { |
85 layer_->Draw(1.f); | 88 layer_->Draw(1.f); |
86 } | 89 } |
90 return false; | |
87 } | 91 } |
88 | 92 |
89 void GlCursor::SetCurrentCursorShape(bool size_changed) { | 93 void GlCursor::SetCurrentCursorShape(bool size_changed) { |
90 if (layer_) { | 94 if (layer_) { |
91 if (size_changed) { | 95 if (size_changed) { |
92 layer_->SetTexture(current_cursor_data_.get(), current_cursor_width_, | 96 layer_->SetTexture(current_cursor_data_.get(), current_cursor_width_, |
93 current_cursor_height_, 0); | 97 current_cursor_height_, 0); |
94 } else { | 98 } else { |
95 layer_->UpdateTexture(current_cursor_data_.get(), 0, 0, | 99 layer_->UpdateTexture(current_cursor_data_.get(), 0, 0, |
96 current_cursor_width_, current_cursor_width_, 0); | 100 current_cursor_width_, current_cursor_width_, 0); |
97 } | 101 } |
98 } | 102 } |
99 } | 103 } |
100 | 104 |
105 base::WeakPtr<Drawable> GlCursor::GetWeakPtr() { | |
106 DCHECK(thread_checker_.CalledOnValidThread()); | |
107 return weak_factory_.GetWeakPtr(); | |
108 } | |
109 | |
101 } // namespace remoting | 110 } // namespace remoting |
OLD | NEW |