1 // Copyright 2012 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_PLAYBACK_PICTURE_H_
6 #define CC_PLAYBACK_PICTURE_H_
8 #include "base/basictypes.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/lazy_instance.h"
11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/trace_event/trace_event.h"
15 #include "cc/base/cc_export.h"
16 #include "cc/base/region.h"
17 #include "cc/playback/pixel_ref_map.h"
18 #include "cc/playback/recording_source.h"
19 #include "skia/ext/refptr.h"
20 #include "third_party/skia/include/core/SkPicture.h"
21 #include "ui/gfx/geometry/rect.h"
35 class ContentLayerClient
;
37 class CC_EXPORT Picture
38 : public base::RefCountedThreadSafe
<Picture
> {
40 static scoped_refptr
<Picture
> Create(
41 const gfx::Rect
& layer_rect
,
42 ContentLayerClient
* client
,
43 const gfx::Size
& tile_grid_size
,
44 bool gather_pixels_refs
,
45 RecordingSource::RecordingMode recording_mode
);
46 static scoped_refptr
<Picture
> CreateFromValue(const base::Value
* value
);
47 static scoped_refptr
<Picture
> CreateFromSkpValue(const base::Value
* value
);
49 gfx::Rect
LayerRect() const { return layer_rect_
; }
51 // Has Record() been called yet?
52 bool HasRecording() const { return picture_
.get() != NULL
; }
54 bool IsSuitableForGpuRasterization(const char** reason
) const;
55 int ApproximateOpCount() const;
56 size_t ApproximateMemoryUsage() const;
60 // Apply this scale and raster the negated region into the canvas.
61 // |negated_content_region| specifies the region to be clipped out of the
62 // raster operation, i.e., the parts of the canvas which will not get drawn
64 int Raster(SkCanvas
* canvas
,
65 SkPicture::AbortCallback
* callback
,
66 const Region
& negated_content_region
,
67 float contents_scale
) const;
69 // Draw the picture directly into the given canvas, without applying any
70 // clip/scale/layer transformations.
71 void Replay(SkCanvas
* canvas
, SkPicture::AbortCallback
* callback
= NULL
);
73 scoped_ptr
<base::Value
> AsValue() const;
75 void EmitTraceSnapshot() const;
76 void EmitTraceSnapshotAlias(Picture
* original
) const;
78 bool WillPlayBackBitmaps() const { return picture_
->willPlayBackBitmaps(); }
80 PixelRefMap::Iterator
GetPixelRefMapIterator(
81 const gfx::Rect
& layer_rect
) const;
84 Picture(const gfx::Rect
& layer_rect
, const gfx::Size
& tile_grid_size
);
85 // This constructor assumes SkPicture is already ref'd and transfers
86 // ownership to this picture.
87 Picture(const skia::RefPtr
<SkPicture
>&,
88 const gfx::Rect
& layer_rect
,
89 const PixelRefMap
& pixel_refs
);
90 // This constructor will call AdoptRef on the SkPicture.
91 Picture(SkPicture
*, const gfx::Rect
& layer_rect
);
94 // Record a paint operation. To be able to safely use this SkPicture for
95 // playback on a different thread this can only be called once.
96 void Record(ContentLayerClient
* client
,
97 RecordingSource::RecordingMode recording_mode
);
99 // Gather pixel refs from recording.
100 void GatherPixelRefs();
102 gfx::Rect layer_rect_
;
103 skia::RefPtr
<SkPicture
> picture_
;
105 PixelRefMap pixel_refs_
;
107 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
108 AsTraceableRasterData(float scale
) const;
109 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
110 AsTraceableRecordData() const;
112 friend class base::RefCountedThreadSafe
<Picture
>;
113 friend class PixelRefMap::Iterator
;
114 DISALLOW_COPY_AND_ASSIGN(Picture
);
119 #endif // CC_PLAYBACK_PICTURE_H_