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/debug/trace_event.h" 10 #include "base/logging.h" 11 #include "cc/output/copy_output_result.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 DCHECK(!result_callback_.is_null()); 40 TRACE_EVENT_ASYNC_BEGIN0("cc", "CopyOutputRequest", this); 41 } 42 43 CopyOutputRequest::~CopyOutputRequest() { 44 if (!result_callback_.is_null()) 45 SendResult(CopyOutputResult::CreateEmptyResult().Pass()); 46 } 47 48 void CopyOutputRequest::SendResult(scoped_ptr<CopyOutputResult> result) { 49 bool success = !result->IsEmpty(); 50 base::ResetAndReturn(&result_callback_).Run(result.Pass()); 51 TRACE_EVENT_ASYNC_END1("cc", "CopyOutputRequest", this, "success", success); 52 } 53 54 void CopyOutputRequest::SendEmptyResult() { 55 SendResult(CopyOutputResult::CreateEmptyResult().Pass()); 56 } 57 58 void CopyOutputRequest::SendBitmapResult(scoped_ptr<SkBitmap> bitmap) { 59 SendResult(CopyOutputResult::CreateBitmapResult(bitmap.Pass()).Pass()); 60 } 61 62 void CopyOutputRequest::SendTextureResult( 63 const gfx::Size& size, 64 const TextureMailbox& texture_mailbox, 65 scoped_ptr<SingleReleaseCallback> release_callback) { 66 DCHECK(texture_mailbox.IsTexture()); 67 SendResult(CopyOutputResult::CreateTextureResult( 68 size, texture_mailbox, release_callback.Pass())); 69 } 70 71 void CopyOutputRequest::SetTextureMailbox( 72 const TextureMailbox& texture_mailbox) { 73 DCHECK(!force_bitmap_result_); 74 DCHECK(texture_mailbox.IsTexture()); 75 has_texture_mailbox_ = true; 76 texture_mailbox_ = texture_mailbox; 77 } 78 79 } // namespace cc 80