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