| 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 30 matching lines...) Expand all Loading... |
| 41 GLenum type, | 41 GLenum type, |
| 42 const char* source, | 42 const char* source, |
| 43 int size) { | 43 int size) { |
| 44 GLuint shader = glCreateShader(type); | 44 GLuint shader = glCreateShader(type); |
| 45 glShaderSource(shader, 1, &source, &size); | 45 glShaderSource(shader, 1, &source, &size); |
| 46 glCompileShader(shader); | 46 glCompileShader(shader); |
| 47 int result = GL_FALSE; | 47 int result = GL_FALSE; |
| 48 glGetShaderiv(shader, GL_COMPILE_STATUS, &result); | 48 glGetShaderiv(shader, GL_COMPILE_STATUS, &result); |
| 49 if (!result) { | 49 if (!result) { |
| 50 char log[4096]; | 50 char log[4096]; |
| 51 glGetShaderInfoLog(shader, arraysize(log), NULL, log); | 51 glGetShaderInfoLog(shader, arraysize(log), nullptr, 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() {} |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 screen_size_ = | 128 screen_size_ = |
| 129 gfx::Size(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); | 129 gfx::Size(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); |
| 130 window_ = CreateWindowEx(0, | 130 window_ = CreateWindowEx(0, |
| 131 L"Static", | 131 L"Static", |
| 132 L"VideoDecodeAcceleratorTest", | 132 L"VideoDecodeAcceleratorTest", |
| 133 WS_OVERLAPPEDWINDOW | WS_VISIBLE, | 133 WS_OVERLAPPEDWINDOW | WS_VISIBLE, |
| 134 0, | 134 0, |
| 135 0, | 135 0, |
| 136 screen_size_.width(), | 136 screen_size_.width(), |
| 137 screen_size_.height(), | 137 screen_size_.height(), |
| 138 NULL, | 138 nullptr, |
| 139 NULL, | 139 nullptr, |
| 140 NULL, | 140 nullptr, |
| 141 NULL); | 141 nullptr); |
| 142 #elif defined(USE_X11) | 142 #elif defined(USE_X11) |
| 143 Display* display = gfx::GetXDisplay(); | 143 Display* display = gfx::GetXDisplay(); |
| 144 Screen* screen = DefaultScreenOfDisplay(display); | 144 Screen* screen = DefaultScreenOfDisplay(display); |
| 145 screen_size_ = gfx::Size(XWidthOfScreen(screen), XHeightOfScreen(screen)); | 145 screen_size_ = gfx::Size(XWidthOfScreen(screen), XHeightOfScreen(screen)); |
| 146 | 146 |
| 147 CHECK(display); | 147 CHECK(display); |
| 148 | 148 |
| 149 XSetWindowAttributes window_attributes; | 149 XSetWindowAttributes window_attributes; |
| 150 memset(&window_attributes, 0, sizeof(window_attributes)); | 150 memset(&window_attributes, 0, sizeof(window_attributes)); |
| 151 window_attributes.background_pixel = | 151 window_attributes.background_pixel = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 168 XStoreName(display, window_, "VideoDecodeAcceleratorTest"); | 168 XStoreName(display, window_, "VideoDecodeAcceleratorTest"); |
| 169 XSelectInput(display, window_, ExposureMask); | 169 XSelectInput(display, window_, ExposureMask); |
| 170 XMapWindow(display, window_); | 170 XMapWindow(display, window_); |
| 171 #else | 171 #else |
| 172 #error unknown platform | 172 #error unknown platform |
| 173 #endif | 173 #endif |
| 174 CHECK(window_ != gfx::kNullAcceleratedWidget); | 174 CHECK(window_ != gfx::kNullAcceleratedWidget); |
| 175 | 175 |
| 176 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_); | 176 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_); |
| 177 gl_context_ = gfx::GLContext::CreateGLContext( | 177 gl_context_ = gfx::GLContext::CreateGLContext( |
| 178 NULL, gl_surface_.get(), gfx::PreferIntegratedGpu); | 178 nullptr, gl_surface_.get(), gfx::PreferIntegratedGpu); |
| 179 gl_context_->MakeCurrent(gl_surface_.get()); | 179 gl_context_->MakeCurrent(gl_surface_.get()); |
| 180 | 180 |
| 181 CHECK_GT(params.window_sizes.size(), 0U); | 181 CHECK_GT(params.window_sizes.size(), 0U); |
| 182 videos_.resize(params.window_sizes.size()); | 182 videos_.resize(params.window_sizes.size()); |
| 183 LayoutRenderingAreas(params.window_sizes); | 183 LayoutRenderingAreas(params.window_sizes); |
| 184 | 184 |
| 185 if (render_as_thumbnails_) { | 185 if (render_as_thumbnails_) { |
| 186 CHECK_EQ(videos_.size(), 1U); | 186 CHECK_EQ(videos_.size(), 1U); |
| 187 | 187 |
| 188 GLint max_texture_size; | 188 GLint max_texture_size; |
| 189 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); | 189 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); |
| 190 CHECK_GE(max_texture_size, params.thumbnails_page_size.width()); | 190 CHECK_GE(max_texture_size, params.thumbnails_page_size.width()); |
| 191 CHECK_GE(max_texture_size, params.thumbnails_page_size.height()); | 191 CHECK_GE(max_texture_size, params.thumbnails_page_size.height()); |
| 192 | 192 |
| 193 thumbnails_fbo_size_ = params.thumbnails_page_size; | 193 thumbnails_fbo_size_ = params.thumbnails_page_size; |
| 194 thumbnail_size_ = params.thumbnail_size; | 194 thumbnail_size_ = params.thumbnail_size; |
| 195 | 195 |
| 196 glGenFramebuffersEXT(1, &thumbnails_fbo_id_); | 196 glGenFramebuffersEXT(1, &thumbnails_fbo_id_); |
| 197 glGenTextures(1, &thumbnails_texture_id_); | 197 glGenTextures(1, &thumbnails_texture_id_); |
| 198 glBindTexture(GL_TEXTURE_2D, thumbnails_texture_id_); | 198 glBindTexture(GL_TEXTURE_2D, thumbnails_texture_id_); |
| 199 glTexImage2D(GL_TEXTURE_2D, | 199 glTexImage2D(GL_TEXTURE_2D, |
| 200 0, | 200 0, |
| 201 GL_RGB, | 201 GL_RGB, |
| 202 thumbnails_fbo_size_.width(), | 202 thumbnails_fbo_size_.width(), |
| 203 thumbnails_fbo_size_.height(), | 203 thumbnails_fbo_size_.height(), |
| 204 0, | 204 0, |
| 205 GL_RGB, | 205 GL_RGB, |
| 206 GL_UNSIGNED_SHORT_5_6_5, | 206 GL_UNSIGNED_SHORT_5_6_5, |
| 207 NULL); | 207 nullptr); |
| 208 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 208 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 209 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 209 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 210 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 210 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 211 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 211 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 212 glBindTexture(GL_TEXTURE_2D, 0); | 212 glBindTexture(GL_TEXTURE_2D, 0); |
| 213 | 213 |
| 214 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); | 214 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); |
| 215 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 215 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| 216 GL_COLOR_ATTACHMENT0, | 216 GL_COLOR_ATTACHMENT0, |
| 217 GL_TEXTURE_2D, | 217 GL_TEXTURE_2D, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 program_, GL_VERTEX_SHADER, kVertexShader, arraysize(kVertexShader)); | 276 program_, GL_VERTEX_SHADER, kVertexShader, arraysize(kVertexShader)); |
| 277 CreateShader(program_, | 277 CreateShader(program_, |
| 278 GL_FRAGMENT_SHADER, | 278 GL_FRAGMENT_SHADER, |
| 279 kFragmentShader, | 279 kFragmentShader, |
| 280 arraysize(kFragmentShader)); | 280 arraysize(kFragmentShader)); |
| 281 glLinkProgram(program_); | 281 glLinkProgram(program_); |
| 282 int result = GL_FALSE; | 282 int result = GL_FALSE; |
| 283 glGetProgramiv(program_, GL_LINK_STATUS, &result); | 283 glGetProgramiv(program_, GL_LINK_STATUS, &result); |
| 284 if (!result) { | 284 if (!result) { |
| 285 char log[4096]; | 285 char log[4096]; |
| 286 glGetShaderInfoLog(program_, arraysize(log), NULL, log); | 286 glGetShaderInfoLog(program_, arraysize(log), nullptr, log); |
| 287 LOG(FATAL) << log; | 287 LOG(FATAL) << log; |
| 288 } | 288 } |
| 289 glUseProgram(program_); | 289 glUseProgram(program_); |
| 290 glDeleteProgram(program_); | 290 glDeleteProgram(program_); |
| 291 | 291 |
| 292 glUniform1i(glGetUniformLocation(program_, "tex_flip"), 0); | 292 glUniform1i(glGetUniformLocation(program_, "tex_flip"), 0); |
| 293 glUniform1i(glGetUniformLocation(program_, "tex"), 0); | 293 glUniform1i(glGetUniformLocation(program_, "tex"), 0); |
| 294 GLint tex_external = glGetUniformLocation(program_, "tex_external"); | 294 GLint tex_external = glGetUniformLocation(program_, "tex_external"); |
| 295 if (tex_external != -1) { | 295 if (tex_external != -1) { |
| 296 glUniform1i(tex_external, 1); | 296 glUniform1i(tex_external, 1); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 309 CHECK_EQ(base::MessageLoop::current(), message_loop_); | 309 CHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 310 | 310 |
| 311 render_task_.Cancel(); | 311 render_task_.Cancel(); |
| 312 | 312 |
| 313 if (render_as_thumbnails_) { | 313 if (render_as_thumbnails_) { |
| 314 glDeleteTextures(1, &thumbnails_texture_id_); | 314 glDeleteTextures(1, &thumbnails_texture_id_); |
| 315 glDeleteFramebuffersEXT(1, &thumbnails_fbo_id_); | 315 glDeleteFramebuffersEXT(1, &thumbnails_fbo_id_); |
| 316 } | 316 } |
| 317 | 317 |
| 318 gl_context_->ReleaseCurrent(gl_surface_.get()); | 318 gl_context_->ReleaseCurrent(gl_surface_.get()); |
| 319 gl_context_ = NULL; | 319 gl_context_ = nullptr; |
| 320 gl_surface_ = NULL; | 320 gl_surface_ = nullptr; |
| 321 | 321 |
| 322 Clear(); | 322 Clear(); |
| 323 done->Signal(); | 323 done->Signal(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void RenderingHelper::CreateTexture(uint32 texture_target, | 326 void RenderingHelper::CreateTexture(uint32 texture_target, |
| 327 uint32* texture_id, | 327 uint32* texture_id, |
| 328 const gfx::Size& size, | 328 const gfx::Size& size, |
| 329 base::WaitableEvent* done) { | 329 base::WaitableEvent* done) { |
| 330 if (base::MessageLoop::current() != message_loop_) { | 330 if (base::MessageLoop::current() != message_loop_) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 341 glBindTexture(texture_target, *texture_id); | 341 glBindTexture(texture_target, *texture_id); |
| 342 if (texture_target == GL_TEXTURE_2D) { | 342 if (texture_target == GL_TEXTURE_2D) { |
| 343 glTexImage2D(GL_TEXTURE_2D, | 343 glTexImage2D(GL_TEXTURE_2D, |
| 344 0, | 344 0, |
| 345 GL_RGBA, | 345 GL_RGBA, |
| 346 size.width(), | 346 size.width(), |
| 347 size.height(), | 347 size.height(), |
| 348 0, | 348 0, |
| 349 GL_RGBA, | 349 GL_RGBA, |
| 350 GL_UNSIGNED_BYTE, | 350 GL_UNSIGNED_BYTE, |
| 351 NULL); | 351 nullptr); |
| 352 } | 352 } |
| 353 glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 353 glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 354 glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 354 glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 355 // OpenGLES2.0.25 section 3.8.2 requires CLAMP_TO_EDGE for NPOT textures. | 355 // OpenGLES2.0.25 section 3.8.2 requires CLAMP_TO_EDGE for NPOT textures. |
| 356 glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 356 glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 357 glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 357 glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 358 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); | 358 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); |
| 359 done->Signal(); | 359 done->Signal(); |
| 360 } | 360 } |
| 361 | 361 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 void* RenderingHelper::GetGLContext() { | 443 void* RenderingHelper::GetGLContext() { |
| 444 return gl_context_->GetHandle(); | 444 return gl_context_->GetHandle(); |
| 445 } | 445 } |
| 446 | 446 |
| 447 void* RenderingHelper::GetGLDisplay() { | 447 void* RenderingHelper::GetGLDisplay() { |
| 448 return gl_surface_->GetDisplay(); | 448 return gl_surface_->GetDisplay(); |
| 449 } | 449 } |
| 450 | 450 |
| 451 void RenderingHelper::Clear() { | 451 void RenderingHelper::Clear() { |
| 452 videos_.clear(); | 452 videos_.clear(); |
| 453 message_loop_ = NULL; | 453 message_loop_ = nullptr; |
| 454 gl_context_ = NULL; | 454 gl_context_ = nullptr; |
| 455 gl_surface_ = NULL; | 455 gl_surface_ = nullptr; |
| 456 | 456 |
| 457 render_as_thumbnails_ = false; | 457 render_as_thumbnails_ = false; |
| 458 frame_count_ = 0; | 458 frame_count_ = 0; |
| 459 thumbnails_fbo_id_ = 0; | 459 thumbnails_fbo_id_ = 0; |
| 460 thumbnails_texture_id_ = 0; | 460 thumbnails_texture_id_ = 0; |
| 461 | 461 |
| 462 #if defined(OS_WIN) | 462 #if defined(OS_WIN) |
| 463 if (window_) | 463 if (window_) |
| 464 DestroyWindow(window_); | 464 DestroyWindow(window_); |
| 465 #else | 465 #else |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 scale = std::min(1.0f, scale); | 604 scale = std::min(1.0f, scale); |
| 605 | 605 |
| 606 size_t w = scale * size.width(); | 606 size_t w = scale * size.width(); |
| 607 size_t h = scale * size.height(); | 607 size_t h = scale * size.height(); |
| 608 size_t x = offset_x[i % cols] + (widths[i % cols] - w) / 2; | 608 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; | 609 size_t y = offset_y[i / cols] + (heights[i / cols] - h) / 2; |
| 610 videos_[i].render_area = gfx::Rect(x, y, w, h); | 610 videos_[i].render_area = gfx::Rect(x, y, w, h); |
| 611 } | 611 } |
| 612 } | 612 } |
| 613 } // namespace content | 613 } // namespace content |
| OLD | NEW |