| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/android_deferred_rendering_backing_strategy.h
" | 5 #include "media/gpu/android_deferred_rendering_backing_strategy.h" |
| 6 | 6 |
| 7 #include <EGL/egl.h> | 7 #include <EGL/egl.h> |
| 8 #include <EGL/eglext.h> | 8 #include <EGL/eglext.h> |
| 9 | 9 |
| 10 #include "base/android/build_info.h" | 10 #include "base/android/build_info.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "content/common/gpu/media/avda_codec_image.h" | |
| 16 #include "content/common/gpu/media/avda_return_on_failure.h" | |
| 17 #include "content/common/gpu/media/avda_shared_state.h" | |
| 18 #include "gpu/command_buffer/service/context_group.h" | 15 #include "gpu/command_buffer/service/context_group.h" |
| 19 #include "gpu/command_buffer/service/gl_stream_texture_image.h" | 16 #include "gpu/command_buffer/service/gl_stream_texture_image.h" |
| 20 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" | 17 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
| 21 #include "gpu/command_buffer/service/texture_manager.h" | 18 #include "gpu/command_buffer/service/texture_manager.h" |
| 22 #include "gpu/ipc/common/gpu_surface_lookup.h" | 19 #include "gpu/ipc/common/gpu_surface_lookup.h" |
| 23 #include "gpu/ipc/service/gpu_channel.h" | 20 #include "gpu/ipc/service/gpu_channel.h" |
| 21 #include "media/gpu/avda_codec_image.h" |
| 22 #include "media/gpu/avda_return_on_failure.h" |
| 23 #include "media/gpu/avda_shared_state.h" |
| 24 #include "ui/gl/android/surface_texture.h" | 24 #include "ui/gl/android/surface_texture.h" |
| 25 #include "ui/gl/egl_util.h" | 25 #include "ui/gl/egl_util.h" |
| 26 #include "ui/gl/gl_bindings.h" | 26 #include "ui/gl/gl_bindings.h" |
| 27 #include "ui/gl/gl_surface_egl.h" | 27 #include "ui/gl/gl_surface_egl.h" |
| 28 #include "ui/gl/scoped_binders.h" | 28 #include "ui/gl/scoped_binders.h" |
| 29 #include "ui/gl/scoped_make_current.h" | 29 #include "ui/gl/scoped_make_current.h" |
| 30 | 30 |
| 31 namespace content { | 31 namespace media { |
| 32 | 32 |
| 33 AndroidDeferredRenderingBackingStrategy:: | 33 AndroidDeferredRenderingBackingStrategy:: |
| 34 AndroidDeferredRenderingBackingStrategy(AVDAStateProvider* state_provider) | 34 AndroidDeferredRenderingBackingStrategy(AVDAStateProvider* state_provider) |
| 35 : state_provider_(state_provider), media_codec_(nullptr) {} | 35 : state_provider_(state_provider), media_codec_(nullptr) {} |
| 36 | 36 |
| 37 AndroidDeferredRenderingBackingStrategy:: | 37 AndroidDeferredRenderingBackingStrategy:: |
| 38 ~AndroidDeferredRenderingBackingStrategy() {} | 38 ~AndroidDeferredRenderingBackingStrategy() {} |
| 39 | 39 |
| 40 gfx::ScopedJavaSurface AndroidDeferredRenderingBackingStrategy::Initialize( | 40 gfx::ScopedJavaSurface AndroidDeferredRenderingBackingStrategy::Initialize( |
| 41 int surface_view_id) { | 41 int surface_view_id) { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, tmp_texture_id); | 296 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, tmp_texture_id); |
| 297 // The target texture's size will exactly match the source. | 297 // The target texture's size will exactly match the source. |
| 298 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 298 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 299 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 299 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 300 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 300 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 301 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 301 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 302 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, | 302 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, |
| 303 GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | 303 GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 304 } | 304 } |
| 305 | 305 |
| 306 | |
| 307 | |
| 308 float transform_matrix[16]; | 306 float transform_matrix[16]; |
| 309 surface_texture_->GetTransformMatrix(transform_matrix); | 307 surface_texture_->GetTransformMatrix(transform_matrix); |
| 310 | 308 |
| 311 gpu::CopyTextureCHROMIUMResourceManager copier; | 309 gpu::CopyTextureCHROMIUMResourceManager copier; |
| 312 copier.Initialize( | 310 copier.Initialize( |
| 313 gl_decoder, | 311 gl_decoder, |
| 314 gl_decoder->GetContextGroup()->feature_info()->feature_flags()); | 312 gl_decoder->GetContextGroup()->feature_info()->feature_flags()); |
| 315 copier.DoCopyTextureWithTransform(gl_decoder, GL_TEXTURE_EXTERNAL_OES, | 313 copier.DoCopyTextureWithTransform(gl_decoder, GL_TEXTURE_EXTERNAL_OES, |
| 316 shared_state_->surface_texture_service_id(), | 314 shared_state_->surface_texture_service_id(), |
| 317 GL_TEXTURE_2D, tmp_texture_id, size.width(), | 315 GL_TEXTURE_2D, tmp_texture_id, size.width(), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 341 continue; | 339 continue; |
| 342 gfx::ScopedTextureBinder texture_binder( | 340 gfx::ScopedTextureBinder texture_binder( |
| 343 GL_TEXTURE_EXTERNAL_OES, texture_ref->texture()->service_id()); | 341 GL_TEXTURE_EXTERNAL_OES, texture_ref->texture()->service_id()); |
| 344 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image); | 342 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image); |
| 345 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 343 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 346 } | 344 } |
| 347 | 345 |
| 348 EGLBoolean result = | 346 EGLBoolean result = |
| 349 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), egl_image); | 347 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), egl_image); |
| 350 if (result == EGL_FALSE) { | 348 if (result == EGL_FALSE) { |
| 351 DLOG(ERROR) << "Error destroying EGLImage: " | 349 DLOG(ERROR) << "Error destroying EGLImage: " << ui::GetLastEGLErrorString(); |
| 352 << ui::GetLastEGLErrorString(); | |
| 353 } | 350 } |
| 354 } | 351 } |
| 355 | 352 |
| 356 bool AndroidDeferredRenderingBackingStrategy::DoesSurfaceTextureDetachWork() | 353 bool AndroidDeferredRenderingBackingStrategy::DoesSurfaceTextureDetachWork() |
| 357 const { | 354 const { |
| 358 bool surface_texture_detach_works = true; | 355 bool surface_texture_detach_works = true; |
| 359 if (gpu::gles2::GLES2Decoder* gl_decoder = | 356 if (gpu::gles2::GLES2Decoder* gl_decoder = |
| 360 state_provider_->GetGlDecoder().get()) { | 357 state_provider_->GetGlDecoder().get()) { |
| 361 if (gpu::gles2::ContextGroup* group = gl_decoder->GetContextGroup()) { | 358 if (gpu::gles2::ContextGroup* group = gl_decoder->GetContextGroup()) { |
| 362 if (gpu::gles2::FeatureInfo* feature_info = group->feature_info()) { | 359 if (gpu::gles2::FeatureInfo* feature_info = group->feature_info()) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 380 } | 377 } |
| 381 } | 378 } |
| 382 | 379 |
| 383 return surface_texture_detach_works; | 380 return surface_texture_detach_works; |
| 384 } | 381 } |
| 385 | 382 |
| 386 bool AndroidDeferredRenderingBackingStrategy::ShouldCopyPictures() const { | 383 bool AndroidDeferredRenderingBackingStrategy::ShouldCopyPictures() const { |
| 387 // Mali + <= KitKat crashes when we try to do this. We don't know if it's | 384 // Mali + <= KitKat crashes when we try to do this. We don't know if it's |
| 388 // due to detaching a surface texture, but it's the same set of devices. | 385 // due to detaching a surface texture, but it's the same set of devices. |
| 389 if (!DoesSurfaceTextureDetachWork()) | 386 if (!DoesSurfaceTextureDetachWork()) |
| 390 return false; | 387 return false; |
| 391 | 388 |
| 392 // Other devices are unreliable for other reasons (e.g., EGLImage). | 389 // Other devices are unreliable for other reasons (e.g., EGLImage). |
| 393 if (gpu::gles2::GLES2Decoder* gl_decoder = | 390 if (gpu::gles2::GLES2Decoder* gl_decoder = |
| 394 state_provider_->GetGlDecoder().get()) { | 391 state_provider_->GetGlDecoder().get()) { |
| 395 if (gpu::gles2::ContextGroup* group = gl_decoder->GetContextGroup()) { | 392 if (gpu::gles2::ContextGroup* group = gl_decoder->GetContextGroup()) { |
| 396 if (gpu::gles2::FeatureInfo* feature_info = group->feature_info()) { | 393 if (gpu::gles2::FeatureInfo* feature_info = group->feature_info()) { |
| 397 return !feature_info->workarounds().avda_dont_copy_pictures; | 394 return !feature_info->workarounds().avda_dont_copy_pictures; |
| 398 } | 395 } |
| 399 } | 396 } |
| 400 } | 397 } |
| 401 | 398 |
| 402 // Assume so. | 399 // Assume so. |
| 403 return true; | 400 return true; |
| 404 } | 401 } |
| 405 | 402 |
| 406 } // namespace content | 403 } // namespace media |
| OLD | NEW |