Roll src/third_party/WebKit a1ed6cd:9e03af6 (svn 190836:190842)
[chromium-blink-merge.git] / cc / layers / delegated_frame_provider.h
blob3bcf91957c8a5d999f209e09c77ff68c56c96d7c
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_
8 #include <vector>
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_f.h"
16 #include "ui/gfx/geometry/size.h"
18 namespace cc {
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> {
29 public:
30 explicit DelegatedFrameProvider(
31 const scoped_refptr<DelegatedFrameResourceCollection>&
32 resource_collection,
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,
44 gfx::RectF* damage);
46 ReturnCallback GetReturnResourcesCallbackForImplThread();
47 void UnrefResourcesOnMainThread(const ReturnedResourceArray& unused);
49 gfx::Size frame_size() const { return frame_size_; }
51 private:
52 friend class base::RefCounted<DelegatedFrameProvider>;
53 ~DelegatedFrameProvider();
55 scoped_refptr<DelegatedFrameResourceCollection> resource_collection_;
57 scoped_ptr<DelegatedFrameData> frame_;
59 struct Observer {
60 DelegatedRendererLayer* layer;
61 gfx::RectF damage;
63 Observer(DelegatedRendererLayer* layer, const gfx::RectF& damage)
64 : layer(layer), damage(damage) {}
66 std::vector<Observer> observers_;
68 gfx::Size frame_size_;
70 DISALLOW_COPY_AND_ASSIGN(DelegatedFrameProvider);
73 } // namespace cc
75 #endif // CC_LAYERS_DELEGATED_FRAME_PROVIDER_H_