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 <list> | |
9 #include <string> | 8 #include <string> |
9 #include <utility> | |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/hash_tables.h" | |
14 #include "base/lazy_instance.h" | |
15 #include "base/logging.h" | |
13 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
14 #include "cc/base/cc_export.h" | 17 #include "cc/base/cc_export.h" |
18 #include "cc/base/hash_pair.h" | |
15 #include "skia/ext/lazy_pixel_ref.h" | 19 #include "skia/ext/lazy_pixel_ref.h" |
16 #include "skia/ext/refptr.h" | 20 #include "skia/ext/refptr.h" |
17 #include "third_party/skia/include/core/SkPixelRef.h" | 21 #include "third_party/skia/include/core/SkPixelRef.h" |
18 #include "third_party/skia/include/core/SkTileGridPicture.h" | 22 #include "third_party/skia/include/core/SkTileGridPicture.h" |
19 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
20 | 24 |
21 namespace skia { | 25 namespace skia { |
22 class AnalysisCanvas; | 26 class AnalysisCanvas; |
23 } | 27 } |
24 | 28 |
25 namespace cc { | 29 namespace cc { |
26 | 30 |
27 class ContentLayerClient; | 31 class ContentLayerClient; |
28 struct RenderingStats; | 32 struct RenderingStats; |
29 | 33 |
30 class CC_EXPORT Picture | 34 class CC_EXPORT Picture |
31 : public base::RefCountedThreadSafe<Picture> { | 35 : public base::RefCountedThreadSafe<Picture> { |
32 public: | 36 public: |
37 typedef std::pair<int, int> PixelRefMapKey; | |
38 typedef std::vector<skia::LazyPixelRef*> PixelRefs; | |
39 typedef base::hash_map<PixelRefMapKey, PixelRefs> PixelRefMap; | |
40 | |
33 static scoped_refptr<Picture> Create(gfx::Rect layer_rect); | 41 static scoped_refptr<Picture> Create(gfx::Rect layer_rect); |
34 static scoped_refptr<Picture> CreateFromBase64String( | 42 static scoped_refptr<Picture> CreateFromBase64String( |
35 const std::string& encoded_string); | 43 const std::string& encoded_string); |
36 | 44 |
37 gfx::Rect LayerRect() const { return layer_rect_; } | 45 gfx::Rect LayerRect() const { return layer_rect_; } |
38 gfx::Rect OpaqueRect() const { return opaque_rect_; } | 46 gfx::Rect OpaqueRect() const { return opaque_rect_; } |
39 | 47 |
40 // Get thread-safe clone for rasterizing with on a specific thread. | 48 // Get thread-safe clone for rasterizing with on a specific thread. |
41 scoped_refptr<Picture> GetCloneForDrawingOnThread( | 49 scoped_refptr<Picture> GetCloneForDrawingOnThread( |
42 unsigned thread_index) const; | 50 unsigned thread_index) const; |
43 | 51 |
44 // Make thread-safe clones for rasterizing with. | 52 // Make thread-safe clones for rasterizing with. |
45 void CloneForDrawing(int num_threads); | 53 void CloneForDrawing(int num_threads); |
46 | 54 |
47 // Record a paint operation. To be able to safely use this SkPicture for | 55 // Record a paint operation. To be able to safely use this SkPicture for |
48 // playback on a different thread this can only be called once. | 56 // playback on a different thread this can only be called once. |
49 void Record(ContentLayerClient*, RenderingStats*, | 57 void Record(ContentLayerClient*, RenderingStats*, |
50 const SkTileGridPicture::TileGridInfo& tile_grid_info); | 58 const SkTileGridPicture::TileGridInfo& tile_grid_info); |
51 | 59 |
52 // Has Record() been called yet? | 60 // Has Record() been called yet? |
53 bool HasRecording() const { return picture_.get() != NULL; } | 61 bool HasRecording() const { return picture_.get() != NULL; } |
54 | 62 |
55 // Apply this contents scale and raster the content rect into the canvas. | 63 // Apply this contents scale and raster the content rect into the canvas. |
56 void Raster(SkCanvas* canvas, | 64 void Raster(SkCanvas* canvas, |
57 gfx::Rect content_rect, | 65 gfx::Rect content_rect, |
58 float contents_scale, | 66 float contents_scale, |
59 bool enable_lcd_text); | 67 bool enable_lcd_text); |
60 | 68 |
61 void GatherPixelRefs( | 69 void AsBase64String(std::string* output) const; |
62 gfx::Rect layer_rect, | |
63 std::list<skia::LazyPixelRef*>& pixel_ref_list); | |
64 | 70 |
65 void AsBase64String(std::string* output) const; | 71 class CC_EXPORT PixelRefIterator { |
72 public: | |
73 PixelRefIterator(); | |
74 PixelRefIterator(gfx::Rect layer_rect, const Picture* picture); | |
75 ~PixelRefIterator(); | |
76 | |
77 skia::LazyPixelRef* operator->() const { | |
78 DCHECK(current_index_ < current_pixel_refs_->size()); | |
reveman
2013/04/25 00:36:28
nit: use DCHECK_LT
| |
79 return (*current_pixel_refs_)[current_index_]; | |
reveman
2013/04/25 00:36:28
current_pixel_refs_->at(index) might be a bit clea
| |
80 } | |
81 | |
82 skia::LazyPixelRef* operator*() const { | |
83 DCHECK(current_index_ < current_pixel_refs_->size()); | |
reveman
2013/04/25 00:36:28
nit: use DCHECK_LT
| |
84 return (*current_pixel_refs_)[current_index_]; | |
85 } | |
86 | |
87 PixelRefIterator& operator++(); | |
88 operator bool() const { | |
89 return current_index_ < current_pixel_refs_->size(); | |
90 } | |
91 | |
92 private: | |
93 static base::LazyInstance<PixelRefs> empty_pixel_refs_; | |
94 const Picture* picture_; | |
95 const PixelRefs* current_pixel_refs_; | |
96 unsigned int current_index_; | |
reveman
2013/04/25 00:36:28
nit: just "unsigned" is preferred
| |
97 | |
98 gfx::Point min_point_; | |
99 gfx::Point max_point_; | |
100 int current_x_; | |
101 int current_y_; | |
102 }; | |
66 | 103 |
67 private: | 104 private: |
68 explicit Picture(gfx::Rect layer_rect); | 105 explicit Picture(gfx::Rect layer_rect); |
69 Picture(const std::string& encoded_string, bool* success); | 106 Picture(const std::string& encoded_string, bool* success); |
70 // This constructor assumes SkPicture is already ref'd and transfers | 107 // This constructor assumes SkPicture is already ref'd and transfers |
71 // ownership to this picture. | 108 // ownership to this picture. |
72 Picture(const skia::RefPtr<SkPicture>&, | 109 Picture(const skia::RefPtr<SkPicture>&, |
73 gfx::Rect layer_rect, | 110 gfx::Rect layer_rect, |
74 gfx::Rect opaque_rect); | 111 gfx::Rect opaque_rect, |
112 const PixelRefMap& pixel_refs); | |
75 ~Picture(); | 113 ~Picture(); |
76 | 114 |
115 void GatherPixelRefsFromSkia(gfx::Rect query_rect, PixelRefs* pixel_refs); | |
116 void GatherAllPixelRefs(); | |
117 | |
77 gfx::Rect layer_rect_; | 118 gfx::Rect layer_rect_; |
78 gfx::Rect opaque_rect_; | 119 gfx::Rect opaque_rect_; |
79 skia::RefPtr<SkPicture> picture_; | 120 skia::RefPtr<SkPicture> picture_; |
80 | 121 |
81 typedef std::vector<scoped_refptr<Picture> > PictureVector; | 122 typedef std::vector<scoped_refptr<Picture> > PictureVector; |
82 PictureVector clones_; | 123 PictureVector clones_; |
83 | 124 |
125 PixelRefMap pixel_refs_; | |
126 gfx::Point min_pixel_cell_; | |
127 gfx::Point max_pixel_cell_; | |
128 gfx::Size cell_size_; | |
129 | |
84 friend class base::RefCountedThreadSafe<Picture>; | 130 friend class base::RefCountedThreadSafe<Picture>; |
131 friend class PixelRefIterator; | |
85 DISALLOW_COPY_AND_ASSIGN(Picture); | 132 DISALLOW_COPY_AND_ASSIGN(Picture); |
86 }; | 133 }; |
87 | 134 |
88 } // namespace cc | 135 } // namespace cc |
89 | 136 |
90 #endif // CC_RESOURCES_PICTURE_H_ | 137 #endif // CC_RESOURCES_PICTURE_H_ |
OLD | NEW |