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 DISCARD_CODEC_BUFFER, // Discards the codec buffer, no UpdateTexImage(). | |
61 RENDER_TO_BACK_BUFFER, // Renders to back buffer, doesn't UpdateTexImage(). | |
62 RENDER_TO_FRONT_BUFFER // Renders to back buffer, calls UpdateTexImage(), | |
63 // which turns the back buffer into the front. | |
liberato (no reviews please)
2016/04/22 20:25:08
this comment isn't right for SV. we use FRONT_BUF
DaleCurtis
2016/04/22 20:58:02
Comment clarified.
| |
64 }; | |
65 | |
66 // Releases the attached codec buffer (if not already released) indicated by | |
67 // |codec_buffer_index_| and updates the surface if specified by the given | |
68 // |update_mode|. See UpdateMode documentation for details. | |
69 void UpdateSurface(UpdateMode update_mode); | |
70 | |
63 // Updates the MediaCodec for this image; clears |codec_buffer_index_|. | 71 // Updates the MediaCodec for this image; clears |codec_buffer_index_|. |
64 void CodecChanged(media::MediaCodecBridge* codec); | 72 void CodecChanged(media::MediaCodecBridge* codec); |
65 | 73 |
66 void SetTexture(gpu::gles2::Texture* texture); | 74 void SetTexture(gpu::gles2::Texture* texture); |
67 | 75 |
76 // Indicates if the codec buffer has been released to the back buffer. | |
77 bool is_rendered_to_back_buffer() const { | |
78 return codec_buffer_index_ == kUpdateOnly; | |
79 } | |
80 | |
81 // Indicates if the codec buffer has been released to the front or back | |
82 // buffer. | |
83 bool is_rendered() const { | |
84 return codec_buffer_index_ <= kInvalidCodecBufferIndex; | |
85 } | |
86 | |
68 protected: | 87 protected: |
69 ~AVDACodecImage() override; | 88 ~AVDACodecImage() override; |
70 | 89 |
71 private: | 90 private: |
72 enum { kInvalidCodecBufferIndex = -1 }; | 91 enum { kInvalidCodecBufferIndex = -1, kUpdateOnly = -2 }; |
73 | 92 |
74 // Make sure that the surface texture's front buffer is current. This will | 93 // 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 | 94 // save / restore the current context. It will optionally restore the texture |
76 // bindings in the surface texture's context, based on |mode|. This is | 95 // 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 | 96 // 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 | 97 // 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 | 98 // both contexts. In other words, the caller is telling us whether it's |
80 // okay to change the binding in the current context. | 99 // okay to change the binding in the current context. |
81 enum RestoreBindingsMode { kDontRestoreBindings, kDoRestoreBindings }; | 100 enum RestoreBindingsMode { kDontRestoreBindings, kDoRestoreBindings }; |
82 void UpdateSurfaceTexture(RestoreBindingsMode mode); | 101 void UpdateSurfaceTexture(RestoreBindingsMode mode); |
83 | 102 |
103 // Internal helper for UpdateSurface() that allows callers to specify the | |
104 // RestoreBindingsMode when a SurfaceTexture is already attached prior to | |
105 // calling this method. | |
106 void UpdateSurfaceInternal(UpdateMode update_mode, | |
107 RestoreBindingsMode attached_bindings_mode); | |
108 | |
109 // Releases the attached codec buffer (if not already released) indicated by | |
110 // |codec_buffer_index_|. Never updates the actual surface. See UpdateMode | |
111 // documentation for details. For the purposes of this function the values | |
112 // RENDER_TO_FRONT_BUFFER and RENDER_TO_BACK_BUFFER do the same thing. | |
113 void ReleaseOutputBuffer(UpdateMode update_mode); | |
114 | |
84 // Attach the surface texture to our GL context to whatever texture is bound | 115 // Attach the surface texture to our GL context to whatever texture is bound |
85 // on the active unit. | 116 // on the active unit. |
86 void AttachSurfaceTextureToContext(); | 117 void AttachSurfaceTextureToContext(); |
87 | 118 |
88 // Make shared_state_->context() current if it isn't already. | 119 // Make shared_state_->context() current if it isn't already. |
89 std::unique_ptr<ui::ScopedMakeCurrent> MakeCurrentIfNeeded(); | 120 std::unique_ptr<ui::ScopedMakeCurrent> MakeCurrentIfNeeded(); |
90 | 121 |
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 | 122 // 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. | 123 // return false also if there's no codec or we otherwise can't update. |
98 bool IsCodecBufferOutstanding() const; | 124 bool IsCodecBufferOutstanding() const; |
99 | 125 |
100 // Shared state between the AVDA and all AVDACodecImages. | 126 // Shared state between the AVDA and all AVDACodecImages. |
101 scoped_refptr<AVDASharedState> shared_state_; | 127 scoped_refptr<AVDASharedState> shared_state_; |
102 | 128 |
103 // The MediaCodec buffer index that we should render. Only valid if not equal | 129 // The MediaCodec buffer index that we should render. Only valid if not equal |
104 // to |kInvalidCodecBufferIndex|. | 130 // to |kInvalidCodecBufferIndex|. |
105 int codec_buffer_index_; | 131 int codec_buffer_index_; |
(...skipping 22 matching lines...) Expand all Loading... | |
128 | 154 |
129 // The picture buffer id attached to this image. | 155 // The picture buffer id attached to this image. |
130 int picture_buffer_id_; | 156 int picture_buffer_id_; |
131 | 157 |
132 DISALLOW_COPY_AND_ASSIGN(AVDACodecImage); | 158 DISALLOW_COPY_AND_ASSIGN(AVDACodecImage); |
133 }; | 159 }; |
134 | 160 |
135 } // namespace content | 161 } // namespace content |
136 | 162 |
137 #endif // CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ | 163 #endif // CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ |
OLD | NEW |