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 #include "cc/output/copy_output_request.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/single_release_callback.h"
13 #include "cc/resources/texture_mailbox.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
19 scoped_ptr
<CopyOutputRequest
> CopyOutputRequest::CreateRelayRequest(
20 const CopyOutputRequest
& original_request
,
21 const CopyOutputRequestCallback
& result_callback
) {
22 scoped_ptr
<CopyOutputRequest
> relay
= CreateRequest(result_callback
);
23 relay
->force_bitmap_result_
= original_request
.force_bitmap_result_
;
24 relay
->has_area_
= original_request
.has_area_
;
25 relay
->area_
= original_request
.area_
;
26 relay
->has_texture_mailbox_
= original_request
.has_texture_mailbox_
;
27 relay
->texture_mailbox_
= original_request
.texture_mailbox_
;
31 CopyOutputRequest::CopyOutputRequest() {}
33 CopyOutputRequest::CopyOutputRequest(
34 bool force_bitmap_result
,
35 const CopyOutputRequestCallback
& result_callback
)
36 : force_bitmap_result_(force_bitmap_result
),
38 has_texture_mailbox_(false),
39 result_callback_(result_callback
) {
40 DCHECK(!result_callback_
.is_null());
41 TRACE_EVENT_ASYNC_BEGIN0("cc", "CopyOutputRequest", this);
44 CopyOutputRequest::~CopyOutputRequest() {
45 if (!result_callback_
.is_null())
46 SendResult(CopyOutputResult::CreateEmptyResult().Pass());
49 void CopyOutputRequest::SendResult(scoped_ptr
<CopyOutputResult
> result
) {
50 base::ResetAndReturn(&result_callback_
).Run(result
.Pass());
51 TRACE_EVENT_ASYNC_END0("cc", "CopyOutputRequest", this);
54 void CopyOutputRequest::SendEmptyResult() {
55 SendResult(CopyOutputResult::CreateEmptyResult().Pass());
58 void CopyOutputRequest::SendBitmapResult(scoped_ptr
<SkBitmap
> bitmap
) {
59 SendResult(CopyOutputResult::CreateBitmapResult(bitmap
.Pass()).Pass());
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()));
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
;