| 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 MEDIA_GPU_AVDA_SHARED_STATE_H_ | 5 #ifndef MEDIA_GPU_AVDA_SHARED_STATE_H_ |
| 6 #define MEDIA_GPU_AVDA_SHARED_STATE_H_ | 6 #define MEDIA_GPU_AVDA_SHARED_STATE_H_ |
| 7 | 7 |
| 8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 10 #include "media/base/android/media_codec_bridge.h" | 10 #include "media/base/android/media_codec_bridge.h" |
| 11 #include "media/gpu/surface_texture_gl_owner.h" |
| 11 #include "ui/gl/gl_bindings.h" | 12 #include "ui/gl/gl_bindings.h" |
| 12 #include "ui/gl/gl_context.h" | 13 #include "ui/gl/gl_context.h" |
| 13 #include "ui/gl/gl_image.h" | 14 #include "ui/gl/gl_image.h" |
| 14 #include "ui/gl/gl_surface.h" | 15 #include "ui/gl/gl_surface.h" |
| 15 | 16 |
| 16 namespace gl { | |
| 17 class SurfaceTexture; | |
| 18 } | |
| 19 | |
| 20 namespace media { | 17 namespace media { |
| 21 | 18 |
| 22 // Shared state to allow communication between the AVDA and the | 19 // Shared state to allow communication between the AVDA and the |
| 23 // GLImages that configure GL for drawing the frames. | 20 // GLImages that configure GL for drawing the frames. |
| 24 class AVDASharedState : public base::RefCounted<AVDASharedState> { | 21 class AVDASharedState : public base::RefCounted<AVDASharedState> { |
| 25 public: | 22 public: |
| 26 AVDASharedState(); | 23 AVDASharedState(); |
| 27 | 24 |
| 28 GLuint surface_texture_service_id() const { | 25 GLuint surface_texture_service_id() const { |
| 29 return surface_texture_service_id_; | 26 return surface_texture_ ? surface_texture_->texture_id() : 0; |
| 30 } | 27 } |
| 31 | 28 |
| 32 // Signal the "frame available" event. This may be called from any thread. | 29 // Signal the "frame available" event. This may be called from any thread. |
| 33 void SignalFrameAvailable(); | 30 void SignalFrameAvailable(); |
| 34 | 31 |
| 35 void WaitForFrameAvailable(); | 32 void WaitForFrameAvailable(); |
| 36 | 33 |
| 37 void SetSurfaceTexture(scoped_refptr<gl::SurfaceTexture> surface_texture, | 34 void SetSurfaceTexture(scoped_refptr<SurfaceTextureGLOwner> surface_texture); |
| 38 GLuint attached_service_id); | |
| 39 | 35 |
| 40 // Context and surface that |surface_texture_| is bound to, if | 36 // Context and surface that |surface_texture_| is bound to, if |
| 41 // |surface_texture_| is not null. | 37 // |surface_texture_| is not null. |
| 42 gl::GLContext* context() const { return context_.get(); } | 38 gl::GLContext* context() const { |
| 39 return surface_texture_ ? surface_texture_->context() : nullptr; |
| 40 } |
| 43 | 41 |
| 44 gl::GLSurface* surface() const { return surface_.get(); } | 42 gl::GLSurface* surface() const { |
| 43 return surface_texture_ ? surface_texture_->surface() : nullptr; |
| 44 } |
| 45 | 45 |
| 46 // Helper method for coordinating the interactions between | 46 // Helper method for coordinating the interactions between |
| 47 // MediaCodec::ReleaseOutputBuffer() and WaitForFrameAvailable() when | 47 // MediaCodec::ReleaseOutputBuffer() and WaitForFrameAvailable() when |
| 48 // rendering to a SurfaceTexture; this method should never be called when | 48 // rendering to a SurfaceTexture; this method should never be called when |
| 49 // rendering to a SurfaceView. | 49 // rendering to a SurfaceView. |
| 50 // | 50 // |
| 51 // The release of the codec buffer to the surface texture is asynchronous, by | 51 // The release of the codec buffer to the surface texture is asynchronous, by |
| 52 // using this helper we can attempt to let this process complete in a non | 52 // using this helper we can attempt to let this process complete in a non |
| 53 // blocking fashion before the SurfaceTexture is used. | 53 // blocking fashion before the SurfaceTexture is used. |
| 54 // | 54 // |
| (...skipping 18 matching lines...) Expand all Loading... |
| 73 // Resets the last time for RenderCodecBufferToSurfaceTexture(). Should be | 73 // Resets the last time for RenderCodecBufferToSurfaceTexture(). Should be |
| 74 // called during codec changes. | 74 // called during codec changes. |
| 75 void clear_release_time() { release_time_ = base::TimeTicks(); } | 75 void clear_release_time() { release_time_ = base::TimeTicks(); } |
| 76 | 76 |
| 77 protected: | 77 protected: |
| 78 virtual ~AVDASharedState(); | 78 virtual ~AVDASharedState(); |
| 79 | 79 |
| 80 private: | 80 private: |
| 81 friend class base::RefCounted<AVDASharedState>; | 81 friend class base::RefCounted<AVDASharedState>; |
| 82 | 82 |
| 83 scoped_refptr<gl::SurfaceTexture> surface_texture_; | 83 scoped_refptr<SurfaceTextureGLOwner> surface_texture_; |
| 84 | |
| 85 // Platform gl texture id for |surface_texture_|. | |
| 86 GLuint surface_texture_service_id_; | |
| 87 | 84 |
| 88 // For signalling OnFrameAvailable(). | 85 // For signalling OnFrameAvailable(). |
| 89 base::WaitableEvent frame_available_event_; | 86 base::WaitableEvent frame_available_event_; |
| 90 | 87 |
| 91 // Context and surface that |surface_texture_| is bound to, if | |
| 92 // |surface_texture_| is not null. | |
| 93 scoped_refptr<gl::GLContext> context_; | |
| 94 scoped_refptr<gl::GLSurface> surface_; | |
| 95 | |
| 96 // The time of the last call to RenderCodecBufferToSurfaceTexture(), null if | 88 // The time of the last call to RenderCodecBufferToSurfaceTexture(), null if |
| 97 // if there has been no last call or WaitForFrameAvailable() has been called | 89 // if there has been no last call or WaitForFrameAvailable() has been called |
| 98 // since the last call. | 90 // since the last call. |
| 99 base::TimeTicks release_time_; | 91 base::TimeTicks release_time_; |
| 100 | 92 |
| 101 // Texture matrix of the front buffer of the surface texture. | 93 // Texture matrix of the front buffer of the surface texture. |
| 102 float gl_matrix_[16]; | 94 float gl_matrix_[16]; |
| 103 | 95 |
| 104 class OnFrameAvailableHandler; | 96 class OnFrameAvailableHandler; |
| 105 scoped_refptr<OnFrameAvailableHandler> on_frame_available_handler_; | 97 scoped_refptr<OnFrameAvailableHandler> on_frame_available_handler_; |
| 106 | 98 |
| 107 DISALLOW_COPY_AND_ASSIGN(AVDASharedState); | 99 DISALLOW_COPY_AND_ASSIGN(AVDASharedState); |
| 108 }; | 100 }; |
| 109 | 101 |
| 110 } // namespace media | 102 } // namespace media |
| 111 | 103 |
| 112 #endif // MEDIA_GPU_AVDA_SHARED_STATE_H_ | 104 #endif // MEDIA_GPU_AVDA_SHARED_STATE_H_ |
| OLD | NEW |