stream_texture_android.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef GPU_IPC_SERVICE_STREAM_TEXTURE_ANDROID_H_
  5. #define GPU_IPC_SERVICE_STREAM_TEXTURE_ANDROID_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/memory/ref_counted.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "base/threading/thread_checker.h"
  12. #include "base/unguessable_token.h"
  13. #include "gpu/command_buffer/service/shared_context_state.h"
  14. #include "gpu/command_buffer/service/stream_texture_shared_image_interface.h"
  15. #include "gpu/command_buffer/service/texture_owner.h"
  16. #include "gpu/ipc/common/gpu_channel.mojom.h"
  17. #include "gpu/ipc/service/command_buffer_stub.h"
  18. #include "mojo/public/cpp/bindings/associated_receiver.h"
  19. #include "mojo/public/cpp/bindings/associated_remote.h"
  20. #include "ui/gl/android/surface_texture.h"
  21. #include "ui/gl/gl_image.h"
  22. namespace gfx {
  23. class Size;
  24. }
  25. namespace gpu {
  26. class GpuChannel;
  27. struct Mailbox;
  28. // This class is thread safe to be used by multiple gpu threads as
  29. // |texture_owner_| is thread safe and all other members are only accessed on
  30. // gpu main thread.
  31. class StreamTexture : public StreamTextureSharedImageInterface,
  32. public mojom::StreamTexture {
  33. public:
  34. static scoped_refptr<StreamTexture> Create(
  35. GpuChannel* channel,
  36. int stream_id,
  37. mojo::PendingAssociatedReceiver<mojom::StreamTexture> receiver);
  38. StreamTexture(const StreamTexture&) = delete;
  39. StreamTexture& operator=(const StreamTexture&) = delete;
  40. // Cleans up related data and nulls |channel_|. Called when the channel
  41. // releases its ref on this class.
  42. void ReleaseChannel();
  43. private:
  44. StreamTexture(GpuChannel* channel,
  45. int32_t route_id,
  46. mojo::PendingAssociatedReceiver<mojom::StreamTexture> receiver,
  47. scoped_refptr<SharedContextState> context_state);
  48. ~StreamTexture() override;
  49. // Static function which is used to access |weak_stream_texture| on correct
  50. // thread since WeakPtr is not thread safe.
  51. static void RunCallback(
  52. scoped_refptr<base::SingleThreadTaskRunner> task_runner,
  53. base::WeakPtr<StreamTexture> weak_stream_texture);
  54. // gl::GLImage implementation:
  55. gfx::Size GetSize() override;
  56. unsigned GetInternalFormat() override;
  57. unsigned GetDataType() override;
  58. BindOrCopy ShouldBindOrCopy() override;
  59. bool BindTexImage(unsigned target) override;
  60. void ReleaseTexImage(unsigned target) override;
  61. bool CopyTexImage(unsigned target) override;
  62. bool CopyTexSubImage(unsigned target,
  63. const gfx::Point& offset,
  64. const gfx::Rect& rect) override;
  65. void SetColorSpace(const gfx::ColorSpace& color_space) override {}
  66. void Flush() override {}
  67. void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
  68. uint64_t process_tracing_id,
  69. const std::string& dump_name) override;
  70. bool HasMutableState() const override;
  71. std::unique_ptr<base::android::ScopedHardwareBufferFenceSync>
  72. GetAHardwareBuffer() override;
  73. // gpu::StreamTextureSharedImageInterface implementation.
  74. void ReleaseResources() override {}
  75. bool IsUsingGpuMemory() const override;
  76. void UpdateAndBindTexImage(GLuint service_id) override;
  77. bool HasTextureOwner() const override;
  78. TextureBase* GetTextureBase() const override;
  79. void NotifyOverlayPromotion(bool promotion, const gfx::Rect& bounds) override;
  80. bool RenderToOverlay() override;
  81. bool TextureOwnerBindsTextureOnUpdate() override;
  82. gpu::Mailbox CreateSharedImage(const gfx::Size& coded_size);
  83. // Called when a new frame is available for the SurfaceOwner.
  84. void OnFrameAvailable();
  85. // mojom::StreamTexture:
  86. void ForwardForSurfaceRequest(const base::UnguessableToken& token) override;
  87. void StartListening(mojo::PendingAssociatedRemote<mojom::StreamTextureClient>
  88. client) override;
  89. void UpdateRotatedVisibleSize(const gfx::Size& natural_size) override;
  90. // The TextureOwner which receives frames.
  91. scoped_refptr<TextureOwner> texture_owner_;
  92. // Current visible size from media player, includes rotation.
  93. gfx::Size rotated_visible_size_;
  94. // Whether a new frame is available that we should update to.
  95. bool has_pending_frame_;
  96. raw_ptr<GpuChannel> channel_;
  97. const int32_t route_id_;
  98. scoped_refptr<SharedContextState> context_state_;
  99. SequenceId sequence_;
  100. mojo::AssociatedReceiver<mojom::StreamTexture> receiver_;
  101. mojo::AssociatedRemote<mojom::StreamTextureClient> client_;
  102. gfx::Size coded_size_;
  103. gfx::Rect visible_rect_;
  104. // Bound to the thread on which StreamTexture is created. Some methods can
  105. // only be called on this thread. StreamTexture is created on gpu main thread.
  106. THREAD_CHECKER(gpu_main_thread_checker_);
  107. base::WeakPtrFactory<StreamTexture> weak_factory_{this};
  108. };
  109. } // namespace gpu
  110. #endif // GPU_IPC_SERVICE_STREAM_TEXTURE_ANDROID_H_