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;
57 bool ShouldBeAnalyzedForSolidColor() const;
61 // Apply this scale and raster the negated region into the canvas.
62 // |negated_content_region| specifies the region to be clipped out of the
63 // raster operation, i.e., the parts of the canvas which will not get drawn
65 int Raster(SkCanvas
* canvas
,
66 SkPicture::AbortCallback
* callback
,
67 const Region
& negated_content_region
,
68 float contents_scale
) const;
70 // Draw the picture directly into the given canvas, without applying any
71 // clip/scale/layer transformations.
72 void Replay(SkCanvas
* canvas
, SkPicture::AbortCallback
* callback
= NULL
);
74 scoped_ptr
<base::Value
> AsValue() const;
76 void EmitTraceSnapshot() const;
77 void EmitTraceSnapshotAlias(Picture
* original
) const;
79 bool WillPlayBackBitmaps() const { return picture_
->willPlayBackBitmaps(); }
81 PixelRefMap::Iterator
GetPixelRefMapIterator(
82 const gfx::Rect
& layer_rect
) const;
85 Picture(const gfx::Rect
& layer_rect
, const gfx::Size
& tile_grid_size
);
86 // This constructor assumes SkPicture is already ref'd and transfers
87 // ownership to this picture.
88 Picture(const skia::RefPtr
<SkPicture
>&,
89 const gfx::Rect
& layer_rect
,
90 const PixelRefMap
& pixel_refs
);
91 // This constructor will call AdoptRef on the SkPicture.
92 Picture(SkPicture
*, const gfx::Rect
& layer_rect
);
95 // Record a paint operation. To be able to safely use this SkPicture for
96 // playback on a different thread this can only be called once.
97 void Record(ContentLayerClient
* client
,
98 RecordingSource::RecordingMode recording_mode
);
100 // Gather pixel refs from recording.
101 void GatherPixelRefs();
103 gfx::Rect layer_rect_
;
104 skia::RefPtr
<SkPicture
> picture_
;
106 PixelRefMap pixel_refs_
;
108 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
109 AsTraceableRasterData(float scale
) const;
110 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
111 AsTraceableRecordData() const;
113 friend class base::RefCountedThreadSafe
<Picture
>;
114 friend class PixelRefMap::Iterator
;
115 DISALLOW_COPY_AND_ASSIGN(Picture
);
120 #endif // CC_PLAYBACK_PICTURE_H_