Roll src/third_party/skia 96e657d:4412465
[chromium-blink-merge.git] / cc / surfaces / surface.h
blob8e6d7a46cbf454876555dcf632527f4ee994169b
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.
5 #ifndef CC_SURFACES_SURFACE_H_
6 #define CC_SURFACES_SURFACE_H_
8 #include <map>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "cc/base/scoped_ptr_vector.h"
17 #include "cc/output/copy_output_request.h"
18 #include "cc/quads/render_pass_id.h"
19 #include "cc/surfaces/surface_factory.h"
20 #include "cc/surfaces/surface_id.h"
21 #include "cc/surfaces/surface_sequence.h"
22 #include "cc/surfaces/surfaces_export.h"
23 #include "ui/gfx/geometry/size.h"
25 namespace ui {
26 struct LatencyInfo;
29 namespace cc {
30 class CompositorFrame;
31 class CopyOutputRequest;
32 class SurfaceManager;
33 class SurfaceFactory;
34 class SurfaceResourceHolder;
36 class CC_SURFACES_EXPORT Surface {
37 public:
38 using DrawCallback = SurfaceFactory::DrawCallback;
40 Surface(SurfaceId id, SurfaceFactory* factory);
41 ~Surface();
43 SurfaceId surface_id() const { return surface_id_; }
45 void QueueFrame(scoped_ptr<CompositorFrame> frame,
46 const DrawCallback& draw_callback);
47 void RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> copy_request);
48 // Adds each CopyOutputRequest in the current frame to copy_requests. The
49 // caller takes ownership of them.
50 void TakeCopyOutputRequests(
51 std::multimap<RenderPassId, CopyOutputRequest*>* copy_requests);
52 // Returns the most recent frame that is eligible to be rendered.
53 const CompositorFrame* GetEligibleFrame();
55 // Returns a number that increments by 1 every time a new frame is enqueued.
56 int frame_index() const { return frame_index_; }
58 void TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info);
59 void RunDrawCallbacks(SurfaceDrawStatus drawn);
61 base::WeakPtr<SurfaceFactory> factory() { return factory_; }
63 // Add a SurfaceSequence that must be satisfied before the Surface is
64 // destroyed.
65 void AddDestructionDependency(SurfaceSequence sequence);
67 // Satisfy all destruction dependencies that are contained in sequences, and
68 // remove them from sequences.
69 void SatisfyDestructionDependencies(
70 base::hash_set<SurfaceSequence>* sequences);
71 size_t GetDestructionDependencyCount() const {
72 return destruction_dependencies_.size();
75 private:
76 void ClearCopyRequests();
78 SurfaceId surface_id_;
79 base::WeakPtr<SurfaceFactory> factory_;
80 // TODO(jamesr): Support multiple frames in flight.
81 scoped_ptr<CompositorFrame> current_frame_;
82 int frame_index_;
83 std::vector<SurfaceSequence> destruction_dependencies_;
85 DrawCallback draw_callback_;
87 DISALLOW_COPY_AND_ASSIGN(Surface);
90 } // namespace cc
92 #endif // CC_SURFACES_SURFACE_H_