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/logging.h"
10 #include "base/trace_event/trace_event.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"
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_
;
30 CopyOutputRequest::CopyOutputRequest() {}
32 CopyOutputRequest::CopyOutputRequest(
33 bool force_bitmap_result
,
34 const CopyOutputRequestCallback
& result_callback
)
35 : force_bitmap_result_(force_bitmap_result
),
37 has_texture_mailbox_(false),
38 result_callback_(result_callback
) {
39 DCHECK(!result_callback_
.is_null());
40 TRACE_EVENT_ASYNC_BEGIN0("cc", "CopyOutputRequest", this);
43 CopyOutputRequest::~CopyOutputRequest() {
44 if (!result_callback_
.is_null())
45 SendResult(CopyOutputResult::CreateEmptyResult().Pass());
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
);
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
;