Chromium Code Reviews| 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> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/hash_tables.h" | |
| 13 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 14 #include "cc/base/cc_export.h" | 16 #include "cc/base/cc_export.h" |
| 17 #include "cc/base/hash_pair.h" | |
| 15 #include "skia/ext/lazy_pixel_ref.h" | 18 #include "skia/ext/lazy_pixel_ref.h" |
| 16 #include "skia/ext/refptr.h" | 19 #include "skia/ext/refptr.h" |
| 17 #include "third_party/skia/include/core/SkPixelRef.h" | 20 #include "third_party/skia/include/core/SkPixelRef.h" |
| 18 #include "third_party/skia/include/core/SkTileGridPicture.h" | 21 #include "third_party/skia/include/core/SkTileGridPicture.h" |
| 19 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
| 20 | 23 |
| 21 namespace skia { | 24 namespace skia { |
| 22 class AnalysisCanvas; | 25 class AnalysisCanvas; |
| 23 } | 26 } |
| 24 | 27 |
| 25 namespace cc { | 28 namespace cc { |
| 26 | 29 |
| 27 class ContentLayerClient; | 30 class ContentLayerClient; |
| 28 struct RenderingStats; | 31 struct RenderingStats; |
| 29 | 32 |
| 30 class CC_EXPORT Picture | 33 class CC_EXPORT Picture |
| 31 : public base::RefCountedThreadSafe<Picture> { | 34 : public base::RefCountedThreadSafe<Picture> { |
| 32 public: | 35 public: |
| 36 typedef std::pair<int, int> PixelRefMapKey; | |
| 37 typedef base::hash_map< | |
| 38 PixelRefMapKey, | |
| 39 std::list<skia::LazyPixelRef*> > PixelRefMap; | |
|
reveman
2013/04/24 14:10:52
Sorry for changing my mind but as the set of lazy
vmpstr
2013/04/24 21:11:10
Changed to vector.
| |
| 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 const gfx::Rect& LayerRect() const { return layer_rect_; } | 45 const gfx::Rect& LayerRect() const { return layer_rect_; } |
| 38 const gfx::Rect& OpaqueRect() const { return opaque_rect_; } | 46 const 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 const 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(const PixelRefIterator& other); | |
| 75 PixelRefIterator(gfx::Rect layer_rect, const Picture* picture); | |
| 76 ~PixelRefIterator(); | |
| 77 | |
| 78 skia::LazyPixelRef* operator->() const { return *current_list_iterator_; } | |
| 79 skia::LazyPixelRef* operator*() const { return *current_list_iterator_; } | |
| 80 PixelRefIterator& operator++(); | |
| 81 PixelRefIterator& operator=(const PixelRefIterator& other); | |
| 82 operator bool() const { return !!*current_list_iterator_; } | |
| 83 | |
| 84 private: | |
| 85 const Picture* picture_; | |
| 86 std::list<skia::LazyPixelRef*> sentinel_list_; | |
| 87 const std::list<skia::LazyPixelRef*>* current_list_; | |
| 88 std::list<skia::LazyPixelRef*>::const_iterator current_list_iterator_; | |
|
reveman
2013/04/24 14:10:52
if we use the std::vector idea I mentioned above t
vmpstr
2013/04/24 21:11:10
I kept the current way.. With position, we'd have
reveman
2013/04/24 23:01:27
index or iterator would be the same for std::vecto
| |
| 89 | |
| 90 gfx::Point min_point_; | |
| 91 gfx::Point max_point_; | |
| 92 int current_x_; | |
| 93 int current_y_; | |
| 94 }; | |
| 66 | 95 |
| 67 private: | 96 private: |
| 68 explicit Picture(gfx::Rect layer_rect); | 97 explicit Picture(gfx::Rect layer_rect); |
| 69 Picture(const std::string& encoded_string, bool* success); | 98 Picture(const std::string& encoded_string, bool* success); |
| 70 // This constructor assumes SkPicture is already ref'd and transfers | 99 // This constructor assumes SkPicture is already ref'd and transfers |
| 71 // ownership to this picture. | 100 // ownership to this picture. |
| 72 Picture(const skia::RefPtr<SkPicture>&, | 101 Picture(const skia::RefPtr<SkPicture>&, |
| 73 gfx::Rect layer_rect, | 102 gfx::Rect layer_rect, |
| 74 gfx::Rect opaque_rect); | 103 gfx::Rect opaque_rect, |
| 104 const PixelRefMap& pixel_refs); | |
| 75 ~Picture(); | 105 ~Picture(); |
| 76 | 106 |
| 107 void GatherPixelRefsFromSkia( | |
| 108 gfx::Rect query_rect, | |
| 109 std::list<skia::LazyPixelRef*>* pixel_ref_list); | |
| 110 void GatherAllPixelRefs(); | |
| 111 | |
| 77 gfx::Rect layer_rect_; | 112 gfx::Rect layer_rect_; |
| 78 gfx::Rect opaque_rect_; | 113 gfx::Rect opaque_rect_; |
| 79 skia::RefPtr<SkPicture> picture_; | 114 skia::RefPtr<SkPicture> picture_; |
| 80 | 115 |
| 81 typedef std::vector<scoped_refptr<Picture> > PictureVector; | 116 typedef std::vector<scoped_refptr<Picture> > PictureVector; |
| 82 PictureVector clones_; | 117 PictureVector clones_; |
| 83 | 118 |
| 119 PixelRefMap pixel_refs_; | |
| 120 gfx::Point min_pixel_cell_; | |
| 121 gfx::Point max_pixel_cell_; | |
| 122 gfx::Size cell_size_; | |
| 123 | |
| 84 friend class base::RefCountedThreadSafe<Picture>; | 124 friend class base::RefCountedThreadSafe<Picture>; |
| 125 friend class PixelRefIterator; | |
| 85 DISALLOW_COPY_AND_ASSIGN(Picture); | 126 DISALLOW_COPY_AND_ASSIGN(Picture); |
| 86 }; | 127 }; |
| 87 | 128 |
| 88 } // namespace cc | 129 } // namespace cc |
| 89 | 130 |
| 90 #endif // CC_RESOURCES_PICTURE_H_ | 131 #endif // CC_RESOURCES_PICTURE_H_ |
| OLD | NEW |