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