| 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_AVDA_SHARED_STATE_H_ | 5 #ifndef CONTENT_COMMON_GPU_AVDA_SHARED_STATE_H_ |
| 6 #define CONTENT_COMMON_GPU_AVDA_SHARED_STATE_H_ | 6 #define CONTENT_COMMON_GPU_AVDA_SHARED_STATE_H_ |
| 7 | 7 |
| 8 #include "base/macros.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 "ui/gl/android/surface_texture.h" |
| 10 #include "media/base/android/media_codec_bridge.h" | 11 #include "ui/gl/gl_bindings.h" |
| 11 #include "media/base/android/sdk_media_codec_bridge.h" | |
| 12 #include "ui/gl/gl_context.h" | 12 #include "ui/gl/gl_context.h" |
| 13 #include "ui/gl/gl_image.h" | |
| 14 #include "ui/gl/gl_surface.h" | 13 #include "ui/gl/gl_surface.h" |
| 15 | 14 |
| 16 namespace gfx { | |
| 17 class SurfaceTexture; | |
| 18 } | |
| 19 | |
| 20 namespace content { | 15 namespace content { |
| 21 | 16 |
| 22 // Shared state to allow communication between the AVDA and the | 17 // Shared state to allow communication between |
| 23 // GLImages that configure GL for drawing the frames. | 18 // AndroidDeferredRenderingBackingStrategy and the AVDACodecImages it creates. |
| 19 // It's refcounted so that it lives as long as the images that refer to it. |
| 24 class AVDASharedState : public base::RefCounted<AVDASharedState> { | 20 class AVDASharedState : public base::RefCounted<AVDASharedState> { |
| 25 public: | 21 public: |
| 26 AVDASharedState(); | 22 AVDASharedState(); |
| 27 | 23 |
| 28 GLint surface_texture_service_id() const { | 24 GLint surface_texture_service_id() const { |
| 29 return surface_texture_service_id_; | 25 return surface_texture_service_id_; |
| 30 } | 26 } |
| 31 | 27 |
| 32 // Set the SurfaceTexture's client texture name, which the SurfaceTexture | 28 // Set the SurfaceTexture's client texture name, which the SurfaceTexture |
| 33 // might not know about yet (see surface_texture_is_attached()). | 29 // might not know about yet (see surface_texture_is_attached()). Ownership of |
| 34 void set_surface_texture_service_id(GLint id) { | 30 // the texture is passed to this object. When it's destructed it will call |
| 35 surface_texture_service_id_ = id; | 31 // the passed callback to delete it. |
| 32 void SetSurfaceTextureServiceID( |
| 33 GLuint id, |
| 34 const base::Callback<void(GLuint)>& delete_texture_cb); |
| 35 |
| 36 scoped_refptr<gfx::SurfaceTexture> surface_texture() const { |
| 37 return surface_texture_; |
| 36 } | 38 } |
| 37 | 39 |
| 38 // Signal the "frame available" event. This may be called from any thread. | 40 void set_surface_texture( |
| 39 void SignalFrameAvailable(); | 41 const scoped_refptr<gfx::SurfaceTexture>& surface_texture) { |
| 40 | 42 surface_texture_ = surface_texture; |
| 41 void WaitForFrameAvailable(); | 43 } |
| 42 | 44 |
| 43 // Context that the surface texture is bound to, or nullptr if it is not in | 45 // Context that the surface texture is bound to, or nullptr if it is not in |
| 44 // the attached state. | 46 // the attached state. |
| 45 gfx::GLContext* context() const { return context_.get(); } | 47 gfx::GLContext* context() const { return context_.get(); } |
| 46 | 48 |
| 47 gfx::GLSurface* surface() const { return surface_.get(); } | 49 gfx::GLSurface* surface() const { return surface_.get(); } |
| 48 | 50 |
| 49 bool surface_texture_is_attached() const { | 51 bool surface_texture_is_attached() const { |
| 50 return surface_texture_is_attached_; | 52 return surface_texture_is_attached_; |
| 51 } | 53 } |
| 52 | 54 |
| 55 // Signal the "frame available" event. This may be called from any thread. |
| 56 void SignalFrameAvailable(); |
| 57 |
| 58 void WaitForFrameAvailable(); |
| 59 |
| 53 // Call this when the SurfaceTexture is attached to a GL context. This will | 60 // Call this when the SurfaceTexture is attached to a GL context. This will |
| 54 // update surface_texture_is_attached(), and set the context() and surface() | 61 // update surface_texture_is_attached(), and set the context() and surface() |
| 55 // to match. | 62 // to match. |
| 56 void did_attach_surface_texture(); | 63 void DidAttachSurfaceTexture(); |
| 57 | 64 |
| 58 private: | 65 private: |
| 59 // Platform gl texture Id for |surface_texture_|. This will be zero if | 66 friend class base::RefCounted<AVDASharedState>; |
| 60 // and only if |texture_owner_| is null. | 67 virtual ~AVDASharedState(); |
| 61 // TODO(liberato): This should be GLuint, but we don't seem to have the type. | 68 |
| 62 GLint surface_texture_service_id_; | 69 // Platform gl texture ID for |surface_texture_|. |
| 70 GLuint surface_texture_service_id_; |
| 71 // Valid when |surface_texture_service_id_| is valid. Used to delete it. |
| 72 base::Callback<void(GLuint)> delete_texture_cb_; |
| 73 |
| 74 scoped_refptr<gfx::SurfaceTexture> surface_texture_; |
| 63 | 75 |
| 64 // For signalling OnFrameAvailable(). | 76 // For signalling OnFrameAvailable(). |
| 65 base::WaitableEvent frame_available_event_; | 77 base::WaitableEvent frame_available_event_; |
| 66 | 78 |
| 67 // True if and only if the surface texture is currently attached. | 79 // True if and only if the surface texture is currently attached. |
| 68 bool surface_texture_is_attached_; | 80 bool surface_texture_is_attached_; |
| 69 | 81 |
| 70 // Context and surface that the surface texture is attached to, if it is | 82 // Context and surface that the surface texture is attached to, if it is |
| 71 // currently attached. | 83 // currently attached. |
| 72 scoped_refptr<gfx::GLContext> context_; | 84 scoped_refptr<gfx::GLContext> context_; |
| 73 scoped_refptr<gfx::GLSurface> surface_; | 85 scoped_refptr<gfx::GLSurface> surface_; |
| 74 | 86 |
| 75 protected: | 87 DISALLOW_COPY_AND_ASSIGN(AVDASharedState); |
| 76 virtual ~AVDASharedState(); | |
| 77 | |
| 78 private: | |
| 79 friend class base::RefCounted<AVDASharedState>; | |
| 80 }; | 88 }; |
| 81 | 89 |
| 82 } // namespace content | 90 } // namespace content |
| 83 | 91 |
| 84 #endif // CONTENT_COMMON_GPU_AVDA_SHARED_STATE_H_ | 92 #endif // CONTENT_COMMON_GPU_AVDA_SHARED_STATE_H_ |
| OLD | NEW |