summaryrefslogtreecommitdiffstats
path: root/cc/output/copy_output_request.h
blob: c4a92481dbca566e42acf150f5a639f60c64628c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_OUTPUT_COPY_OUTPUT_REQUEST_H_
#define CC_OUTPUT_COPY_OUTPUT_REQUEST_H_

#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "cc/base/cc_export.h"
#include "ui/gfx/rect.h"

class SkBitmap;

namespace cc {
class CopyOutputResult;
class SingleReleaseCallback;
class TextureMailbox;

class CC_EXPORT CopyOutputRequest {
 public:
  typedef base::Callback<void(scoped_ptr<CopyOutputResult> result)>
      CopyOutputRequestCallback;

  static scoped_ptr<CopyOutputRequest> CreateEmptyRequest() {
    return make_scoped_ptr(new CopyOutputRequest);
  }
  static scoped_ptr<CopyOutputRequest> CreateRequest(
      const CopyOutputRequestCallback& result_callback) {
    return make_scoped_ptr(new CopyOutputRequest(false, result_callback));
  }
  static scoped_ptr<CopyOutputRequest> CreateBitmapRequest(
      const CopyOutputRequestCallback& result_callback) {
    return make_scoped_ptr(new CopyOutputRequest(true, result_callback));
  }
  static scoped_ptr<CopyOutputRequest> CreateRelayRequest(
      const CopyOutputRequest& original_request,
      const CopyOutputRequestCallback& result_callback) {
    scoped_ptr<CopyOutputRequest> relay = CreateRequest(result_callback);
    relay->force_bitmap_result_ = original_request.force_bitmap_result_;
    relay->has_area_ = original_request.has_area_;
    relay->area_ = original_request.area_;
    return relay.Pass();
  }

  ~CopyOutputRequest();

  bool IsEmpty() const { return result_callback_.is_null(); }

  bool force_bitmap_result() const { return force_bitmap_result_; }

  // By default copy requests copy the entire layer's subtree output. If an
  // area is given, then the intersection of this rect (in layer space) with
  // the layer's subtree output will be returned.
  void set_area(gfx::Rect area) {
    has_area_ = true;
    area_ = area;
  }
  bool has_area() const { return has_area_; }
  gfx::Rect area() const { return area_; }

  void SendEmptyResult();
  void SendBitmapResult(scoped_ptr<SkBitmap> bitmap);
  void SendTextureResult(gfx::Size size,
                         const TextureMailbox& texture_mailbox,
                         scoped_ptr<SingleReleaseCallback> release_callback);

  void SendResult(scoped_ptr<CopyOutputResult> result);

  bool Equals(const CopyOutputRequest& other) const {
    return result_callback_.Equals(other.result_callback_) &&
        force_bitmap_result_ == other.force_bitmap_result_;
  }

 private:
  CopyOutputRequest();
  explicit CopyOutputRequest(bool force_bitmap_result,
                             const CopyOutputRequestCallback& result_callback);

  bool force_bitmap_result_;
  bool has_area_;
  gfx::Rect area_;
  CopyOutputRequestCallback result_callback_;
};

}  // namespace cc

#endif  // CC_OUTPUT_COPY_OUTPUT_REQUEST_H_