OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/common/gpu/media/rendering_helper.h" | 5 #include "content/common/gpu/media/rendering_helper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <numeric> | 8 #include <numeric> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 glGetShaderInfoLog(shader, arraysize(log), NULL, log); | 51 glGetShaderInfoLog(shader, arraysize(log), NULL, log); |
52 LOG(FATAL) << log; | 52 LOG(FATAL) << log; |
53 } | 53 } |
54 glAttachShader(program, shader); | 54 glAttachShader(program, shader); |
55 glDeleteShader(shader); | 55 glDeleteShader(shader); |
56 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); | 56 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); |
57 } | 57 } |
58 | 58 |
59 namespace content { | 59 namespace content { |
60 | 60 |
61 RenderingHelperParams::RenderingHelperParams() {} | 61 RenderingHelperParams::RenderingHelperParams() |
| 62 : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) { |
| 63 } |
62 | 64 |
63 RenderingHelperParams::~RenderingHelperParams() {} | 65 RenderingHelperParams::~RenderingHelperParams() {} |
64 | 66 |
65 VideoFrameTexture::VideoFrameTexture(uint32 texture_target, | 67 VideoFrameTexture::VideoFrameTexture(uint32 texture_target, |
66 uint32 texture_id, | 68 uint32 texture_id, |
67 const base::Closure& no_longer_needed_cb) | 69 const base::Closure& no_longer_needed_cb) |
68 : texture_target_(texture_target), | 70 : texture_target_(texture_target), |
69 texture_id_(texture_id), | 71 texture_id_(texture_id), |
70 no_longer_needed_cb_(no_longer_needed_cb) { | 72 no_longer_needed_cb_(no_longer_needed_cb) { |
71 DCHECK(!no_longer_needed_cb_.is_null()); | 73 DCHECK(!no_longer_needed_cb_.is_null()); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 if (tex_external != -1) { | 297 if (tex_external != -1) { |
296 glUniform1i(tex_external, 1); | 298 glUniform1i(tex_external, 1); |
297 } | 299 } |
298 int pos_location = glGetAttribLocation(program_, "in_pos"); | 300 int pos_location = glGetAttribLocation(program_, "in_pos"); |
299 glEnableVertexAttribArray(pos_location); | 301 glEnableVertexAttribArray(pos_location); |
300 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); | 302 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); |
301 int tc_location = glGetAttribLocation(program_, "in_tc"); | 303 int tc_location = glGetAttribLocation(program_, "in_tc"); |
302 glEnableVertexAttribArray(tc_location); | 304 glEnableVertexAttribArray(tc_location); |
303 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, kTextureCoords); | 305 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, kTextureCoords); |
304 | 306 |
| 307 if (frame_duration_ != base::TimeDelta()) |
| 308 WarmUpRendering(params.warm_up_iterations); |
| 309 |
305 done->Signal(); | 310 done->Signal(); |
306 } | 311 } |
307 | 312 |
| 313 // The rendering for the first few frames is slow (e.g., 100ms on Peach Pit). |
| 314 // This affects the numbers measured in the performance test. We try to render |
| 315 // several frames here to warm up the rendering. |
| 316 void RenderingHelper::WarmUpRendering(int warm_up_iterations) { |
| 317 unsigned int texture_id; |
| 318 scoped_ptr<GLubyte[]> emptyData(new GLubyte[screen_size_.GetArea() * 2]); |
| 319 glGenTextures(1, &texture_id); |
| 320 glBindTexture(GL_TEXTURE_2D, texture_id); |
| 321 glTexImage2D(GL_TEXTURE_2D, |
| 322 0, |
| 323 GL_RGB, |
| 324 screen_size_.width(), |
| 325 screen_size_.height(), |
| 326 0, |
| 327 GL_RGB, |
| 328 GL_UNSIGNED_SHORT_5_6_5, |
| 329 emptyData.get()); |
| 330 for (int i = 0; i < warm_up_iterations; ++i) { |
| 331 RenderTexture(GL_TEXTURE_2D, texture_id); |
| 332 gl_surface_->SwapBuffers(); |
| 333 } |
| 334 glDeleteTextures(1, &texture_id); |
| 335 } |
| 336 |
308 void RenderingHelper::UnInitialize(base::WaitableEvent* done) { | 337 void RenderingHelper::UnInitialize(base::WaitableEvent* done) { |
309 CHECK_EQ(base::MessageLoop::current(), message_loop_); | 338 CHECK_EQ(base::MessageLoop::current(), message_loop_); |
310 | 339 |
311 render_task_.Cancel(); | 340 render_task_.Cancel(); |
312 | 341 |
313 if (render_as_thumbnails_) { | 342 if (render_as_thumbnails_) { |
314 glDeleteTextures(1, &thumbnails_texture_id_); | 343 glDeleteTextures(1, &thumbnails_texture_id_); |
315 glDeleteFramebuffersEXT(1, &thumbnails_fbo_id_); | 344 glDeleteFramebuffersEXT(1, &thumbnails_fbo_id_); |
316 } | 345 } |
317 | 346 |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 scale = std::min(1.0f, scale); | 633 scale = std::min(1.0f, scale); |
605 | 634 |
606 size_t w = scale * size.width(); | 635 size_t w = scale * size.width(); |
607 size_t h = scale * size.height(); | 636 size_t h = scale * size.height(); |
608 size_t x = offset_x[i % cols] + (widths[i % cols] - w) / 2; | 637 size_t x = offset_x[i % cols] + (widths[i % cols] - w) / 2; |
609 size_t y = offset_y[i / cols] + (heights[i / cols] - h) / 2; | 638 size_t y = offset_y[i / cols] + (heights[i / cols] - h) / 2; |
610 videos_[i].render_area = gfx::Rect(x, y, w, h); | 639 videos_[i].render_area = gfx::Rect(x, y, w, h); |
611 } | 640 } |
612 } | 641 } |
613 } // namespace content | 642 } // namespace content |
OLD | NEW |