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_OUTPUT_COPY_OUTPUT_REQUEST_H_ 6 #define CC_OUTPUT_COPY_OUTPUT_REQUEST_H_ 7 8 #include "base/callback.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "cc/base/cc_export.h" 11 #include "ui/gfx/rect.h" 12 13 class SkBitmap; 14 15 namespace cc { 16 class CopyOutputResult; 17 class TextureMailbox; 18 19 class CC_EXPORT CopyOutputRequest { 20 public: 21 typedef base::Callback<void(scoped_ptr<CopyOutputResult> result)> 22 CopyOutputRequestCallback; 23 24 static scoped_ptr<CopyOutputRequest> CreateEmptyRequest() { 25 return make_scoped_ptr(new CopyOutputRequest); 26 } 27 static scoped_ptr<CopyOutputRequest> CreateRequest( 28 const CopyOutputRequestCallback& result_callback) { 29 return make_scoped_ptr(new CopyOutputRequest(false, result_callback)); 30 } 31 static scoped_ptr<CopyOutputRequest> CreateBitmapRequest( 32 const CopyOutputRequestCallback& result_callback) { 33 return make_scoped_ptr(new CopyOutputRequest(true, result_callback)); 34 } 35 static scoped_ptr<CopyOutputRequest> CreateRelayRequest( 36 const CopyOutputRequest& original_request, 37 const CopyOutputRequestCallback& result_callback) { 38 scoped_ptr<CopyOutputRequest> relay = CreateRequest(result_callback); 39 relay->force_bitmap_result_ = original_request.force_bitmap_result_; 40 relay->has_area_ = original_request.has_area_; 41 relay->area_ = original_request.area_; 42 return relay.Pass(); 43 } 44 45 ~CopyOutputRequest(); 46 47 bool IsEmpty() const { return result_callback_.is_null(); } 48 49 bool force_bitmap_result() const { return force_bitmap_result_; } 50 51 // By default copy requests copy the entire layer's subtree output. If an 52 // area is given, then the intersection of this rect (in layer space) with 53 // the layer's subtree output will be returned. 54 void set_area(gfx::Rect area) { 55 has_area_ = true; 56 area_ = area; 57 } 58 bool has_area() const { return has_area_; } 59 gfx::Rect area() const { return area_; } 60 61 void SendEmptyResult(); 62 void SendBitmapResult(scoped_ptr<SkBitmap> bitmap); 63 void SendTextureResult(gfx::Size size, 64 scoped_ptr<TextureMailbox> texture_mailbox); 65 66 void SendResult(scoped_ptr<CopyOutputResult> result); 67 68 bool Equals(const CopyOutputRequest& other) const { 69 return result_callback_.Equals(other.result_callback_) && 70 force_bitmap_result_ == other.force_bitmap_result_; 71 } 72 73 private: 74 CopyOutputRequest(); 75 explicit CopyOutputRequest(bool force_bitmap_result, 76 const CopyOutputRequestCallback& result_callback); 77 78 bool force_bitmap_result_; 79 bool has_area_; 80 gfx::Rect area_; 81 CopyOutputRequestCallback result_callback_; 82 }; 83 84 } // namespace cc 85 86 #endif // CC_OUTPUT_COPY_OUTPUT_REQUEST_H_ 87