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 #ifndef CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ | 5 #ifndef CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ |
6 #define CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ | 6 #define CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 const gfx::RectF& crop_rect) override; | 46 const gfx::RectF& crop_rect) override; |
47 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 47 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
48 uint64_t process_tracing_id, | 48 uint64_t process_tracing_id, |
49 const std::string& dump_name) override; | 49 const std::string& dump_name) override; |
50 // gpu::gles2::GLStreamTextureMatrix implementation | 50 // gpu::gles2::GLStreamTextureMatrix implementation |
51 void GetTextureMatrix(float xform[16]) override; | 51 void GetTextureMatrix(float xform[16]) override; |
52 | 52 |
53 // Decoded buffer index that has the image for us to display. | 53 // Decoded buffer index that has the image for us to display. |
54 void SetMediaCodecBufferIndex(int buffer_index); | 54 void SetMediaCodecBufferIndex(int buffer_index); |
55 | 55 |
56 // Return the codec buffer that we will return to the codec, or | |
57 // <0 if there is no such buffer. | |
58 int GetMediaCodecBufferIndex() const; | |
59 | |
60 // Set the size of the current image. | 56 // Set the size of the current image. |
61 void SetSize(const gfx::Size& size); | 57 void SetSize(const gfx::Size& size); |
62 | 58 |
| 59 enum class UpdateMode { |
| 60 // Discards the codec buffer, no UpdateTexImage(). |
| 61 DISCARD_CODEC_BUFFER, |
| 62 |
| 63 // Renders to back buffer, no UpdateTexImage(); can only be used with a |
| 64 // valid |surface_texture_|. |
| 65 RENDER_TO_BACK_BUFFER, |
| 66 |
| 67 // Renders to the back buffer. When used with a SurfaceView, promotion to |
| 68 // the front buffer is automatic. When using a |surface_texture_|, |
| 69 // UpdateTexImage() is called to promote the back buffer into the front. |
| 70 RENDER_TO_FRONT_BUFFER |
| 71 }; |
| 72 |
| 73 // Releases the attached codec buffer (if not already released) indicated by |
| 74 // |codec_buffer_index_| and updates the surface if specified by the given |
| 75 // |update_mode|. See UpdateMode documentation for details. |
| 76 void UpdateSurface(UpdateMode update_mode); |
| 77 |
63 // Updates the MediaCodec for this image; clears |codec_buffer_index_|. | 78 // Updates the MediaCodec for this image; clears |codec_buffer_index_|. |
64 void CodecChanged(media::MediaCodecBridge* codec); | 79 void CodecChanged(media::MediaCodecBridge* codec); |
65 | 80 |
66 void SetTexture(gpu::gles2::Texture* texture); | 81 void SetTexture(gpu::gles2::Texture* texture); |
67 | 82 |
| 83 // Indicates if the codec buffer has been released to the back buffer. |
| 84 bool is_rendered_to_back_buffer() const { |
| 85 return codec_buffer_index_ == kUpdateOnly; |
| 86 } |
| 87 |
| 88 // Indicates if the codec buffer has been released to the front or back |
| 89 // buffer. |
| 90 bool is_rendered() const { |
| 91 return codec_buffer_index_ <= kInvalidCodecBufferIndex; |
| 92 } |
| 93 |
68 protected: | 94 protected: |
69 ~AVDACodecImage() override; | 95 ~AVDACodecImage() override; |
70 | 96 |
71 private: | 97 private: |
72 enum { kInvalidCodecBufferIndex = -1 }; | 98 enum { kInvalidCodecBufferIndex = -1, kUpdateOnly = -2 }; |
73 | 99 |
74 // Make sure that the surface texture's front buffer is current. This will | 100 // Make sure that the surface texture's front buffer is current. This will |
75 // save / restore the current context. It will optionally restore the texture | 101 // save / restore the current context. It will optionally restore the texture |
76 // bindings in the surface texture's context, based on |mode|. This is | 102 // bindings in the surface texture's context, based on |mode|. This is |
77 // intended as a hint if we don't need to change contexts. If we do need to | 103 // intended as a hint if we don't need to change contexts. If we do need to |
78 // change contexts, then we'll always preserve the texture bindings in the | 104 // change contexts, then we'll always preserve the texture bindings in the |
79 // both contexts. In other words, the caller is telling us whether it's | 105 // both contexts. In other words, the caller is telling us whether it's |
80 // okay to change the binding in the current context. | 106 // okay to change the binding in the current context. |
81 enum RestoreBindingsMode { kDontRestoreBindings, kDoRestoreBindings }; | 107 enum RestoreBindingsMode { kDontRestoreBindings, kDoRestoreBindings }; |
82 void UpdateSurfaceTexture(RestoreBindingsMode mode); | 108 void UpdateSurfaceTexture(RestoreBindingsMode mode); |
83 | 109 |
| 110 // Internal helper for UpdateSurface() that allows callers to specify the |
| 111 // RestoreBindingsMode when a SurfaceTexture is already attached prior to |
| 112 // calling this method. |
| 113 void UpdateSurfaceInternal(UpdateMode update_mode, |
| 114 RestoreBindingsMode attached_bindings_mode); |
| 115 |
| 116 // Releases the attached codec buffer (if not already released) indicated by |
| 117 // |codec_buffer_index_|. Never updates the actual surface. See UpdateMode |
| 118 // documentation for details. For the purposes of this function the values |
| 119 // RENDER_TO_FRONT_BUFFER and RENDER_TO_BACK_BUFFER do the same thing. |
| 120 void ReleaseOutputBuffer(UpdateMode update_mode); |
| 121 |
84 // Attach the surface texture to our GL context to whatever texture is bound | 122 // Attach the surface texture to our GL context to whatever texture is bound |
85 // on the active unit. | 123 // on the active unit. |
86 void AttachSurfaceTextureToContext(); | 124 void AttachSurfaceTextureToContext(); |
87 | 125 |
88 // Make shared_state_->context() current if it isn't already. | 126 // Make shared_state_->context() current if it isn't already. |
89 std::unique_ptr<ui::ScopedMakeCurrent> MakeCurrentIfNeeded(); | 127 std::unique_ptr<ui::ScopedMakeCurrent> MakeCurrentIfNeeded(); |
90 | 128 |
91 // Return whether or not the current context is in the same share group as | |
92 // |surface_texture_|'s client texture. | |
93 // TODO(liberato): is this needed? | |
94 bool IsCorrectShareGroup() const; | |
95 | |
96 // Return whether there is a codec buffer that we haven't rendered yet. Will | 129 // Return whether there is a codec buffer that we haven't rendered yet. Will |
97 // return false also if there's no codec or we otherwise can't update. | 130 // return false also if there's no codec or we otherwise can't update. |
98 bool IsCodecBufferOutstanding() const; | 131 bool IsCodecBufferOutstanding() const; |
99 | 132 |
100 // Shared state between the AVDA and all AVDACodecImages. | 133 // Shared state between the AVDA and all AVDACodecImages. |
101 scoped_refptr<AVDASharedState> shared_state_; | 134 scoped_refptr<AVDASharedState> shared_state_; |
102 | 135 |
103 // The MediaCodec buffer index that we should render. Only valid if not equal | 136 // The MediaCodec buffer index that we should render. Only valid if not equal |
104 // to |kInvalidCodecBufferIndex|. | 137 // to |kInvalidCodecBufferIndex|. |
105 int codec_buffer_index_; | 138 int codec_buffer_index_; |
(...skipping 22 matching lines...) Expand all Loading... |
128 | 161 |
129 // The picture buffer id attached to this image. | 162 // The picture buffer id attached to this image. |
130 int picture_buffer_id_; | 163 int picture_buffer_id_; |
131 | 164 |
132 DISALLOW_COPY_AND_ASSIGN(AVDACodecImage); | 165 DISALLOW_COPY_AND_ASSIGN(AVDACodecImage); |
133 }; | 166 }; |
134 | 167 |
135 } // namespace content | 168 } // namespace content |
136 | 169 |
137 #endif // CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ | 170 #endif // CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ |
OLD | NEW |