| 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/avda_codec_image.h" | 5 #include "content/common/gpu/media/avda_codec_image.h" |
| 6 | 6 |
| 7 #include "content/common/gpu/media/avda_shared_state.h" | 7 #include "content/common/gpu/media/avda_shared_state.h" |
| 8 #include "gpu/command_buffer/service/context_group.h" |
| 8 #include "gpu/command_buffer/service/context_state.h" | 9 #include "gpu/command_buffer/service/context_state.h" |
| 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 10 #include "gpu/command_buffer/service/texture_manager.h" | 11 #include "gpu/command_buffer/service/texture_manager.h" |
| 11 #include "ui/gl/android/surface_texture.h" | 12 #include "ui/gl/android/surface_texture.h" |
| 12 #include "ui/gl/gl_context.h" | 13 #include "ui/gl/gl_context.h" |
| 13 #include "ui/gl/scoped_make_current.h" | 14 #include "ui/gl/scoped_make_current.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 AVDACodecImage::AVDACodecImage( | 18 AVDACodecImage::AVDACodecImage( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 43 | 44 |
| 44 gfx::Size AVDACodecImage::GetSize() { | 45 gfx::Size AVDACodecImage::GetSize() { |
| 45 return size_; | 46 return size_; |
| 46 } | 47 } |
| 47 | 48 |
| 48 unsigned AVDACodecImage::GetInternalFormat() { | 49 unsigned AVDACodecImage::GetInternalFormat() { |
| 49 return GL_RGBA; | 50 return GL_RGBA; |
| 50 } | 51 } |
| 51 | 52 |
| 52 bool AVDACodecImage::BindTexImage(unsigned target) { | 53 bool AVDACodecImage::BindTexImage(unsigned target) { |
| 53 return true; | 54 return false; |
| 54 } | 55 } |
| 55 | 56 |
| 56 void AVDACodecImage::ReleaseTexImage(unsigned target) {} | 57 void AVDACodecImage::ReleaseTexImage(unsigned target) {} |
| 57 | 58 |
| 58 bool AVDACodecImage::CopyTexSubImage(unsigned target, | 59 bool AVDACodecImage::CopyTexImage(unsigned target) { |
| 59 const gfx::Point& offset, | 60 if (target != GL_TEXTURE_EXTERNAL_OES) |
| 60 const gfx::Rect& rect) { | 61 return false; |
| 61 return false; | |
| 62 } | |
| 63 | 62 |
| 64 void AVDACodecImage::WillUseTexImage() { | |
| 65 // Have we bound the SurfaceTexture's texture handle to the active | 63 // Have we bound the SurfaceTexture's texture handle to the active |
| 66 // texture unit yet? | 64 // texture unit yet? |
| 67 bool bound_texture = false; | 65 bool bound_texture = false; |
| 68 | 66 |
| 69 // Attach the surface texture to our GL context if needed. | 67 // Attach the surface texture to our GL context if needed. |
| 70 if (!shared_state_->surface_texture_service_id()) { | 68 if (!shared_state_->surface_texture_service_id()) { |
| 71 AttachSurfaceTextureToContext(); | 69 AttachSurfaceTextureToContext(); |
| 72 bound_texture = true; | 70 bound_texture = true; |
| 73 } | 71 } |
| 74 | 72 |
| 75 // Make sure that we have the right image in the front buffer. | 73 // Make sure that we have the right image in the front buffer. |
| 76 bound_texture |= UpdateSurfaceTexture(); | 74 bound_texture |= UpdateSurfaceTexture(); |
| 77 | 75 |
| 78 // TODO(liberato): Handle the texture matrix properly. | |
| 79 // Either we can update the shader with it or we can move all of the logic | |
| 80 // to updateTexImage() to the right place in the cc to send it to the shader. | |
| 81 // For now, we just skip it. crbug.com/530681 | |
| 82 | |
| 83 // Sneakily bind the ST texture handle in the real GL context. | 76 // Sneakily bind the ST texture handle in the real GL context. |
| 84 // If we called UpdateTexImage() to update the ST front buffer, then we can | 77 // If we called UpdateTexImage() to update the ST front buffer, then we can |
| 85 // skip this. Since one draw/frame is the common case, we optimize for it. | 78 // skip this. Since one draw/frame is the common case, we optimize for it. |
| 86 if (!bound_texture) | 79 if (!bound_texture) |
| 87 glBindTexture(GL_TEXTURE_EXTERNAL_OES, | 80 glBindTexture(GL_TEXTURE_EXTERNAL_OES, |
| 88 shared_state_->surface_texture_service_id()); | 81 shared_state_->surface_texture_service_id()); |
| 82 |
| 83 // TODO(liberato): Handle the texture matrix properly. |
| 84 // Either we can update the shader with it or we can move all of the logic |
| 85 // to updateTexImage() to the right place in the cc to send it to the shader. |
| 86 // For now, we just skip it. crbug.com/530681 |
| 87 |
| 88 gpu::gles2::TextureManager* texture_manager = |
| 89 decoder_->GetContextGroup()->texture_manager(); |
| 90 gpu::gles2::Texture* texture = |
| 91 texture_manager->GetTextureForServiceId( |
| 92 shared_state_->surface_texture_service_id()); |
| 93 if (texture) { |
| 94 // By setting image state to UNBOUND instead of COPIED we ensure that |
| 95 // CopyTexImage() is called each time the surface texture is used for |
| 96 // drawing. |
| 97 texture->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this, |
| 98 gpu::gles2::Texture::UNBOUND); |
| 99 } |
| 100 |
| 101 return true; |
| 89 } | 102 } |
| 90 | 103 |
| 91 void AVDACodecImage::DidUseTexImage() { | 104 bool AVDACodecImage::CopyTexSubImage(unsigned target, |
| 92 // Unbind the ST's service_id in the real GL context in favor of whatever | 105 const gfx::Point& offset, |
| 93 // the decoder thinks is bound there. | 106 const gfx::Rect& rect) { |
| 94 const gpu::gles2::ContextState* state = decoder_->GetContextState(); | 107 return false; |
| 95 const gpu::gles2::TextureUnit& active_unit = | |
| 96 state->texture_units[state->active_texture_unit]; | |
| 97 glBindTexture(GL_TEXTURE_EXTERNAL_OES, | |
| 98 active_unit.bound_texture_external_oes.get() | |
| 99 ? active_unit.bound_texture_external_oes->service_id() | |
| 100 : 0); | |
| 101 } | 108 } |
| 102 | 109 |
| 103 bool AVDACodecImage::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 110 bool AVDACodecImage::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
| 104 int z_order, | 111 int z_order, |
| 105 gfx::OverlayTransform transform, | 112 gfx::OverlayTransform transform, |
| 106 const gfx::Rect& bounds_rect, | 113 const gfx::Rect& bounds_rect, |
| 107 const gfx::RectF& crop_rect) { | 114 const gfx::RectF& crop_rect) { |
| 108 return false; | 115 return false; |
| 109 } | 116 } |
| 110 | 117 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 176 |
| 170 // The surface texture is already detached, so just attach it. | 177 // The surface texture is already detached, so just attach it. |
| 171 surface_texture_->AttachToGLContext(); | 178 surface_texture_->AttachToGLContext(); |
| 172 shared_state_->set_surface_texture_service_id(surface_texture_service_id); | 179 shared_state_->set_surface_texture_service_id(surface_texture_service_id); |
| 173 detach_surface_texture_on_destruction_ = true; | 180 detach_surface_texture_on_destruction_ = true; |
| 174 | 181 |
| 175 // We do not restore the GL state here. | 182 // We do not restore the GL state here. |
| 176 } | 183 } |
| 177 | 184 |
| 178 } // namespace content | 185 } // namespace content |
| OLD | NEW |