OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_RESOURCES_PICTURE_H_ | 5 #ifndef CC_RESOURCES_PICTURE_H_ |
6 #define CC_RESOURCES_PICTURE_H_ | 6 #define CC_RESOURCES_PICTURE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
19 #include "cc/base/cc_export.h" | 19 #include "cc/base/cc_export.h" |
20 #include "cc/base/region.h" | 20 #include "cc/base/region.h" |
| 21 #include "cc/resources/recording_source.h" |
21 #include "skia/ext/refptr.h" | 22 #include "skia/ext/refptr.h" |
22 #include "third_party/skia/include/core/SkPicture.h" | 23 #include "third_party/skia/include/core/SkPicture.h" |
23 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
24 | 25 |
25 class SkDrawPictureCallback; | 26 class SkDrawPictureCallback; |
26 class SkPixelRef; | 27 class SkPixelRef; |
27 | 28 |
28 namespace base { | 29 namespace base { |
29 class Value; | 30 class Value; |
30 } | 31 } |
31 | 32 |
32 namespace skia { | 33 namespace skia { |
33 class AnalysisCanvas; | 34 class AnalysisCanvas; |
34 } | 35 } |
35 | 36 |
36 namespace cc { | 37 namespace cc { |
37 | 38 |
38 class ContentLayerClient; | 39 class ContentLayerClient; |
39 | 40 |
40 class CC_EXPORT Picture | 41 class CC_EXPORT Picture |
41 : public base::RefCountedThreadSafe<Picture> { | 42 : public base::RefCountedThreadSafe<Picture> { |
42 public: | 43 public: |
43 typedef std::pair<int, int> PixelRefMapKey; | 44 typedef std::pair<int, int> PixelRefMapKey; |
44 typedef std::vector<SkPixelRef*> PixelRefs; | 45 typedef std::vector<SkPixelRef*> PixelRefs; |
45 typedef base::hash_map<PixelRefMapKey, PixelRefs> PixelRefMap; | 46 typedef base::hash_map<PixelRefMapKey, PixelRefs> PixelRefMap; |
46 | 47 |
47 enum RecordingMode { | 48 static scoped_refptr<Picture> Create( |
48 RECORD_NORMALLY, | 49 const gfx::Rect& layer_rect, |
49 RECORD_WITH_SK_NULL_CANVAS, | 50 ContentLayerClient* client, |
50 RECORD_WITH_PAINTING_DISABLED, | 51 const gfx::Size& tile_grid_size, |
51 RECORDING_MODE_COUNT, // Must be the last entry. | 52 bool gather_pixels_refs, |
52 }; | 53 RecordingSource::RecordingMode recording_mode); |
53 | |
54 static scoped_refptr<Picture> Create(const gfx::Rect& layer_rect, | |
55 ContentLayerClient* client, | |
56 const gfx::Size& tile_grid_size, | |
57 bool gather_pixels_refs, | |
58 RecordingMode recording_mode); | |
59 static scoped_refptr<Picture> CreateFromValue(const base::Value* value); | 54 static scoped_refptr<Picture> CreateFromValue(const base::Value* value); |
60 static scoped_refptr<Picture> CreateFromSkpValue(const base::Value* value); | 55 static scoped_refptr<Picture> CreateFromSkpValue(const base::Value* value); |
61 | 56 |
62 gfx::Rect LayerRect() const { return layer_rect_; } | 57 gfx::Rect LayerRect() const { return layer_rect_; } |
63 | 58 |
64 // Has Record() been called yet? | 59 // Has Record() been called yet? |
65 bool HasRecording() const { return picture_.get() != NULL; } | 60 bool HasRecording() const { return picture_.get() != NULL; } |
66 | 61 |
67 bool IsSuitableForGpuRasterization(const char** reason) const; | 62 bool IsSuitableForGpuRasterization(const char** reason) const; |
68 int ApproximateOpCount() const; | 63 int ApproximateOpCount() const; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 const gfx::Rect& layer_rect, | 129 const gfx::Rect& layer_rect, |
135 const PixelRefMap& pixel_refs); | 130 const PixelRefMap& pixel_refs); |
136 // This constructor will call AdoptRef on the SkPicture. | 131 // This constructor will call AdoptRef on the SkPicture. |
137 Picture(SkPicture*, const gfx::Rect& layer_rect); | 132 Picture(SkPicture*, const gfx::Rect& layer_rect); |
138 ~Picture(); | 133 ~Picture(); |
139 | 134 |
140 // Record a paint operation. To be able to safely use this SkPicture for | 135 // Record a paint operation. To be able to safely use this SkPicture for |
141 // playback on a different thread this can only be called once. | 136 // playback on a different thread this can only be called once. |
142 void Record(ContentLayerClient* client, | 137 void Record(ContentLayerClient* client, |
143 const gfx::Size& tile_grid_size, | 138 const gfx::Size& tile_grid_size, |
144 RecordingMode recording_mode); | 139 RecordingSource::RecordingMode recording_mode); |
145 | 140 |
146 // Gather pixel refs from recording. | 141 // Gather pixel refs from recording. |
147 void GatherPixelRefs(const gfx::Size& tile_grid_info); | 142 void GatherPixelRefs(const gfx::Size& tile_grid_info); |
148 | 143 |
149 gfx::Rect layer_rect_; | 144 gfx::Rect layer_rect_; |
150 skia::RefPtr<SkPicture> picture_; | 145 skia::RefPtr<SkPicture> picture_; |
151 | 146 |
152 PixelRefMap pixel_refs_; | 147 PixelRefMap pixel_refs_; |
153 gfx::Point min_pixel_cell_; | 148 gfx::Point min_pixel_cell_; |
154 gfx::Point max_pixel_cell_; | 149 gfx::Point max_pixel_cell_; |
155 gfx::Size cell_size_; | 150 gfx::Size cell_size_; |
156 | 151 |
157 scoped_refptr<base::debug::ConvertableToTraceFormat> | 152 scoped_refptr<base::debug::ConvertableToTraceFormat> |
158 AsTraceableRasterData(float scale) const; | 153 AsTraceableRasterData(float scale) const; |
159 scoped_refptr<base::debug::ConvertableToTraceFormat> | 154 scoped_refptr<base::debug::ConvertableToTraceFormat> |
160 AsTraceableRecordData() const; | 155 AsTraceableRecordData() const; |
161 | 156 |
162 friend class base::RefCountedThreadSafe<Picture>; | 157 friend class base::RefCountedThreadSafe<Picture>; |
163 friend class PixelRefIterator; | 158 friend class PixelRefIterator; |
164 DISALLOW_COPY_AND_ASSIGN(Picture); | 159 DISALLOW_COPY_AND_ASSIGN(Picture); |
165 }; | 160 }; |
166 | 161 |
167 } // namespace cc | 162 } // namespace cc |
168 | 163 |
169 #endif // CC_RESOURCES_PICTURE_H_ | 164 #endif // CC_RESOURCES_PICTURE_H_ |
OLD | NEW |