Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(772)

Side by Side Diff: cc/resources/picture.h

Issue 14230007: cc: Do GatherPixelRefs from skia at record time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reviews Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "cc/base/cc_export.h" 15 #include "cc/base/cc_export.h"
16 #include "cc/base/hash_pair.h"
15 #include "skia/ext/lazy_pixel_ref.h" 17 #include "skia/ext/lazy_pixel_ref.h"
16 #include "skia/ext/refptr.h" 18 #include "skia/ext/refptr.h"
17 #include "third_party/skia/include/core/SkPixelRef.h" 19 #include "third_party/skia/include/core/SkPixelRef.h"
18 #include "third_party/skia/include/core/SkTileGridPicture.h" 20 #include "third_party/skia/include/core/SkTileGridPicture.h"
19 #include "ui/gfx/rect.h" 21 #include "ui/gfx/rect.h"
20 22
21 namespace skia { 23 namespace skia {
22 class AnalysisCanvas; 24 class AnalysisCanvas;
23 } 25 }
24 26
25 namespace cc { 27 namespace cc {
26 28
27 class ContentLayerClient; 29 class ContentLayerClient;
28 struct RenderingStats; 30 struct RenderingStats;
29 31
30 class CC_EXPORT Picture 32 class CC_EXPORT Picture
31 : public base::RefCountedThreadSafe<Picture> { 33 : public base::RefCountedThreadSafe<Picture> {
32 public: 34 public:
35 typedef std::pair<int, int> PixelRefMapKey;
36 typedef base::hash_map<
37 PixelRefMapKey,
38 std::vector<skia::LazyPixelRef*> > PixelRefMap;
39
33 static scoped_refptr<Picture> Create(gfx::Rect layer_rect); 40 static scoped_refptr<Picture> Create(gfx::Rect layer_rect);
34 static scoped_refptr<Picture> CreateFromBase64String( 41 static scoped_refptr<Picture> CreateFromBase64String(
35 const std::string& encoded_string); 42 const std::string& encoded_string);
36 43
37 const gfx::Rect& LayerRect() const { return layer_rect_; } 44 const gfx::Rect& LayerRect() const { return layer_rect_; }
38 const gfx::Rect& OpaqueRect() const { return opaque_rect_; } 45 const gfx::Rect& OpaqueRect() const { return opaque_rect_; }
39 46
40 // Get thread-safe clone for rasterizing with on a specific thread. 47 // Get thread-safe clone for rasterizing with on a specific thread.
41 scoped_refptr<Picture> GetCloneForDrawingOnThread( 48 scoped_refptr<Picture> GetCloneForDrawingOnThread(
42 unsigned thread_index) const; 49 unsigned thread_index) const;
43 50
44 // Make thread-safe clones for rasterizing with. 51 // Make thread-safe clones for rasterizing with.
45 void CloneForDrawing(int num_threads); 52 void CloneForDrawing(int num_threads);
46 53
47 // Record a paint operation. To be able to safely use this SkPicture for 54 // 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. 55 // playback on a different thread this can only be called once.
49 void Record(ContentLayerClient*, RenderingStats*, 56 void Record(ContentLayerClient*, RenderingStats*,
50 const SkTileGridPicture::TileGridInfo& tile_grid_info); 57 const SkTileGridPicture::TileGridInfo& tile_grid_info);
51 58
52 // Has Record() been called yet? 59 // Has Record() been called yet?
53 bool HasRecording() const { return picture_.get() != NULL; } 60 bool HasRecording() const { return picture_.get() != NULL; }
54 61
55 // Apply this contents scale and raster the content rect into the canvas. 62 // Apply this contents scale and raster the content rect into the canvas.
56 void Raster(SkCanvas* canvas, 63 void Raster(SkCanvas* canvas,
57 gfx::Rect content_rect, 64 gfx::Rect content_rect,
58 float contents_scale, 65 float contents_scale,
59 bool enable_lcd_text); 66 bool enable_lcd_text);
60 67
61 void GatherPixelRefs( 68 void AsBase64String(std::string* output) const;
62 const gfx::Rect& layer_rect,
63 std::list<skia::LazyPixelRef*>& pixel_ref_list);
64 69
65 void AsBase64String(std::string* output) const; 70 class CC_EXPORT PixelRefIterator {
71 public:
72 PixelRefIterator();
73 PixelRefIterator(const PixelRefIterator& other);
74 PixelRefIterator(gfx::Rect layer_rect, const Picture* picture);
75 ~PixelRefIterator();
76
77 skia::LazyPixelRef* operator->() const { return *current_iterator_; }
78 skia::LazyPixelRef* operator*() const { return *current_iterator_; }
79 PixelRefIterator& operator++();
80 PixelRefIterator& operator=(const PixelRefIterator& other);
81 operator bool() const { return !!*current_iterator_; }
82
83 private:
84 const Picture* picture_;
85 std::vector<skia::LazyPixelRef*> sentinel_;
86 const std::vector<skia::LazyPixelRef*>* current_pixel_refs_;
87 std::vector<skia::LazyPixelRef*>::const_iterator current_iterator_;
88
89 gfx::Point min_point_;
90 gfx::Point max_point_;
91 int current_x_;
92 int current_y_;
93 };
66 94
67 private: 95 private:
68 explicit Picture(gfx::Rect layer_rect); 96 explicit Picture(gfx::Rect layer_rect);
69 Picture(const std::string& encoded_string, bool* success); 97 Picture(const std::string& encoded_string, bool* success);
70 // This constructor assumes SkPicture is already ref'd and transfers 98 // This constructor assumes SkPicture is already ref'd and transfers
71 // ownership to this picture. 99 // ownership to this picture.
72 Picture(const skia::RefPtr<SkPicture>&, 100 Picture(const skia::RefPtr<SkPicture>&,
73 gfx::Rect layer_rect, 101 gfx::Rect layer_rect,
74 gfx::Rect opaque_rect); 102 gfx::Rect opaque_rect,
103 const PixelRefMap& pixel_refs);
75 ~Picture(); 104 ~Picture();
76 105
106 void GatherPixelRefsFromSkia(
107 gfx::Rect query_rect,
108 std::vector<skia::LazyPixelRef*>* pixel_refs);
109 void GatherAllPixelRefs();
110
77 gfx::Rect layer_rect_; 111 gfx::Rect layer_rect_;
78 gfx::Rect opaque_rect_; 112 gfx::Rect opaque_rect_;
79 skia::RefPtr<SkPicture> picture_; 113 skia::RefPtr<SkPicture> picture_;
80 114
81 typedef std::vector<scoped_refptr<Picture> > PictureVector; 115 typedef std::vector<scoped_refptr<Picture> > PictureVector;
82 PictureVector clones_; 116 PictureVector clones_;
83 117
118 PixelRefMap pixel_refs_;
119 gfx::Point min_pixel_cell_;
120 gfx::Point max_pixel_cell_;
121 gfx::Size cell_size_;
122
84 friend class base::RefCountedThreadSafe<Picture>; 123 friend class base::RefCountedThreadSafe<Picture>;
124 friend class PixelRefIterator;
85 DISALLOW_COPY_AND_ASSIGN(Picture); 125 DISALLOW_COPY_AND_ASSIGN(Picture);
86 }; 126 };
87 127
88 } // namespace cc 128 } // namespace cc
89 129
90 #endif // CC_RESOURCES_PICTURE_H_ 130 #endif // CC_RESOURCES_PICTURE_H_
OLDNEW
« no previous file with comments | « cc/base/util.h ('k') | cc/resources/picture.cc » ('j') | cc/resources/picture_pile_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698