Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/plugin/pepper_video_renderer_3d.h" | 5 #include "remoting/client/plugin/pepper_video_renderer_3d.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "ppapi/c/pp_codecs.h" | 12 #include "ppapi/c/pp_codecs.h" |
| 13 #include "ppapi/c/ppb_opengles2.h" | |
| 14 #include "ppapi/c/ppb_video_decoder.h" | 13 #include "ppapi/c/ppb_video_decoder.h" |
| 15 #include "ppapi/cpp/instance.h" | 14 #include "ppapi/cpp/instance.h" |
| 16 #include "ppapi/lib/gl/include/GLES2/gl2.h" | 15 #include "ppapi/lib/gl/include/GLES2/gl2.h" |
| 17 #include "ppapi/lib/gl/include/GLES2/gl2ext.h" | 16 #include "ppapi/lib/gl/include/GLES2/gl2ext.h" |
| 18 #include "remoting/proto/video.pb.h" | 17 #include "remoting/proto/video.pb.h" |
| 19 #include "remoting/protocol/frame_stats.h" | 18 #include "remoting/protocol/frame_stats.h" |
| 20 #include "remoting/protocol/performance_tracker.h" | 19 #include "remoting/protocol/performance_tracker.h" |
| 21 #include "remoting/protocol/session_config.h" | 20 #include "remoting/protocol/session_config.h" |
| 22 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" | 21 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
| 23 | 22 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 if (shader_program_) | 83 if (shader_program_) |
| 85 gles2_if_->DeleteProgram(graphics_.pp_resource(), shader_program_); | 84 gles2_if_->DeleteProgram(graphics_.pp_resource(), shader_program_); |
| 86 } | 85 } |
| 87 | 86 |
| 88 void PepperVideoRenderer3D::SetPepperContext( | 87 void PepperVideoRenderer3D::SetPepperContext( |
| 89 pp::Instance* instance, | 88 pp::Instance* instance, |
| 90 EventHandler* event_handler) { | 89 EventHandler* event_handler) { |
| 91 DCHECK(event_handler); | 90 DCHECK(event_handler); |
| 92 DCHECK(!event_handler_); | 91 DCHECK(!event_handler_); |
| 93 | 92 |
| 93 fallback_renderer_.SetPepperContext(instance, event_handler); | |
| 94 | |
| 94 event_handler_ = event_handler; | 95 event_handler_ = event_handler; |
| 95 pp_instance_ = instance; | 96 pp_instance_ = instance; |
| 96 } | 97 } |
| 97 | 98 |
| 98 void PepperVideoRenderer3D::OnViewChanged(const pp::View& view) { | 99 void PepperVideoRenderer3D::OnViewChanged(const pp::View& view) { |
| 100 fallback_renderer_.OnViewChanged(view); | |
| 101 | |
| 99 pp::Size size = view.GetRect().size(); | 102 pp::Size size = view.GetRect().size(); |
| 100 float scale = view.GetDeviceScale(); | 103 float scale = view.GetDeviceScale(); |
| 101 view_size_.set(ceilf(size.width() * scale), ceilf(size.height() * scale)); | 104 view_size_.set(ceilf(size.width() * scale), ceilf(size.height() * scale)); |
| 102 graphics_.ResizeBuffers(view_size_.width(), view_size_.height()); | 105 graphics_.ResizeBuffers(view_size_.width(), view_size_.height()); |
| 103 | 106 |
| 104 force_repaint_ = true; | 107 force_repaint_ = true; |
| 105 PaintIfNeeded(); | 108 PaintIfNeeded(); |
| 106 } | 109 } |
| 107 | 110 |
| 108 void PepperVideoRenderer3D::EnableDebugDirtyRegion(bool enable) { | 111 void PepperVideoRenderer3D::EnableDebugDirtyRegion(bool enable) { |
| 112 fallback_renderer_.EnableDebugDirtyRegion(enable); | |
| 109 debug_dirty_region_ = enable; | 113 debug_dirty_region_ = enable; |
| 110 } | 114 } |
| 111 | 115 |
| 112 bool PepperVideoRenderer3D::Initialize( | 116 bool PepperVideoRenderer3D::Initialize( |
| 113 const ClientContext& context, | 117 const ClientContext& context, |
| 114 protocol::FrameStatsConsumer* stats_consumer) { | 118 protocol::FrameStatsConsumer* stats_consumer) { |
| 119 fallback_renderer_usable_ = | |
| 120 fallback_renderer_.Initialize(context, stats_consumer); | |
| 121 | |
| 115 stats_consumer_ = stats_consumer; | 122 stats_consumer_ = stats_consumer; |
| 116 | 123 |
| 117 const int32_t context_attributes[] = { | 124 const int32_t context_attributes[] = { |
| 118 PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, | 125 PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, |
| 119 PP_GRAPHICS3DATTRIB_BLUE_SIZE, 8, | 126 PP_GRAPHICS3DATTRIB_BLUE_SIZE, 8, |
| 120 PP_GRAPHICS3DATTRIB_GREEN_SIZE, 8, | 127 PP_GRAPHICS3DATTRIB_GREEN_SIZE, 8, |
| 121 PP_GRAPHICS3DATTRIB_RED_SIZE, 8, | 128 PP_GRAPHICS3DATTRIB_RED_SIZE, 8, |
| 122 PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 0, | 129 PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 0, |
| 123 PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 0, | 130 PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 0, |
| 124 PP_GRAPHICS3DATTRIB_SAMPLES, 0, | 131 PP_GRAPHICS3DATTRIB_SAMPLES, 0, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 static const float kVertices[] = { | 166 static const float kVertices[] = { |
| 160 -1, -1, -1, 1, 1, -1, 1, 1, // Position coordinates. | 167 -1, -1, -1, 1, 1, -1, 1, 1, // Position coordinates. |
| 161 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates. | 168 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates. |
| 162 }; | 169 }; |
| 163 | 170 |
| 164 GLuint buffer; | 171 GLuint buffer; |
| 165 gles2_if_->GenBuffers(graphics_3d, 1, &buffer); | 172 gles2_if_->GenBuffers(graphics_3d, 1, &buffer); |
| 166 gles2_if_->BindBuffer(graphics_3d, GL_ARRAY_BUFFER, buffer); | 173 gles2_if_->BindBuffer(graphics_3d, GL_ARRAY_BUFFER, buffer); |
| 167 gles2_if_->BufferData(graphics_3d, GL_ARRAY_BUFFER, sizeof(kVertices), | 174 gles2_if_->BufferData(graphics_3d, GL_ARRAY_BUFFER, sizeof(kVertices), |
| 168 kVertices, GL_STATIC_DRAW); | 175 kVertices, GL_STATIC_DRAW); |
| 176 gles2_if_->GetIntegerv( | |
| 177 graphics_3d, GL_MAX_TEXTURE_SIZE, &gl_max_texture_size_); | |
| 169 | 178 |
| 170 CheckGLError(); | 179 CheckGLError(); |
| 171 | 180 |
| 172 return true; | 181 return true; |
| 173 } | 182 } |
| 174 | 183 |
| 175 void PepperVideoRenderer3D::OnSessionConfig( | 184 void PepperVideoRenderer3D::OnSessionConfig( |
| 176 const protocol::SessionConfig& config) { | 185 const protocol::SessionConfig& config) { |
| 186 fallback_renderer_.OnSessionConfig(config); | |
| 187 | |
| 177 PP_VideoProfile video_profile = PP_VIDEOPROFILE_VP8_ANY; | 188 PP_VideoProfile video_profile = PP_VIDEOPROFILE_VP8_ANY; |
| 178 switch (config.video_config().codec) { | 189 switch (config.video_config().codec) { |
| 179 case protocol::ChannelConfig::CODEC_VP8: | 190 case protocol::ChannelConfig::CODEC_VP8: |
| 180 video_profile = PP_VIDEOPROFILE_VP8_ANY; | 191 video_profile = PP_VIDEOPROFILE_VP8_ANY; |
| 181 break; | 192 break; |
| 182 case protocol::ChannelConfig::CODEC_VP9: | 193 case protocol::ChannelConfig::CODEC_VP9: |
| 183 video_profile = PP_VIDEOPROFILE_VP9_ANY; | 194 video_profile = PP_VIDEOPROFILE_VP9_ANY; |
| 184 break; | 195 break; |
| 185 default: | 196 default: |
| 186 NOTREACHED(); | 197 NOTREACHED(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 205 return nullptr; | 216 return nullptr; |
| 206 } | 217 } |
| 207 | 218 |
| 208 protocol::FrameStatsConsumer* PepperVideoRenderer3D::GetFrameStatsConsumer() { | 219 protocol::FrameStatsConsumer* PepperVideoRenderer3D::GetFrameStatsConsumer() { |
| 209 return stats_consumer_; | 220 return stats_consumer_; |
| 210 } | 221 } |
| 211 | 222 |
| 212 void PepperVideoRenderer3D::ProcessVideoPacket( | 223 void PepperVideoRenderer3D::ProcessVideoPacket( |
| 213 std::unique_ptr<VideoPacket> packet, | 224 std::unique_ptr<VideoPacket> packet, |
| 214 const base::Closure& done) { | 225 const base::Closure& done) { |
| 226 if (!use_fallback_renderer_ && fallback_renderer_usable_) { | |
| 227 use_fallback_renderer_ = | |
|
Sergey Ulanov
2016/07/14 17:45:28
Once we start using the fallback renderer I think
Hzj_jie
2016/07/15 02:30:50
No, if use_fallback_renderer_ is true, it won't fa
| |
| 228 gl_max_texture_size_ < packet->format().screen_width() || | |
|
Sergey Ulanov
2016/07/14 17:45:28
nit: would be more readable if this condition was
Sergey Ulanov
2016/07/14 17:45:28
screen_width() and screen_height() are set only wh
Hzj_jie
2016/07/15 02:30:50
I believe in protobuf, an unset integer field is a
Hzj_jie
2016/07/15 02:30:50
Done.
Sergey Ulanov
2016/07/15 23:33:18
It's true, but in general it's usually better to c
Hzj_jie
2016/07/16 01:19:21
Done.
| |
| 229 gl_max_texture_size_ < packet->format().screen_height(); | |
| 230 } | |
| 231 | |
| 232 if (use_fallback_renderer_) { | |
| 233 fallback_renderer_.GetVideoStub()->ProcessVideoPacket( | |
| 234 std::move(packet), done); | |
| 235 return; | |
| 236 } | |
| 237 | |
| 215 VideoPacket* packet_ptr = packet.get(); | 238 VideoPacket* packet_ptr = packet.get(); |
| 216 std::unique_ptr<FrameTracker> frame_tracker( | 239 std::unique_ptr<FrameTracker> frame_tracker( |
| 217 new FrameTracker(std::move(packet), stats_consumer_, done)); | 240 new FrameTracker(std::move(packet), stats_consumer_, done)); |
| 218 | 241 |
| 219 // Don't need to do anything if the packet is empty. Host sends empty video | 242 // Don't need to do anything if the packet is empty. Host sends empty video |
| 220 // packets when the screen is not changing. | 243 // packets when the screen is not changing. |
| 221 if (packet_ptr->data().empty()) | 244 if (packet_ptr->data().empty()) |
| 222 return; | 245 return; |
| 223 | 246 |
| 224 if (!frame_received_) { | 247 if (!frame_received_) { |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 gles2_if_->AttachShader(graphics_.pp_resource(), shader_program_, shader); | 553 gles2_if_->AttachShader(graphics_.pp_resource(), shader_program_, shader); |
| 531 gles2_if_->DeleteShader(graphics_.pp_resource(), shader); | 554 gles2_if_->DeleteShader(graphics_.pp_resource(), shader); |
| 532 } | 555 } |
| 533 | 556 |
| 534 void PepperVideoRenderer3D::CheckGLError() { | 557 void PepperVideoRenderer3D::CheckGLError() { |
| 535 GLenum error = gles2_if_->GetError(graphics_.pp_resource()); | 558 GLenum error = gles2_if_->GetError(graphics_.pp_resource()); |
| 536 CHECK_EQ(error, static_cast<GLenum>(GL_NO_ERROR)) << "GL error: " << error; | 559 CHECK_EQ(error, static_cast<GLenum>(GL_NO_ERROR)) << "GL error: " << error; |
| 537 } | 560 } |
| 538 | 561 |
| 539 } // namespace remoting | 562 } // namespace remoting |
| OLD | NEW |