dcomp_texture_win.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright 2021 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_DCOMP_TEXTURE_WIN_H_
  5. #define GPU_IPC_SERVICE_DCOMP_TEXTURE_WIN_H_
  6. #include <stdint.h>
  7. #include "base/memory/raw_ptr.h"
  8. #include "base/memory/ref_counted.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "base/timer/timer.h"
  11. #include "base/unguessable_token.h"
  12. #include "gpu/command_buffer/service/shared_context_state.h"
  13. #include "gpu/ipc/common/gpu_channel.mojom.h"
  14. #include "gpu/ipc/service/command_buffer_stub.h"
  15. #include "mojo/public/cpp/bindings/associated_receiver.h"
  16. #include "mojo/public/cpp/bindings/associated_remote.h"
  17. #include "ui/gl/gl_image_dcomp_surface.h"
  18. namespace gfx {
  19. class Size;
  20. }
  21. namespace gpu {
  22. class GpuChannel;
  23. struct Mailbox;
  24. class DCOMPTexture : public gl::GLImageDCOMPSurface,
  25. public SharedContextState::ContextLostObserver,
  26. public mojom::DCOMPTexture {
  27. public:
  28. // A nullptr is returned if it fails to create one.
  29. static scoped_refptr<DCOMPTexture> Create(
  30. GpuChannel* channel,
  31. int route_id,
  32. mojo::PendingAssociatedReceiver<mojom::DCOMPTexture> receiver);
  33. // Cleans up related data and nulls |channel_|. Called when the channel
  34. // releases its ref on this class.
  35. void ReleaseChannel();
  36. private:
  37. DCOMPTexture(GpuChannel* channel,
  38. int32_t route_id,
  39. mojo::PendingAssociatedReceiver<mojom::DCOMPTexture> receiver,
  40. scoped_refptr<SharedContextState> context_state);
  41. DCOMPTexture(const DCOMPTexture&) = delete;
  42. DCOMPTexture& operator=(const DCOMPTexture&) = delete;
  43. ~DCOMPTexture() override;
  44. // gl::GLImage implementation is in gl::GLImageDCOMPSurface.
  45. // SharedContextState::ContextLostObserver implementation.
  46. void OnContextLost() override;
  47. // mojom::DCOMPTexture:
  48. void StartListening(
  49. mojo::PendingAssociatedRemote<mojom::DCOMPTextureClient> client) override;
  50. void SetTextureSize(const gfx::Size& size) override;
  51. void SetDCOMPSurfaceHandle(const base::UnguessableToken& token,
  52. SetDCOMPSurfaceHandleCallback callback) override;
  53. gpu::Mailbox CreateSharedImage();
  54. gfx::Rect GetParentWindowRect();
  55. void SetParentWindow(HWND parent) override;
  56. void OnUpdateParentWindowRect();
  57. void SetRect(const gfx::Rect& window_relative_rect) override;
  58. void SendOutputRect();
  59. bool IsContextValid() const override;
  60. bool context_lost_ = false;
  61. bool shared_image_mailbox_created_ = false;
  62. raw_ptr<GpuChannel> channel_ = nullptr;
  63. const int32_t route_id_;
  64. scoped_refptr<SharedContextState> context_state_;
  65. SequenceId sequence_;
  66. mojo::AssociatedReceiver<mojom::DCOMPTexture> receiver_;
  67. mojo::AssociatedRemote<mojom::DCOMPTextureClient> client_;
  68. gfx::Rect last_output_rect_;
  69. gfx::Rect parent_window_rect_;
  70. gfx::Rect window_relative_rect_;
  71. base::RepeatingTimer window_pos_timer_;
  72. base::WeakPtrFactory<DCOMPTexture> weak_factory_{this};
  73. };
  74. } // namespace gpu
  75. #endif // GPU_IPC_SERVICE_DCOMP_TEXTURE_WIN_H_