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