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_desktop.h" | 5 #include "remoting/client/display/gl_desktop.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "remoting/client/display/gl_canvas.h" | 9 #include "remoting/client/display/canvas.h" |
10 #include "remoting/client/display/gl_math.h" | 10 #include "remoting/client/display/gl_math.h" |
11 #include "remoting/client/display/gl_render_layer.h" | 11 #include "remoting/client/display/gl_render_layer.h" |
12 #include "remoting/client/display/gl_texture_ids.h" | 12 #include "remoting/client/display/gl_texture_ids.h" |
13 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 13 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
14 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" | 14 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
15 | 15 |
16 namespace remoting { | 16 namespace remoting { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
(...skipping 30 matching lines...) Expand all Loading... |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 struct GlDesktop::GlDesktopTextureContainer { | 55 struct GlDesktop::GlDesktopTextureContainer { |
56 std::unique_ptr<GlRenderLayer> layer; | 56 std::unique_ptr<GlRenderLayer> layer; |
57 webrtc::DesktopRect rect; | 57 webrtc::DesktopRect rect; |
58 }; | 58 }; |
59 | 59 |
60 GlDesktop::GlDesktop() {} | 60 GlDesktop::GlDesktop() : weak_factory_(this) { |
| 61 SetZIndex(DrawableZIndex::DESKTOP); |
| 62 } |
61 | 63 |
62 GlDesktop::~GlDesktop() {} | 64 GlDesktop::~GlDesktop() {} |
63 | 65 |
64 void GlDesktop::SetCanvas(GlCanvas* canvas) { | 66 void GlDesktop::SetCanvas(base::WeakPtr<Canvas> canvas) { |
65 last_desktop_size_.set(0, 0); | 67 last_desktop_size_.set(0, 0); |
66 textures_.clear(); | 68 textures_.clear(); |
67 canvas_ = canvas; | 69 canvas_ = canvas; |
68 if (canvas) { | 70 if (canvas) { |
69 max_texture_size_ = canvas->GetMaxTextureSize(); | 71 max_texture_size_ = canvas->GetMaxTextureSize(); |
70 } | 72 } |
71 } | 73 } |
72 | 74 |
73 void GlDesktop::SetVideoFrame(const webrtc::DesktopFrame& frame) { | 75 void GlDesktop::SetVideoFrame(const webrtc::DesktopFrame& frame) { |
74 if (!canvas_) { | 76 if (!canvas_) { |
75 return; | 77 return; |
76 } | 78 } |
77 if (!frame.size().equals(last_desktop_size_)) { | 79 if (!frame.size().equals(last_desktop_size_)) { |
78 last_desktop_size_.set(frame.size().width(), frame.size().height()); | 80 last_desktop_size_.set(frame.size().width(), frame.size().height()); |
79 ReallocateTextures(last_desktop_size_); | 81 ReallocateTextures(last_desktop_size_); |
80 } | 82 } |
81 for (std::unique_ptr<GlDesktopTextureContainer>& texture : textures_) { | 83 for (std::unique_ptr<GlDesktopTextureContainer>& texture : textures_) { |
82 SetFrameForTexture(frame, texture->layer.get(), texture->rect); | 84 SetFrameForTexture(frame, texture->layer.get(), texture->rect); |
83 } | 85 } |
84 } | 86 } |
85 | 87 |
86 void GlDesktop::Draw() { | 88 bool GlDesktop::Draw() { |
| 89 DCHECK(thread_checker_.CalledOnValidThread()); |
87 if (!textures_.empty() && !last_desktop_size_.is_empty()) { | 90 if (!textures_.empty() && !last_desktop_size_.is_empty()) { |
88 for (std::unique_ptr<GlDesktopTextureContainer>& texture : textures_) { | 91 for (std::unique_ptr<GlDesktopTextureContainer>& texture : textures_) { |
89 texture->layer->Draw(1.0f); | 92 texture->layer->Draw(1.0f); |
90 } | 93 } |
91 } | 94 } |
| 95 return false; |
92 } | 96 } |
93 | 97 |
94 void GlDesktop::ReallocateTextures(const webrtc::DesktopSize& size) { | 98 void GlDesktop::ReallocateTextures(const webrtc::DesktopSize& size) { |
95 DCHECK(max_texture_size_); | 99 DCHECK(max_texture_size_); |
96 DCHECK(canvas_); | 100 DCHECK(canvas_); |
97 textures_.clear(); | 101 textures_.clear(); |
98 | 102 |
99 int textures_per_row = | 103 int textures_per_row = |
100 (size.width() + max_texture_size_ - 1) / max_texture_size_; | 104 (size.width() + max_texture_size_ - 1) / max_texture_size_; |
101 | 105 |
102 int textures_per_column = | 106 int textures_per_column = |
103 (size.height() + max_texture_size_ - 1) / max_texture_size_; | 107 (size.height() + max_texture_size_ - 1) / max_texture_size_; |
104 | 108 |
105 webrtc::DesktopRect desktop_rect = webrtc::DesktopRect::MakeSize(size); | 109 webrtc::DesktopRect desktop_rect = webrtc::DesktopRect::MakeSize(size); |
106 | 110 |
107 int texture_id = kGlDesktopFirstTextureId; | 111 int texture_id = kGlDesktopFirstTextureId; |
108 std::array<float, 8> positions; | 112 std::array<float, 8> positions; |
109 for (int x = 0; x < textures_per_row; x++) { | 113 for (int x = 0; x < textures_per_row; x++) { |
110 for (int y = 0; y < textures_per_column; y++) { | 114 for (int y = 0; y < textures_per_column; y++) { |
111 webrtc::DesktopRect rect = webrtc::DesktopRect::MakeXYWH( | 115 webrtc::DesktopRect rect = webrtc::DesktopRect::MakeXYWH( |
112 x * max_texture_size_, y * max_texture_size_, max_texture_size_, | 116 x * max_texture_size_, y * max_texture_size_, max_texture_size_, |
113 max_texture_size_); | 117 max_texture_size_); |
114 rect.IntersectWith(desktop_rect); | 118 rect.IntersectWith(desktop_rect); |
115 std::unique_ptr<GlDesktopTextureContainer> container = | 119 std::unique_ptr<GlDesktopTextureContainer> container = base::WrapUnique( |
116 base::WrapUnique(new GlDesktopTextureContainer{ | 120 new GlDesktopTextureContainer{base::MakeUnique<GlRenderLayer>( |
117 base::MakeUnique<GlRenderLayer>(texture_id, canvas_), rect}); | 121 texture_id, canvas_->GetWeakPtr()), |
| 122 rect}); |
118 FillRectangleVertexPositions(rect.left(), rect.top(), rect.width(), | 123 FillRectangleVertexPositions(rect.left(), rect.top(), rect.width(), |
119 rect.height(), &positions); | 124 rect.height(), &positions); |
120 container->layer->SetVertexPositions(positions); | 125 container->layer->SetVertexPositions(positions); |
121 textures_.push_back(std::move(container)); | 126 textures_.push_back(std::move(container)); |
122 texture_id++; | 127 texture_id++; |
123 } | 128 } |
124 } | 129 } |
125 } | 130 } |
126 | 131 |
| 132 base::WeakPtr<Drawable> GlDesktop::GetWeakPtr() { |
| 133 DCHECK(thread_checker_.CalledOnValidThread()); |
| 134 return weak_factory_.GetWeakPtr(); |
| 135 } |
| 136 |
127 } // namespace remoting | 137 } // namespace remoting |
OLD | NEW |