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