summaryrefslogtreecommitdiffstats
path: root/chromium/cc/surfaces/surface.h
blob: 007f33d10a252a8c19ff2b59c37a5836288809a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_SURFACES_SURFACE_H_
#define CC_SURFACES_SURFACE_H_

#include "base/containers/hash_tables.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "cc/resources/resource_provider.h"
#include "cc/resources/return_callback.h"
#include "cc/surfaces/surface_client.h"
#include "cc/surfaces/surface_id.h"
#include "cc/surfaces/surfaces_export.h"
#include "ui/gfx/size.h"

namespace cc {
class CompositorFrame;
class SurfaceManager;

class CC_SURFACES_EXPORT Surface {
 public:
  Surface(SurfaceManager* manager,
          SurfaceClient* client,
          const gfx::Size& size);
  ~Surface();

  const gfx::Size& size() const { return size_; }
  SurfaceId surface_id() const { return surface_id_; }

  void QueueFrame(scoped_ptr<CompositorFrame> frame);
  // Returns the most recent frame that is eligible to be rendered.
  CompositorFrame* GetEligibleFrame();

  // Takes a reference to all of the current frame's resources for an external
  // consumer (e.g. a ResourceProvider). The caller to this should call
  // UnrefResources() when they are done with the resources.
  void RefCurrentFrameResources();
  void UnrefResources(const ReturnedResourceArray& resources);

  // Returns all resources that are currently not in use to the client.
  void ReturnUnusedResourcesToClient();

 private:
  void ReceiveResourcesFromClient(const TransferableResourceArray& resources);

  SurfaceManager* manager_;
  SurfaceClient* client_;
  gfx::Size size_;
  SurfaceId surface_id_;
  // TODO(jamesr): Support multiple frames in flight.
  scoped_ptr<CompositorFrame> current_frame_;

  struct ResourceRefs {
    ResourceRefs();

    int refs_received_from_child;
    int refs_holding_resource_alive;
  };
  // Keeps track of the number of users currently in flight for each resource
  // ID we've received from the client. When this counter hits zero for a
  // particular resource, that ID is available to return to the client.
  typedef base::hash_map<ResourceProvider::ResourceId, ResourceRefs>
      ResourceIdCountMap;
  ResourceIdCountMap resource_id_use_count_map_;

  ReturnedResourceArray resources_available_to_return_;

  DISALLOW_COPY_AND_ASSIGN(Surface);
};

}  // namespace cc

#endif  // CC_SURFACES_SURFACE_H_