summaryrefslogtreecommitdiffstats
path: root/cc/picture.h
blob: f64c6e84916aa12344522f7b12baf86aed396ac3 (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
// Copyright 2012 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_PICTURE_H_
#define CC_PICTURE_H_

#include <list>

#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "cc/cc_export.h"
#include "skia/ext/lazy_pixel_ref.h"
#include "skia/ext/refptr.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkPixelRef.h"
#include "ui/gfx/rect.h"

namespace cc {

class ContentLayerClient;
struct RenderingStats;

class CC_EXPORT Picture
    : public base::RefCountedThreadSafe<Picture> {
 public:
  static scoped_refptr<Picture> Create(gfx::Rect layer_rect);

  const gfx::Rect& LayerRect() const { return layer_rect_; }
  const gfx::Rect& OpaqueRect() const { return opaque_rect_; }

  // Make a thread-safe clone for rasterizing with.
  scoped_refptr<Picture> Clone() const;

  // Record a paint operation. To be able to safely use this SkPicture for
  // playback on a different thread this can only be called once.
  void Record(ContentLayerClient*, RenderingStats&);

  // Has Record() been called yet?
  bool HasRecording() const { return picture_.get() != NULL; }

  // Apply this contents scale and raster the content rect into the canvas.
  void Raster(SkCanvas* canvas, gfx::Rect content_rect, float contents_scale);

  bool IsCheapInRect(const gfx::Rect& layer_rect);

  void GatherPixelRefs(
      const gfx::Rect& layer_rect,
      std::list<skia::LazyPixelRef*>& pixel_ref_list);

 private:
  Picture(gfx::Rect layer_rect);
  // This constructor assumes SkPicture is already ref'd and transfers
  // ownership to this picture.
  Picture(const skia::RefPtr<SkPicture>&,
          gfx::Rect layer_rect,
          gfx::Rect opaque_rect);
  ~Picture();

  gfx::Rect layer_rect_;
  gfx::Rect opaque_rect_;
  skia::RefPtr<SkPicture> picture_;

  friend class base::RefCountedThreadSafe<Picture>;
  DISALLOW_COPY_AND_ASSIGN(Picture);
};

}  // namespace cc

#endif  // CC_PICTURE_H_