Evict resources from resource pool after timeout
[chromium-blink-merge.git] / cc / output / copy_output_request.h
blobc634db44dda1574da83dbac6a036037123cd971e
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 #ifndef CC_OUTPUT_COPY_OUTPUT_REQUEST_H_
6 #define CC_OUTPUT_COPY_OUTPUT_REQUEST_H_
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "cc/base/cc_export.h"
11 #include "cc/resources/single_release_callback.h"
12 #include "cc/resources/texture_mailbox.h"
13 #include "ui/gfx/geometry/rect.h"
15 class SkBitmap;
17 namespace cc {
18 class CopyOutputResult;
20 class CC_EXPORT CopyOutputRequest {
21 public:
22 typedef base::Callback<void(scoped_ptr<CopyOutputResult> result)>
23 CopyOutputRequestCallback;
25 static scoped_ptr<CopyOutputRequest> CreateEmptyRequest() {
26 return make_scoped_ptr(new CopyOutputRequest);
28 static scoped_ptr<CopyOutputRequest> CreateRequest(
29 const CopyOutputRequestCallback& result_callback) {
30 return make_scoped_ptr(new CopyOutputRequest(false, result_callback));
32 static scoped_ptr<CopyOutputRequest> CreateBitmapRequest(
33 const CopyOutputRequestCallback& result_callback) {
34 return make_scoped_ptr(new CopyOutputRequest(true, result_callback));
36 static scoped_ptr<CopyOutputRequest> CreateRelayRequest(
37 const CopyOutputRequest& original_request,
38 const CopyOutputRequestCallback& result_callback);
40 ~CopyOutputRequest();
42 bool IsEmpty() const { return result_callback_.is_null(); }
44 // Optionally specify the source of this copy request. If set when this copy
45 // request is submitted to a layer, a prior uncommitted copy request from the
46 // same |source| will be aborted.
47 void set_source(void* source) { source_ = source; }
48 void* source() const { return source_; }
50 bool force_bitmap_result() const { return force_bitmap_result_; }
52 // By default copy requests copy the entire layer's subtree output. If an
53 // area is given, then the intersection of this rect (in layer space) with
54 // the layer's subtree output will be returned.
55 void set_area(const gfx::Rect& area) {
56 has_area_ = true;
57 area_ = area;
59 bool has_area() const { return has_area_; }
60 gfx::Rect area() const { return area_; }
62 // By default copy requests create a new TextureMailbox to return contents
63 // in. This allows a client to provide a TextureMailbox, and the compositor
64 // will place the result inside the TextureMailbox.
65 void SetTextureMailbox(const TextureMailbox& texture_mailbox);
66 bool has_texture_mailbox() const { return has_texture_mailbox_; }
67 const TextureMailbox& texture_mailbox() const { return texture_mailbox_; }
69 void SendEmptyResult();
70 void SendBitmapResult(scoped_ptr<SkBitmap> bitmap);
71 void SendTextureResult(const gfx::Size& size,
72 const TextureMailbox& texture_mailbox,
73 scoped_ptr<SingleReleaseCallback> release_callback);
75 void SendResult(scoped_ptr<CopyOutputResult> result);
77 private:
78 CopyOutputRequest();
79 CopyOutputRequest(bool force_bitmap_result,
80 const CopyOutputRequestCallback& result_callback);
82 void* source_;
83 bool force_bitmap_result_;
84 bool has_area_;
85 bool has_texture_mailbox_;
86 gfx::Rect area_;
87 TextureMailbox texture_mailbox_;
88 CopyOutputRequestCallback result_callback_;
91 } // namespace cc
93 #endif // CC_OUTPUT_COPY_OUTPUT_REQUEST_H_