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/discardable_image_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"
33 class ContentLayerClient
;
35 class CC_EXPORT Picture
36 : public base::RefCountedThreadSafe
<Picture
> {
38 static scoped_refptr
<Picture
> Create(
39 const gfx::Rect
& layer_rect
,
40 ContentLayerClient
* client
,
41 const gfx::Size
& tile_grid_size
,
42 bool gather_discardable_images
,
43 RecordingSource::RecordingMode recording_mode
);
44 static scoped_refptr
<Picture
> CreateFromValue(const base::Value
* value
);
45 static scoped_refptr
<Picture
> CreateFromSkpValue(const base::Value
* value
);
47 gfx::Rect
LayerRect() const { return layer_rect_
; }
49 // Has Record() been called yet?
50 bool HasRecording() const { return picture_
.get() != NULL
; }
52 bool IsSuitableForGpuRasterization(const char** reason
) const;
53 int ApproximateOpCount() const;
54 size_t ApproximateMemoryUsage() const;
55 bool ShouldBeAnalyzedForSolidColor() const;
59 // Apply this scale and raster the negated region into the canvas.
60 // |negated_content_region| specifies the region to be clipped out of the
61 // raster operation, i.e., the parts of the canvas which will not get drawn
63 int Raster(SkCanvas
* canvas
,
64 SkPicture::AbortCallback
* callback
,
65 const Region
& negated_content_region
,
66 float contents_scale
) const;
68 // Draw the picture directly into the given canvas, without applying any
69 // clip/scale/layer transformations.
70 void Replay(SkCanvas
* canvas
, SkPicture::AbortCallback
* callback
= NULL
);
72 scoped_ptr
<base::Value
> AsValue() const;
74 void EmitTraceSnapshot() const;
75 void EmitTraceSnapshotAlias(Picture
* original
) const;
77 bool WillPlayBackBitmaps() const { return picture_
->willPlayBackBitmaps(); }
79 DiscardableImageMap::Iterator
GetDiscardableImageMapIterator(
80 const gfx::Rect
& layer_rect
) const;
83 Picture(const gfx::Rect
& layer_rect
, const gfx::Size
& tile_grid_size
);
84 // This constructor assumes SkPicture is already ref'd and transfers
85 // ownership to this picture.
86 Picture(const skia::RefPtr
<SkPicture
>&,
87 const gfx::Rect
& layer_rect
,
88 const DiscardableImageMap
& images
);
89 // This constructor will call AdoptRef on the SkPicture.
90 Picture(SkPicture
*, const gfx::Rect
& layer_rect
);
93 // Record a paint operation. To be able to safely use this SkPicture for
94 // playback on a different thread this can only be called once.
95 void Record(ContentLayerClient
* client
,
96 RecordingSource::RecordingMode recording_mode
);
98 // Gather discardable images from recording.
99 void GatherDiscardableImages();
101 gfx::Rect layer_rect_
;
102 skia::RefPtr
<SkPicture
> picture_
;
104 DiscardableImageMap images_
;
106 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
107 AsTraceableRasterData(float scale
) const;
108 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
109 AsTraceableRecordData() const;
111 friend class base::RefCountedThreadSafe
<Picture
>;
112 friend class DiscardableImageMap::Iterator
;
113 DISALLOW_COPY_AND_ASSIGN(Picture
);
118 #endif // CC_PLAYBACK_PICTURE_H_