frame_evictor.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2017 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 COMPONENTS_VIZ_CLIENT_FRAME_EVICTOR_H_
  5. #define COMPONENTS_VIZ_CLIENT_FRAME_EVICTOR_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "components/viz/client/frame_eviction_manager.h"
  8. namespace viz {
  9. class FrameEvictorClient {
  10. public:
  11. virtual ~FrameEvictorClient() {}
  12. virtual void EvictDelegatedFrame() = 0;
  13. };
  14. // Keeps track of the visibility state of a child and notifies when the parent
  15. // needs to drop its surface.
  16. class VIZ_CLIENT_EXPORT FrameEvictor : public FrameEvictionManagerClient {
  17. public:
  18. explicit FrameEvictor(FrameEvictorClient* client);
  19. FrameEvictor(const FrameEvictor&) = delete;
  20. FrameEvictor& operator=(const FrameEvictor&) = delete;
  21. ~FrameEvictor() override;
  22. // Called when the parent allocates a new LocalSurfaceId for this child and
  23. // embeds it.
  24. void OnNewSurfaceEmbedded();
  25. // Called when the parent stops embedding the child's surface and evicts it.
  26. void OnSurfaceDiscarded();
  27. // Returns whether the parent is currently embedding a surface of this child.
  28. bool has_surface() const { return has_surface_; }
  29. // Notifies that the visibility state of the child has changed.
  30. void SetVisible(bool visible);
  31. bool visible() const { return visible_; }
  32. private:
  33. // FrameEvictionManagerClient implementation.
  34. void EvictCurrentFrame() override;
  35. raw_ptr<FrameEvictorClient> client_;
  36. bool has_surface_ = false;
  37. bool visible_ = false;
  38. };
  39. } // namespace viz
  40. #endif // COMPONENTS_VIZ_CLIENT_FRAME_EVICTOR_H_