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(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() { |
87 if (!textures_.empty() && !last_desktop_size_.is_empty()) { | 89 if (!textures_.empty() && !last_desktop_size_.is_empty()) { |
88 for (std::unique_ptr<GlDesktopTextureContainer>& texture : textures_) { | 90 for (std::unique_ptr<GlDesktopTextureContainer>& texture : textures_) { |
89 texture->layer->Draw(1.0f); | 91 texture->layer->Draw(1.0f); |
90 } | 92 } |
91 } | 93 } |
| 94 return false; |
92 } | 95 } |
93 | 96 |
94 void GlDesktop::ReallocateTextures(const webrtc::DesktopSize& size) { | 97 void GlDesktop::ReallocateTextures(const webrtc::DesktopSize& size) { |
95 DCHECK(max_texture_size_); | 98 DCHECK(max_texture_size_); |
96 DCHECK(canvas_); | 99 DCHECK(canvas_); |
97 textures_.clear(); | 100 textures_.clear(); |
98 | 101 |
99 int textures_per_row = | 102 int textures_per_row = |
100 (size.width() + max_texture_size_ - 1) / max_texture_size_; | 103 (size.width() + max_texture_size_ - 1) / max_texture_size_; |
101 | 104 |
(...skipping 15 matching lines...) Expand all Loading... |
117 base::MakeUnique<GlRenderLayer>(texture_id, canvas_), rect}); | 120 base::MakeUnique<GlRenderLayer>(texture_id, canvas_), rect}); |
118 FillRectangleVertexPositions(rect.left(), rect.top(), rect.width(), | 121 FillRectangleVertexPositions(rect.left(), rect.top(), rect.width(), |
119 rect.height(), &positions); | 122 rect.height(), &positions); |
120 container->layer->SetVertexPositions(positions); | 123 container->layer->SetVertexPositions(positions); |
121 textures_.push_back(std::move(container)); | 124 textures_.push_back(std::move(container)); |
122 texture_id++; | 125 texture_id++; |
123 } | 126 } |
124 } | 127 } |
125 } | 128 } |
126 | 129 |
| 130 base::WeakPtr<Drawable> GlDesktop::GetWeakPtr() { |
| 131 return weak_factory_.GetWeakPtr(); |
| 132 } |
| 133 |
127 } // namespace remoting | 134 } // namespace remoting |
OLD | NEW |