Index: remoting/client/gl_desktop.cc |
diff --git a/remoting/client/gl_desktop.cc b/remoting/client/gl_desktop.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4a6d26bfea4b8e6d635b4ac8c14d9d3087f5fa8d |
--- /dev/null |
+++ b/remoting/client/gl_desktop.cc |
@@ -0,0 +1,64 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "remoting/client/gl_desktop.h" |
+ |
+#include "base/logging.h" |
+#include "remoting/client/gl_canvas.h" |
+#include "remoting/client/gl_render_layer.h" |
+#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
+ |
+namespace { |
+ |
+const int kTextureId = 0; |
+const int kBytesPerPixel = 4; |
Sergey Ulanov
2016/07/09 01:01:20
use webrtc::DesktopFrame::kBytesPerPixel
Yuwei
2016/07/11 22:38:23
Done.
|
+ |
+} |
Sergey Ulanov
2016/07/09 01:01:20
// namespace
Yuwei
2016/07/11 22:38:23
Done.
|
+ |
+namespace remoting { |
+ |
+GlDesktop::GlDesktop() {} |
+ |
+GlDesktop::~GlDesktop() {} |
+ |
+void GlDesktop::SetCanvas(GlCanvas* canvas) { |
+ if (!canvas) { |
+ layer_.reset(); |
+ return; |
+ } |
+ layer_.reset(new GlRenderLayer(kTextureId, canvas)); |
+ if (last_frame_) { |
+ layer_->SetTexture(last_frame_->data(), last_frame_->size().width(), |
+ last_frame_->size().height()); |
+ } |
+} |
+ |
+void GlDesktop::SetVideoFrame(std::unique_ptr<webrtc::DesktopFrame> frame) { |
+ if (layer_) { |
+ if (!last_frame_ || frame->size().width() != last_frame_->size().width() || |
Sergey Ulanov
2016/07/09 01:01:20
!frame->size().equal(last_frame_->size())
to avoid
Yuwei
2016/07/11 22:38:23
Done.
|
+ frame->size().height() != last_frame_->size().height()) { |
+ layer_->SetTexture(frame->data(), frame->size().width(), |
+ frame->size().height()); |
+ } else { |
+ for (webrtc::DesktopRegion::Iterator i(frame->updated_region()); |
+ !i.IsAtEnd(); i.Advance()) { |
+ const uint8_t* rect_start = |
+ reinterpret_cast<const uint8_t*>(frame->data()) + |
Sergey Ulanov
2016/07/09 01:01:20
Don't need this cast.
Yuwei
2016/07/11 22:38:23
Done.
|
+ frame->stride() * i.rect().top() + i.rect().left() * kBytesPerPixel; |
Sergey Ulanov
2016/07/09 01:01:20
Use DesktopFrame::GetFrameDataAtPos(i.rect().top_l
|
+ layer_->UpdateTexture(rect_start, i.rect().left(), i.rect().top(), |
+ i.rect().width(), i.rect().height(), |
+ frame->stride() / kBytesPerPixel); |
Sergey Ulanov
2016/07/09 01:01:20
stride() may not be multiple of kBytesPerPixel. Pa
Yuwei
2016/07/09 01:21:24
Hmm... The problem is GL_UNPACK_ROW_LENGTH expects
Sergey Ulanov
2016/07/13 04:42:11
hm, yeah. I don't know of any real world scenario
Yuwei
2016/07/13 18:14:16
Done. Acknowledged.
|
+ } |
+ } |
+ } |
+ last_frame_ = std::move(frame); |
+} |
+ |
+void GlDesktop::Draw() { |
+ if (layer_ && last_frame_) { |
+ layer_->Draw(); |
+ } |
+} |
+ |
+} // namespace remoting |