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_
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"
30 class CompositorFrame
;
31 class CopyOutputRequest
;
34 class SurfaceResourceHolder
;
36 class CC_SURFACES_EXPORT Surface
{
38 using DrawCallback
= SurfaceFactory::DrawCallback
;
40 Surface(SurfaceId id
, SurfaceFactory
* factory
);
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
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 base::hash_set
<uint32_t>* valid_id_namespaces
);
72 size_t GetDestructionDependencyCount() const {
73 return destruction_dependencies_
.size();
76 const std::vector
<SurfaceId
>& referenced_surfaces() const {
77 return referenced_surfaces_
;
80 bool destroyed() const { return destroyed_
; }
81 void set_destroyed(bool destroyed
) { destroyed_
= destroyed
; }
84 void ClearCopyRequests();
86 SurfaceId surface_id_
;
87 base::WeakPtr
<SurfaceFactory
> factory_
;
88 // TODO(jamesr): Support multiple frames in flight.
89 scoped_ptr
<CompositorFrame
> current_frame_
;
92 std::vector
<SurfaceSequence
> destruction_dependencies_
;
94 std::vector
<SurfaceId
> referenced_surfaces_
;
96 DrawCallback draw_callback_
;
98 DISALLOW_COPY_AND_ASSIGN(Surface
);
103 #endif // CC_SURFACES_SURFACE_H_