1// Copyright 2014 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 CC_SURFACES_SURFACE_H_
6#define CC_SURFACES_SURFACE_H_
7
8#include <vector>
9
10#include "base/callback.h"
11#include "base/containers/hash_tables.h"
12#include "base/macros.h"
13#include "base/memory/scoped_ptr.h"
14#include "cc/base/scoped_ptr_vector.h"
15#include "cc/output/copy_output_request.h"
16#include "cc/surfaces/surface_id.h"
17#include "cc/surfaces/surfaces_export.h"
18#include "ui/gfx/size.h"
19
20namespace ui {
21struct LatencyInfo;
22}
23
24namespace cc {
25class CompositorFrame;
26class CopyOutputRequest;
27class SurfaceManager;
28class SurfaceFactory;
29class SurfaceResourceHolder;
30
31class CC_SURFACES_EXPORT Surface {
32 public:
33  Surface(SurfaceId id, const gfx::Size& size, SurfaceFactory* factory);
34  ~Surface();
35
36  const gfx::Size& size() const { return size_; }
37  SurfaceId surface_id() const { return surface_id_; }
38
39  void QueueFrame(scoped_ptr<CompositorFrame> frame,
40                  const base::Closure& draw_callback);
41  void RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> copy_request);
42  void TakeCopyOutputRequests(
43      ScopedPtrVector<CopyOutputRequest>* copy_requests);
44  // Returns the most recent frame that is eligible to be rendered.
45  const CompositorFrame* GetEligibleFrame();
46
47  // Returns a number that increments by 1 every time a new frame is enqueued.
48  int frame_index() const { return frame_index_; }
49
50  void TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info);
51  void RunDrawCallbacks();
52
53  SurfaceFactory* factory() { return factory_; }
54
55 private:
56  SurfaceId surface_id_;
57  gfx::Size size_;
58  SurfaceFactory* factory_;
59  // TODO(jamesr): Support multiple frames in flight.
60  scoped_ptr<CompositorFrame> current_frame_;
61  int frame_index_;
62  ScopedPtrVector<CopyOutputRequest> copy_requests_;
63
64  base::Closure draw_callback_;
65
66  DISALLOW_COPY_AND_ASSIGN(Surface);
67};
68
69}  // namespace cc
70
71#endif  // CC_SURFACES_SURFACE_H_
72