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> | |
9 #include <utility> | |
10 #include <vector> | |
11 | |
12 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
13 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
14 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
15 #include "base/logging.h" | 11 #include "base/logging.h" |
16 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
18 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
19 #include "cc/base/cc_export.h" | 15 #include "cc/base/cc_export.h" |
20 #include "cc/base/region.h" | 16 #include "cc/base/region.h" |
| 17 #include "cc/resources/pixel_ref_map.h" |
21 #include "cc/resources/recording_source.h" | 18 #include "cc/resources/recording_source.h" |
22 #include "skia/ext/refptr.h" | 19 #include "skia/ext/refptr.h" |
23 #include "third_party/skia/include/core/SkPicture.h" | 20 #include "third_party/skia/include/core/SkPicture.h" |
24 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" |
25 | 22 |
26 class SkDrawPictureCallback; | 23 class SkDrawPictureCallback; |
27 class SkPixelRef; | 24 class SkPixelRef; |
28 | 25 |
29 namespace base { | 26 namespace base { |
30 class Value; | 27 class Value; |
31 } | 28 } |
32 | 29 |
33 namespace skia { | 30 namespace skia { |
34 class AnalysisCanvas; | 31 class AnalysisCanvas; |
35 } | 32 } |
36 | 33 |
37 namespace cc { | 34 namespace cc { |
38 | 35 |
39 class ContentLayerClient; | 36 class ContentLayerClient; |
40 | 37 |
41 class CC_EXPORT Picture | 38 class CC_EXPORT Picture |
42 : public base::RefCountedThreadSafe<Picture> { | 39 : public base::RefCountedThreadSafe<Picture> { |
43 public: | 40 public: |
44 typedef std::pair<int, int> PixelRefMapKey; | |
45 typedef std::vector<SkPixelRef*> PixelRefs; | |
46 typedef base::hash_map<PixelRefMapKey, PixelRefs> PixelRefMap; | |
47 | |
48 static scoped_refptr<Picture> Create( | 41 static scoped_refptr<Picture> Create( |
49 const gfx::Rect& layer_rect, | 42 const gfx::Rect& layer_rect, |
50 ContentLayerClient* client, | 43 ContentLayerClient* client, |
51 const gfx::Size& tile_grid_size, | 44 const gfx::Size& tile_grid_size, |
52 bool gather_pixels_refs, | 45 bool gather_pixels_refs, |
53 RecordingSource::RecordingMode recording_mode); | 46 RecordingSource::RecordingMode recording_mode); |
54 static scoped_refptr<Picture> CreateFromValue(const base::Value* value); | 47 static scoped_refptr<Picture> CreateFromValue(const base::Value* value); |
55 static scoped_refptr<Picture> CreateFromSkpValue(const base::Value* value); | 48 static scoped_refptr<Picture> CreateFromSkpValue(const base::Value* value); |
56 | 49 |
57 gfx::Rect LayerRect() const { return layer_rect_; } | 50 gfx::Rect LayerRect() const { return layer_rect_; } |
(...skipping 15 matching lines...) Expand all Loading... |
73 SkDrawPictureCallback* callback, | 66 SkDrawPictureCallback* callback, |
74 const Region& negated_content_region, | 67 const Region& negated_content_region, |
75 float contents_scale) const; | 68 float contents_scale) const; |
76 | 69 |
77 // Draw the picture directly into the given canvas, without applying any | 70 // Draw the picture directly into the given canvas, without applying any |
78 // clip/scale/layer transformations. | 71 // clip/scale/layer transformations. |
79 void Replay(SkCanvas* canvas); | 72 void Replay(SkCanvas* canvas); |
80 | 73 |
81 scoped_ptr<base::Value> AsValue() const; | 74 scoped_ptr<base::Value> AsValue() const; |
82 | 75 |
83 // This iterator imprecisely returns the set of pixel refs that are needed to | |
84 // raster this layer rect from this picture. Internally, pixel refs are | |
85 // clumped into tile grid buckets, so there may be false positives. | |
86 class CC_EXPORT PixelRefIterator { | |
87 public: | |
88 PixelRefIterator(); | |
89 PixelRefIterator(const gfx::Rect& layer_rect, const Picture* picture); | |
90 ~PixelRefIterator(); | |
91 | |
92 SkPixelRef* operator->() const { | |
93 DCHECK_LT(current_index_, current_pixel_refs_->size()); | |
94 return (*current_pixel_refs_)[current_index_]; | |
95 } | |
96 | |
97 SkPixelRef* operator*() const { | |
98 DCHECK_LT(current_index_, current_pixel_refs_->size()); | |
99 return (*current_pixel_refs_)[current_index_]; | |
100 } | |
101 | |
102 PixelRefIterator& operator++(); | |
103 operator bool() const { | |
104 return current_index_ < current_pixel_refs_->size(); | |
105 } | |
106 | |
107 private: | |
108 static base::LazyInstance<PixelRefs> empty_pixel_refs_; | |
109 const Picture* picture_; | |
110 const PixelRefs* current_pixel_refs_; | |
111 unsigned current_index_; | |
112 | |
113 gfx::Point min_point_; | |
114 gfx::Point max_point_; | |
115 int current_x_; | |
116 int current_y_; | |
117 }; | |
118 | |
119 void EmitTraceSnapshot() const; | 76 void EmitTraceSnapshot() const; |
120 void EmitTraceSnapshotAlias(Picture* original) const; | 77 void EmitTraceSnapshotAlias(Picture* original) const; |
121 | 78 |
122 bool WillPlayBackBitmaps() const { return picture_->willPlayBackBitmaps(); } | 79 bool WillPlayBackBitmaps() const { return picture_->willPlayBackBitmaps(); } |
123 | 80 |
| 81 PixelRefMapIterator GetPixelRefMapIterator(const gfx::Rect& layer_rect) const; |
| 82 |
124 private: | 83 private: |
125 explicit Picture(const gfx::Rect& layer_rect); | 84 Picture(const gfx::Rect& layer_rect, const gfx::Size& tile_grid_size); |
126 // This constructor assumes SkPicture is already ref'd and transfers | 85 // This constructor assumes SkPicture is already ref'd and transfers |
127 // ownership to this picture. | 86 // ownership to this picture. |
128 Picture(const skia::RefPtr<SkPicture>&, | 87 Picture(const skia::RefPtr<SkPicture>&, |
129 const gfx::Rect& layer_rect, | 88 const gfx::Rect& layer_rect, |
130 const PixelRefMap& pixel_refs); | 89 const PixelRefMap& pixel_refs); |
131 // This constructor will call AdoptRef on the SkPicture. | 90 // This constructor will call AdoptRef on the SkPicture. |
132 Picture(SkPicture*, const gfx::Rect& layer_rect); | 91 Picture(SkPicture*, const gfx::Rect& layer_rect); |
133 ~Picture(); | 92 ~Picture(); |
134 | 93 |
135 // Record a paint operation. To be able to safely use this SkPicture for | 94 // Record a paint operation. To be able to safely use this SkPicture for |
136 // playback on a different thread this can only be called once. | 95 // playback on a different thread this can only be called once. |
137 void Record(ContentLayerClient* client, | 96 void Record(ContentLayerClient* client, |
138 const gfx::Size& tile_grid_size, | |
139 RecordingSource::RecordingMode recording_mode); | 97 RecordingSource::RecordingMode recording_mode); |
140 | 98 |
141 // Gather pixel refs from recording. | 99 // Gather pixel refs from recording. |
142 void GatherPixelRefs(const gfx::Size& tile_grid_info); | 100 void GatherPixelRefs(); |
143 | 101 |
144 gfx::Rect layer_rect_; | 102 gfx::Rect layer_rect_; |
145 skia::RefPtr<SkPicture> picture_; | 103 skia::RefPtr<SkPicture> picture_; |
146 | 104 |
147 PixelRefMap pixel_refs_; | 105 PixelRefMap pixel_refs_; |
148 gfx::Point min_pixel_cell_; | |
149 gfx::Point max_pixel_cell_; | |
150 gfx::Size cell_size_; | |
151 | 106 |
152 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 107 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
153 AsTraceableRasterData(float scale) const; | 108 AsTraceableRasterData(float scale) const; |
154 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 109 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
155 AsTraceableRecordData() const; | 110 AsTraceableRecordData() const; |
156 | 111 |
157 friend class base::RefCountedThreadSafe<Picture>; | 112 friend class base::RefCountedThreadSafe<Picture>; |
158 friend class PixelRefIterator; | 113 friend class PixelRefMapIterator; |
159 DISALLOW_COPY_AND_ASSIGN(Picture); | 114 DISALLOW_COPY_AND_ASSIGN(Picture); |
160 }; | 115 }; |
161 | 116 |
162 } // namespace cc | 117 } // namespace cc |
163 | 118 |
164 #endif // CC_RESOURCES_PICTURE_H_ | 119 #endif // CC_RESOURCES_PICTURE_H_ |
OLD | NEW |