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