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(); |
101 view_size_.set(ceilf(size.width() * scale), ceilf(size.height() * scale)); | 105 DCHECK(scale > 0); |
Sergey Ulanov
2016/10/17 20:02:44
nit: DCHECK_GT(scale, 0.0);
Hzj_jie
2016/10/17 22:55:42
Done.
| |
106 view_size_.set(std::min<float>(ceilf(size.width() * scale), | |
Sergey Ulanov
2016/10/17 20:02:44
I think it's better to use std::min<int> here and
Hzj_jie
2016/10/17 22:55:43
Done.
| |
107 gl_limits_.viewport_size[0]), | |
108 std::min<float>(ceilf(size.height() * scale), | |
109 gl_limits_.viewport_size[1])); | |
102 graphics_.ResizeBuffers(view_size_.width(), view_size_.height()); | 110 graphics_.ResizeBuffers(view_size_.width(), view_size_.height()); |
103 | 111 |
104 force_repaint_ = true; | 112 force_repaint_ = true; |
105 PaintIfNeeded(); | 113 PaintIfNeeded(); |
106 } | 114 } |
107 | 115 |
108 void PepperVideoRenderer3D::EnableDebugDirtyRegion(bool enable) { | 116 void PepperVideoRenderer3D::EnableDebugDirtyRegion(bool enable) { |
117 fallback_renderer_.EnableDebugDirtyRegion(enable); | |
109 debug_dirty_region_ = enable; | 118 debug_dirty_region_ = enable; |
110 } | 119 } |
111 | 120 |
112 bool PepperVideoRenderer3D::Initialize( | 121 bool PepperVideoRenderer3D::Initialize( |
113 const ClientContext& context, | 122 const ClientContext& context, |
114 protocol::FrameStatsConsumer* stats_consumer) { | 123 protocol::FrameStatsConsumer* stats_consumer) { |
124 if (!fallback_renderer_.Initialize(context, stats_consumer)) { | |
125 LOG(FATAL) << "Failed to initialize fallback_renderer_"; | |
126 } | |
127 | |
115 stats_consumer_ = stats_consumer; | 128 stats_consumer_ = stats_consumer; |
116 | 129 |
117 const int32_t context_attributes[] = { | 130 const int32_t context_attributes[] = { |
118 PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, | 131 PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, |
119 PP_GRAPHICS3DATTRIB_BLUE_SIZE, 8, | 132 PP_GRAPHICS3DATTRIB_BLUE_SIZE, 8, |
120 PP_GRAPHICS3DATTRIB_GREEN_SIZE, 8, | 133 PP_GRAPHICS3DATTRIB_GREEN_SIZE, 8, |
121 PP_GRAPHICS3DATTRIB_RED_SIZE, 8, | 134 PP_GRAPHICS3DATTRIB_RED_SIZE, 8, |
122 PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 0, | 135 PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 0, |
123 PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 0, | 136 PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 0, |
124 PP_GRAPHICS3DATTRIB_SAMPLES, 0, | 137 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. | 173 -1, -1, -1, 1, 1, -1, 1, 1, // Position coordinates. |
161 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates. | 174 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates. |
162 }; | 175 }; |
163 | 176 |
164 GLuint buffer; | 177 GLuint buffer; |
165 gles2_if_->GenBuffers(graphics_3d, 1, &buffer); | 178 gles2_if_->GenBuffers(graphics_3d, 1, &buffer); |
166 gles2_if_->BindBuffer(graphics_3d, GL_ARRAY_BUFFER, buffer); | 179 gles2_if_->BindBuffer(graphics_3d, GL_ARRAY_BUFFER, buffer); |
167 gles2_if_->BufferData(graphics_3d, GL_ARRAY_BUFFER, sizeof(kVertices), | 180 gles2_if_->BufferData(graphics_3d, GL_ARRAY_BUFFER, sizeof(kVertices), |
168 kVertices, GL_STATIC_DRAW); | 181 kVertices, GL_STATIC_DRAW); |
169 | 182 |
183 gles2_if_->GetIntegerv( | |
184 graphics_3d, GL_MAX_TEXTURE_SIZE, &gl_limits_.texture_size); | |
185 gles2_if_->GetIntegerv( | |
186 graphics_3d, GL_MAX_VIEWPORT_DIMS, gl_limits_.viewport_size); | |
187 | |
170 CheckGLError(); | 188 CheckGLError(); |
171 | 189 |
172 return true; | 190 return true; |
173 } | 191 } |
174 | 192 |
175 void PepperVideoRenderer3D::OnSessionConfig( | 193 void PepperVideoRenderer3D::OnSessionConfig( |
176 const protocol::SessionConfig& config) { | 194 const protocol::SessionConfig& config) { |
195 fallback_renderer_.OnSessionConfig(config); | |
196 | |
177 PP_VideoProfile video_profile = PP_VIDEOPROFILE_VP8_ANY; | 197 PP_VideoProfile video_profile = PP_VIDEOPROFILE_VP8_ANY; |
178 switch (config.video_config().codec) { | 198 switch (config.video_config().codec) { |
179 case protocol::ChannelConfig::CODEC_VP8: | 199 case protocol::ChannelConfig::CODEC_VP8: |
180 video_profile = PP_VIDEOPROFILE_VP8_ANY; | 200 video_profile = PP_VIDEOPROFILE_VP8_ANY; |
181 break; | 201 break; |
182 case protocol::ChannelConfig::CODEC_VP9: | 202 case protocol::ChannelConfig::CODEC_VP9: |
183 video_profile = PP_VIDEOPROFILE_VP9_ANY; | 203 video_profile = PP_VIDEOPROFILE_VP9_ANY; |
184 break; | 204 break; |
185 default: | 205 default: |
186 NOTREACHED(); | 206 NOTREACHED(); |
(...skipping 18 matching lines...) Expand all Loading... | |
205 return nullptr; | 225 return nullptr; |
206 } | 226 } |
207 | 227 |
208 protocol::FrameStatsConsumer* PepperVideoRenderer3D::GetFrameStatsConsumer() { | 228 protocol::FrameStatsConsumer* PepperVideoRenderer3D::GetFrameStatsConsumer() { |
209 return stats_consumer_; | 229 return stats_consumer_; |
210 } | 230 } |
211 | 231 |
212 void PepperVideoRenderer3D::ProcessVideoPacket( | 232 void PepperVideoRenderer3D::ProcessVideoPacket( |
213 std::unique_ptr<VideoPacket> packet, | 233 std::unique_ptr<VideoPacket> packet, |
214 const base::Closure& done) { | 234 const base::Closure& done) { |
235 if (!use_fallback_renderer_ && | |
236 packet->format().has_screen_width() && | |
237 packet->format().has_screen_height() && | |
238 (packet->format().screen_width() > gl_limits_.texture_size || | |
239 packet->format().screen_height() > gl_limits_.texture_size)) { | |
Hzj_jie
2016/10/17 18:49:57
As we have talked offline, I do not think this fal
Sergey Ulanov
2016/10/17 20:02:44
I'm not sure what you mean here. Is your point tha
Hzj_jie
2016/10/17 22:55:43
Sorry, I mean pure software renderer as what we ha
Sergey Ulanov
2016/10/18 03:11:44
I see. Is it the same on on other client platforms
Hzj_jie
2016/10/18 19:05:58
Windows machines usually have a larger hardware li
| |
240 use_fallback_renderer_ = true; | |
241 // Clear current instance and use fallback_renderer_. | |
242 current_picture_frames_.clear(); | |
243 current_picture_.reset(); | |
244 next_picture_frames_.clear(); | |
245 next_picture_.reset(); | |
246 decoded_frames_.clear(); | |
247 pending_frames_.clear(); | |
248 graphics_ = pp::Graphics3D(); | |
249 video_decoder_ = pp::VideoDecoder(); | |
250 } | |
251 | |
252 if (use_fallback_renderer_) { | |
253 fallback_renderer_.GetVideoStub()->ProcessVideoPacket( | |
254 std::move(packet), done); | |
255 return; | |
256 } | |
257 | |
215 VideoPacket* packet_ptr = packet.get(); | 258 VideoPacket* packet_ptr = packet.get(); |
216 std::unique_ptr<FrameTracker> frame_tracker( | 259 std::unique_ptr<FrameTracker> frame_tracker( |
217 new FrameTracker(std::move(packet), stats_consumer_, done)); | 260 new FrameTracker(std::move(packet), stats_consumer_, done)); |
218 | 261 |
219 // Don't need to do anything if the packet is empty. Host sends empty video | 262 // Don't need to do anything if the packet is empty. Host sends empty video |
220 // packets when the screen is not changing. | 263 // packets when the screen is not changing. |
221 if (packet_ptr->data().empty()) | 264 if (packet_ptr->data().empty()) |
222 return; | 265 return; |
223 | 266 |
224 if (!frame_received_) { | 267 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); | 573 gles2_if_->AttachShader(graphics_.pp_resource(), shader_program_, shader); |
531 gles2_if_->DeleteShader(graphics_.pp_resource(), shader); | 574 gles2_if_->DeleteShader(graphics_.pp_resource(), shader); |
532 } | 575 } |
533 | 576 |
534 void PepperVideoRenderer3D::CheckGLError() { | 577 void PepperVideoRenderer3D::CheckGLError() { |
535 GLenum error = gles2_if_->GetError(graphics_.pp_resource()); | 578 GLenum error = gles2_if_->GetError(graphics_.pp_resource()); |
536 CHECK_EQ(error, static_cast<GLenum>(GL_NO_ERROR)) << "GL error: " << error; | 579 CHECK_EQ(error, static_cast<GLenum>(GL_NO_ERROR)) << "GL error: " << error; |
537 } | 580 } |
538 | 581 |
539 } // namespace remoting | 582 } // namespace remoting |
OLD | NEW |