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