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 #include "cc/output/copy_output_request.h" 6 7 #include "base/bind.h" 8 #include "base/callback_helpers.h" 9 #include "base/logging.h" 10 #include "cc/output/copy_output_result.h" 11 #include "cc/resources/single_release_callback.h" 12 #include "cc/resources/texture_mailbox.h" 13 #include "third_party/skia/include/core/SkBitmap.h" 14 15 namespace cc { 16 17 // static 18 scoped_ptr<CopyOutputRequest> CopyOutputRequest::CreateRelayRequest( 19 const CopyOutputRequest& original_request, 20 const CopyOutputRequestCallback& result_callback) { 21 scoped_ptr<CopyOutputRequest> relay = CreateRequest(result_callback); 22 relay->force_bitmap_result_ = original_request.force_bitmap_result_; 23 relay->has_area_ = original_request.has_area_; 24 relay->area_ = original_request.area_; 25 relay->has_texture_mailbox_ = original_request.has_texture_mailbox_; 26 relay->texture_mailbox_ = original_request.texture_mailbox_; 27 return relay.Pass(); 28 } 29 30 CopyOutputRequest::CopyOutputRequest() {} 31 32 CopyOutputRequest::CopyOutputRequest( 33 bool force_bitmap_result, 34 const CopyOutputRequestCallback& result_callback) 35 : force_bitmap_result_(force_bitmap_result), 36 has_area_(false), 37 has_texture_mailbox_(false), 38 result_callback_(result_callback) {} 39 40 CopyOutputRequest::~CopyOutputRequest() { 41 if (!result_callback_.is_null()) 42 SendResult(CopyOutputResult::CreateEmptyResult().Pass()); 43 } 44 45 void CopyOutputRequest::SendResult(scoped_ptr<CopyOutputResult> result) { 46 base::ResetAndReturn(&result_callback_).Run(result.Pass()); 47 } 48 49 void CopyOutputRequest::SendEmptyResult() { 50 SendResult(CopyOutputResult::CreateEmptyResult().Pass()); 51 } 52 53 void CopyOutputRequest::SendBitmapResult(scoped_ptr<SkBitmap> bitmap) { 54 SendResult(CopyOutputResult::CreateBitmapResult(bitmap.Pass()).Pass()); 55 } 56 57 void CopyOutputRequest::SendTextureResult( 58 gfx::Size size, 59 const TextureMailbox& texture_mailbox, 60 scoped_ptr<SingleReleaseCallback> release_callback) { 61 DCHECK(texture_mailbox.IsTexture()); 62 SendResult(CopyOutputResult::CreateTextureResult( 63 size, texture_mailbox, release_callback.Pass())); 64 } 65 66 void CopyOutputRequest::SetTextureMailbox( 67 const TextureMailbox& texture_mailbox) { 68 DCHECK(!force_bitmap_result_); 69 DCHECK(texture_mailbox.IsTexture()); 70 has_texture_mailbox_ = true; 71 texture_mailbox_ = texture_mailbox; 72 } 73 74 } // namespace cc 75