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> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 if (shader_program_) | 84 if (shader_program_) |
| 85 gles2_if_->DeleteProgram(graphics_.pp_resource(), shader_program_); | 85 gles2_if_->DeleteProgram(graphics_.pp_resource(), shader_program_); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void PepperVideoRenderer3D::SetPepperContext( | 88 void PepperVideoRenderer3D::SetPepperContext( |
| 89 pp::Instance* instance, | 89 pp::Instance* instance, |
| 90 EventHandler* event_handler) { | 90 EventHandler* event_handler) { |
| 91 DCHECK(event_handler); | 91 DCHECK(event_handler); |
| 92 DCHECK(!event_handler_); | 92 DCHECK(!event_handler_); |
| 93 | 93 |
| 94 fallback_renderer_.SetPepperContext(instance, event_handler); | |
| 95 | |
| 94 event_handler_ = event_handler; | 96 event_handler_ = event_handler; |
| 95 pp_instance_ = instance; | 97 pp_instance_ = instance; |
| 96 } | 98 } |
| 97 | 99 |
| 98 void PepperVideoRenderer3D::OnViewChanged(const pp::View& view) { | 100 void PepperVideoRenderer3D::OnViewChanged(const pp::View& view) { |
| 101 fallback_renderer_.OnViewChanged(view); | |
| 102 | |
| 99 pp::Size size = view.GetRect().size(); | 103 pp::Size size = view.GetRect().size(); |
| 100 float scale = view.GetDeviceScale(); | 104 float scale = view.GetDeviceScale(); |
| 105 if (scale == 0) { | |
|
Sergey Ulanov
2016/10/12 21:53:31
scale is never expected to be 0. maybe replace it
Hzj_jie
2016/10/12 23:42:46
Done.
| |
| 106 LOG(WARNING) << "Unexpected device scale factor received."; | |
| 107 scale = 1; | |
| 108 } | |
| 109 gl_scaled_limits_.texture_size = gl_limits_.texture_size / scale; | |
|
Sergey Ulanov
2016/10/12 21:53:31
I'm not sure this is correct. textures should not
Hzj_jie
2016/10/12 23:42:46
Yes, the GetDeviceScale returns a scale factor to
| |
| 110 gl_scaled_limits_.viewport_size[0] = gl_limits_.viewport_size[0] / scale; | |
| 111 gl_scaled_limits_.viewport_size[1] = gl_limits_.viewport_size[1] / scale; | |
| 101 view_size_.set(ceilf(size.width() * scale), ceilf(size.height() * scale)); | 112 view_size_.set(ceilf(size.width() * scale), ceilf(size.height() * scale)); |
| 102 graphics_.ResizeBuffers(view_size_.width(), view_size_.height()); | 113 graphics_.ResizeBuffers(view_size_.width(), view_size_.height()); |
| 103 | 114 |
| 104 force_repaint_ = true; | 115 force_repaint_ = true; |
| 105 PaintIfNeeded(); | 116 PaintIfNeeded(); |
| 106 } | 117 } |
| 107 | 118 |
| 108 void PepperVideoRenderer3D::EnableDebugDirtyRegion(bool enable) { | 119 void PepperVideoRenderer3D::EnableDebugDirtyRegion(bool enable) { |
| 120 fallback_renderer_.EnableDebugDirtyRegion(enable); | |
| 109 debug_dirty_region_ = enable; | 121 debug_dirty_region_ = enable; |
| 110 } | 122 } |
| 111 | 123 |
| 112 bool PepperVideoRenderer3D::Initialize( | 124 bool PepperVideoRenderer3D::Initialize( |
| 113 const ClientContext& context, | 125 const ClientContext& context, |
| 114 protocol::FrameStatsConsumer* stats_consumer) { | 126 protocol::FrameStatsConsumer* stats_consumer) { |
| 127 CHECK(fallback_renderer_.Initialize(context, stats_consumer)); | |
|
Sergey Ulanov
2016/10/12 21:53:31
Please change this to
if (!fallback_renderer_.I
Hzj_jie
2016/10/12 23:42:46
Done.
| |
| 128 | |
| 115 stats_consumer_ = stats_consumer; | 129 stats_consumer_ = stats_consumer; |
| 116 | 130 |
| 117 const int32_t context_attributes[] = { | 131 const int32_t context_attributes[] = { |
| 118 PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, | 132 PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, |
| 119 PP_GRAPHICS3DATTRIB_BLUE_SIZE, 8, | 133 PP_GRAPHICS3DATTRIB_BLUE_SIZE, 8, |
| 120 PP_GRAPHICS3DATTRIB_GREEN_SIZE, 8, | 134 PP_GRAPHICS3DATTRIB_GREEN_SIZE, 8, |
| 121 PP_GRAPHICS3DATTRIB_RED_SIZE, 8, | 135 PP_GRAPHICS3DATTRIB_RED_SIZE, 8, |
| 122 PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 0, | 136 PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 0, |
| 123 PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 0, | 137 PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 0, |
| 124 PP_GRAPHICS3DATTRIB_SAMPLES, 0, | 138 PP_GRAPHICS3DATTRIB_SAMPLES, 0, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 -1, -1, -1, 1, 1, -1, 1, 1, // Position coordinates. | 174 -1, -1, -1, 1, 1, -1, 1, 1, // Position coordinates. |
| 161 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates. | 175 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates. |
| 162 }; | 176 }; |
| 163 | 177 |
| 164 GLuint buffer; | 178 GLuint buffer; |
| 165 gles2_if_->GenBuffers(graphics_3d, 1, &buffer); | 179 gles2_if_->GenBuffers(graphics_3d, 1, &buffer); |
| 166 gles2_if_->BindBuffer(graphics_3d, GL_ARRAY_BUFFER, buffer); | 180 gles2_if_->BindBuffer(graphics_3d, GL_ARRAY_BUFFER, buffer); |
| 167 gles2_if_->BufferData(graphics_3d, GL_ARRAY_BUFFER, sizeof(kVertices), | 181 gles2_if_->BufferData(graphics_3d, GL_ARRAY_BUFFER, sizeof(kVertices), |
| 168 kVertices, GL_STATIC_DRAW); | 182 kVertices, GL_STATIC_DRAW); |
| 169 | 183 |
| 184 gles2_if_->GetIntegerv( | |
| 185 graphics_3d, GL_MAX_TEXTURE_SIZE, &gl_limits_.texture_size); | |
| 186 gles2_if_->GetIntegerv( | |
| 187 graphics_3d, GL_MAX_VIEWPORT_DIMS, gl_limits_.viewport_size); | |
| 188 | |
| 170 CheckGLError(); | 189 CheckGLError(); |
| 171 | 190 |
| 172 return true; | 191 return true; |
| 173 } | 192 } |
| 174 | 193 |
| 175 void PepperVideoRenderer3D::OnSessionConfig( | 194 void PepperVideoRenderer3D::OnSessionConfig( |
| 176 const protocol::SessionConfig& config) { | 195 const protocol::SessionConfig& config) { |
| 196 fallback_renderer_.OnSessionConfig(config); | |
| 197 | |
| 177 PP_VideoProfile video_profile = PP_VIDEOPROFILE_VP8_ANY; | 198 PP_VideoProfile video_profile = PP_VIDEOPROFILE_VP8_ANY; |
| 178 switch (config.video_config().codec) { | 199 switch (config.video_config().codec) { |
| 179 case protocol::ChannelConfig::CODEC_VP8: | 200 case protocol::ChannelConfig::CODEC_VP8: |
| 180 video_profile = PP_VIDEOPROFILE_VP8_ANY; | 201 video_profile = PP_VIDEOPROFILE_VP8_ANY; |
| 181 break; | 202 break; |
| 182 case protocol::ChannelConfig::CODEC_VP9: | 203 case protocol::ChannelConfig::CODEC_VP9: |
| 183 video_profile = PP_VIDEOPROFILE_VP9_ANY; | 204 video_profile = PP_VIDEOPROFILE_VP9_ANY; |
| 184 break; | 205 break; |
| 185 default: | 206 default: |
| 186 NOTREACHED(); | 207 NOTREACHED(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 205 return nullptr; | 226 return nullptr; |
| 206 } | 227 } |
| 207 | 228 |
| 208 protocol::FrameStatsConsumer* PepperVideoRenderer3D::GetFrameStatsConsumer() { | 229 protocol::FrameStatsConsumer* PepperVideoRenderer3D::GetFrameStatsConsumer() { |
| 209 return stats_consumer_; | 230 return stats_consumer_; |
| 210 } | 231 } |
| 211 | 232 |
| 212 void PepperVideoRenderer3D::ProcessVideoPacket( | 233 void PepperVideoRenderer3D::ProcessVideoPacket( |
| 213 std::unique_ptr<VideoPacket> packet, | 234 std::unique_ptr<VideoPacket> packet, |
| 214 const base::Closure& done) { | 235 const base::Closure& done) { |
| 236 if (!use_fallback_renderer_) { | |
| 237 use_fallback_renderer_ = | |
| 238 packet->format().has_screen_width() && | |
| 239 packet->format().has_screen_height() && | |
| 240 (packet->format().screen_width() > gl_scaled_limits_.texture_size || | |
|
Sergey Ulanov
2016/10/12 21:53:31
We only want to initialize fallback when resolutio
Hzj_jie
2016/10/12 23:42:46
Sorry, I cannot quite get the point of your commen
| |
| 241 packet->format().screen_height() > gl_scaled_limits_.texture_size || | |
| 242 packet->format().screen_width() > gl_scaled_limits_.viewport_size[0] || | |
|
Sergey Ulanov
2016/10/12 21:53:31
It seems strange to compare host screen size with
Hzj_jie
2016/10/12 23:42:46
Have I made a misunderstanding here? I believe the
| |
| 243 packet->format().screen_height() > gl_scaled_limits_.viewport_size[1]); | |
| 244 if (use_fallback_renderer_) { | |
|
Sergey Ulanov
2016/10/12 21:53:31
It would be easier to understand this code if it w
Hzj_jie
2016/10/12 23:42:46
Done.
| |
| 245 // Clear current instance and use fallback_renderer_. | |
| 246 current_picture_frames_.clear(); | |
| 247 current_picture_.reset(); | |
| 248 next_picture_frames_.clear(); | |
| 249 next_picture_.reset(); | |
| 250 decoded_frames_.clear(); | |
| 251 pending_frames_.clear(); | |
| 252 graphics_ = pp::Graphics3D(); | |
| 253 video_decoder_ = pp::VideoDecoder(); | |
| 254 } | |
| 255 } | |
| 256 | |
| 257 if (use_fallback_renderer_) { | |
| 258 fallback_renderer_.GetVideoStub()->ProcessVideoPacket( | |
| 259 std::move(packet), done); | |
| 260 return; | |
| 261 } | |
| 262 | |
| 215 VideoPacket* packet_ptr = packet.get(); | 263 VideoPacket* packet_ptr = packet.get(); |
| 216 std::unique_ptr<FrameTracker> frame_tracker( | 264 std::unique_ptr<FrameTracker> frame_tracker( |
| 217 new FrameTracker(std::move(packet), stats_consumer_, done)); | 265 new FrameTracker(std::move(packet), stats_consumer_, done)); |
| 218 | 266 |
| 219 // Don't need to do anything if the packet is empty. Host sends empty video | 267 // Don't need to do anything if the packet is empty. Host sends empty video |
| 220 // packets when the screen is not changing. | 268 // packets when the screen is not changing. |
| 221 if (packet_ptr->data().empty()) | 269 if (packet_ptr->data().empty()) |
| 222 return; | 270 return; |
| 223 | 271 |
| 224 if (!frame_received_) { | 272 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); | 578 gles2_if_->AttachShader(graphics_.pp_resource(), shader_program_, shader); |
| 531 gles2_if_->DeleteShader(graphics_.pp_resource(), shader); | 579 gles2_if_->DeleteShader(graphics_.pp_resource(), shader); |
| 532 } | 580 } |
| 533 | 581 |
| 534 void PepperVideoRenderer3D::CheckGLError() { | 582 void PepperVideoRenderer3D::CheckGLError() { |
| 535 GLenum error = gles2_if_->GetError(graphics_.pp_resource()); | 583 GLenum error = gles2_if_->GetError(graphics_.pp_resource()); |
| 536 CHECK_EQ(error, static_cast<GLenum>(GL_NO_ERROR)) << "GL error: " << error; | 584 CHECK_EQ(error, static_cast<GLenum>(GL_NO_ERROR)) << "GL error: " << error; |
| 537 } | 585 } |
| 538 | 586 |
| 539 } // namespace remoting | 587 } // namespace remoting |
| OLD | NEW |