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. 4 5 #ifndef CC_LAYERS_DELEGATED_FRAME_PROVIDER_H_ 6 #define CC_LAYERS_DELEGATED_FRAME_PROVIDER_H_ 7 8 #include <vector> 9 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/rect_f.h" 16 #include "ui/gfx/size.h" 17 18 namespace cc { 19 class DelegatedFrameData; 20 class DelegatedFrameResourceCollection; 21 class DelegatedRendererLayer; 22 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); 34 35 void AddObserver(DelegatedRendererLayer* layer); 36 void RemoveObserver(DelegatedRendererLayer* layer); 37 38 void SetFrameData(scoped_ptr<DelegatedFrameData> frame); 39 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); 45 46 ReturnCallback GetReturnResourcesCallbackForImplThread(); 47 void UnrefResourcesOnMainThread(const ReturnedResourceArray& unused); 48 frame_size()49 gfx::Size frame_size() const { return frame_size_; } 50 51 private: 52 friend class base::RefCounted<DelegatedFrameProvider>; 53 ~DelegatedFrameProvider(); 54 55 scoped_refptr<DelegatedFrameResourceCollection> resource_collection_; 56 57 scoped_ptr<DelegatedFrameData> frame_; 58 59 struct Observer { 60 DelegatedRendererLayer* layer; 61 gfx::RectF damage; 62 ObserverObserver63 Observer(DelegatedRendererLayer* layer, const gfx::RectF& damage) 64 : layer(layer), damage(damage) {} 65 }; 66 std::vector<Observer> observers_; 67 68 gfx::Size frame_size_; 69 70 DISALLOW_COPY_AND_ASSIGN(DelegatedFrameProvider); 71 }; 72 73 } // namespace cc 74 75 #endif // CC_LAYERS_DELEGATED_FRAME_PROVIDER_H_ 76