| 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 | 61 |
| 62 GlDesktop::~GlDesktop() {} | 62 GlDesktop::~GlDesktop() {} |
| 63 | 63 |
| 64 void GlDesktop::SetCanvas(GlCanvas* canvas) { | 64 void GlDesktop::SetCanvas(base::WeakPtr<Canvas> canvas) { |
| 65 last_desktop_size_.set(0, 0); | 65 last_desktop_size_.set(0, 0); |
| 66 textures_.clear(); | 66 textures_.clear(); |
| 67 canvas_ = canvas; | 67 canvas_ = canvas; |
| 68 if (canvas) { | 68 if (canvas) { |
| 69 max_texture_size_ = canvas->GetMaxTextureSize(); | 69 max_texture_size_ = canvas->GetMaxTextureSize(); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 void GlDesktop::SetVideoFrame(const webrtc::DesktopFrame& frame) { | 73 void GlDesktop::SetVideoFrame(const webrtc::DesktopFrame& frame) { |
| 74 if (!canvas_) { | 74 if (!canvas_) { |
| 75 return; | 75 return; |
| 76 } | 76 } |
| 77 if (!frame.size().equals(last_desktop_size_)) { | 77 if (!frame.size().equals(last_desktop_size_)) { |
| 78 last_desktop_size_.set(frame.size().width(), frame.size().height()); | 78 last_desktop_size_.set(frame.size().width(), frame.size().height()); |
| 79 ReallocateTextures(last_desktop_size_); | 79 ReallocateTextures(last_desktop_size_); |
| 80 } | 80 } |
| 81 for (std::unique_ptr<GlDesktopTextureContainer>& texture : textures_) { | 81 for (std::unique_ptr<GlDesktopTextureContainer>& texture : textures_) { |
| 82 SetFrameForTexture(frame, texture->layer.get(), texture->rect); | 82 SetFrameForTexture(frame, texture->layer.get(), texture->rect); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 void GlDesktop::Draw() { | 86 bool GlDesktop::Draw() { |
| 87 DCHECK(thread_checker_.CalledOnValidThread()); |
| 87 if (!textures_.empty() && !last_desktop_size_.is_empty()) { | 88 if (!textures_.empty() && !last_desktop_size_.is_empty()) { |
| 88 for (std::unique_ptr<GlDesktopTextureContainer>& texture : textures_) { | 89 for (std::unique_ptr<GlDesktopTextureContainer>& texture : textures_) { |
| 89 texture->layer->Draw(1.0f); | 90 texture->layer->Draw(1.0f); |
| 90 } | 91 } |
| 91 } | 92 } |
| 93 return false; |
| 94 } |
| 95 |
| 96 int GlDesktop::ZIndex() { |
| 97 return Drawable::ZIndexDefault::DESKTOP; |
| 92 } | 98 } |
| 93 | 99 |
| 94 void GlDesktop::ReallocateTextures(const webrtc::DesktopSize& size) { | 100 void GlDesktop::ReallocateTextures(const webrtc::DesktopSize& size) { |
| 95 DCHECK(max_texture_size_); | 101 DCHECK(max_texture_size_); |
| 96 DCHECK(canvas_); | 102 DCHECK(canvas_); |
| 97 textures_.clear(); | 103 textures_.clear(); |
| 98 | 104 |
| 99 int textures_per_row = | 105 int textures_per_row = |
| 100 (size.width() + max_texture_size_ - 1) / max_texture_size_; | 106 (size.width() + max_texture_size_ - 1) / max_texture_size_; |
| 101 | 107 |
| 102 int textures_per_column = | 108 int textures_per_column = |
| 103 (size.height() + max_texture_size_ - 1) / max_texture_size_; | 109 (size.height() + max_texture_size_ - 1) / max_texture_size_; |
| 104 | 110 |
| 105 webrtc::DesktopRect desktop_rect = webrtc::DesktopRect::MakeSize(size); | 111 webrtc::DesktopRect desktop_rect = webrtc::DesktopRect::MakeSize(size); |
| 106 | 112 |
| 107 int texture_id = kGlDesktopFirstTextureId; | 113 int texture_id = kGlDesktopFirstTextureId; |
| 108 std::array<float, 8> positions; | 114 std::array<float, 8> positions; |
| 109 for (int x = 0; x < textures_per_row; x++) { | 115 for (int x = 0; x < textures_per_row; x++) { |
| 110 for (int y = 0; y < textures_per_column; y++) { | 116 for (int y = 0; y < textures_per_column; y++) { |
| 111 webrtc::DesktopRect rect = webrtc::DesktopRect::MakeXYWH( | 117 webrtc::DesktopRect rect = webrtc::DesktopRect::MakeXYWH( |
| 112 x * max_texture_size_, y * max_texture_size_, max_texture_size_, | 118 x * max_texture_size_, y * max_texture_size_, max_texture_size_, |
| 113 max_texture_size_); | 119 max_texture_size_); |
| 114 rect.IntersectWith(desktop_rect); | 120 rect.IntersectWith(desktop_rect); |
| 115 std::unique_ptr<GlDesktopTextureContainer> container = | 121 std::unique_ptr<GlDesktopTextureContainer> container = base::WrapUnique( |
| 116 base::WrapUnique(new GlDesktopTextureContainer{ | 122 new GlDesktopTextureContainer{base::MakeUnique<GlRenderLayer>( |
| 117 base::MakeUnique<GlRenderLayer>(texture_id, canvas_), rect}); | 123 texture_id, canvas_->GetWeakPtr()), |
| 124 rect}); |
| 118 FillRectangleVertexPositions(rect.left(), rect.top(), rect.width(), | 125 FillRectangleVertexPositions(rect.left(), rect.top(), rect.width(), |
| 119 rect.height(), &positions); | 126 rect.height(), &positions); |
| 120 container->layer->SetVertexPositions(positions); | 127 container->layer->SetVertexPositions(positions); |
| 121 textures_.push_back(std::move(container)); | 128 textures_.push_back(std::move(container)); |
| 122 texture_id++; | 129 texture_id++; |
| 123 } | 130 } |
| 124 } | 131 } |
| 125 } | 132 } |
| 126 | 133 |
| 134 base::WeakPtr<Drawable> GlDesktop::GetWeakPtr() { |
| 135 DCHECK(thread_checker_.CalledOnValidThread()); |
| 136 return weak_factory_.GetWeakPtr(); |
| 137 } |
| 138 |
| 127 } // namespace remoting | 139 } // namespace remoting |
| OLD | NEW |