1 // Copyright 2013 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_LAYERS_DELEGATED_FRAME_PROVIDER_H_
6 #define CC_LAYERS_DELEGATED_FRAME_PROVIDER_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "cc/base/cc_export.h"
13 #include "cc/resources/return_callback.h"
14 #include "cc/resources/returned_resource.h"
15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/size.h"
19 class DelegatedFrameData
;
20 class DelegatedFrameResourceCollection
;
21 class DelegatedRendererLayer
;
23 // Only one observing layer has ownership of the DelegatedFrameProvider. Only
24 // the active observer should call GetFrameDataAndRefResources(). All frames
25 // provided by a single DelegatedFrameProvider must have the same size. A new
26 // provider must be used for frames of a different size.
27 class CC_EXPORT DelegatedFrameProvider
28 : public base::RefCounted
<DelegatedFrameProvider
> {
30 explicit DelegatedFrameProvider(
31 const scoped_refptr
<DelegatedFrameResourceCollection
>&
33 scoped_ptr
<DelegatedFrameData
> frame
);
35 void AddObserver(DelegatedRendererLayer
* layer
);
36 void RemoveObserver(DelegatedRendererLayer
* layer
);
38 void SetFrameData(scoped_ptr
<DelegatedFrameData
> frame
);
40 // The DelegatedFrameData returned here must be displayed in order to not
41 // lose track of damage.
42 DelegatedFrameData
* GetFrameDataAndRefResources(
43 DelegatedRendererLayer
* observer
,
46 ReturnCallback
GetReturnResourcesCallbackForImplThread();
47 void UnrefResourcesOnMainThread(const ReturnedResourceArray
& unused
);
49 gfx::Size
frame_size() const { return frame_size_
; }
52 friend class base::RefCounted
<DelegatedFrameProvider
>;
53 ~DelegatedFrameProvider();
55 scoped_refptr
<DelegatedFrameResourceCollection
> resource_collection_
;
57 scoped_ptr
<DelegatedFrameData
> frame_
;
60 DelegatedRendererLayer
* layer
;
63 Observer(DelegatedRendererLayer
* layer
, const gfx::Rect
& damage
)
64 : layer(layer
), damage(damage
) {}
66 std::vector
<Observer
> observers_
;
68 gfx::Size frame_size_
;
70 DISALLOW_COPY_AND_ASSIGN(DelegatedFrameProvider
);
75 #endif // CC_LAYERS_DELEGATED_FRAME_PROVIDER_H_