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

Side by Side Diff: cc/playback/discardable_image_map.cc

Issue 2514263002: Handle simple SkImageShaders (Closed)
Patch Set: rebase Created 4 years 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "cc/playback/discardable_image_map.h" 5 #include "cc/playback/discardable_image_map.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
11 11
12 #include "base/containers/adapters.h" 12 #include "base/containers/adapters.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "cc/base/math_util.h" 14 #include "cc/base/math_util.h"
15 #include "cc/playback/display_item_list.h" 15 #include "cc/playback/display_item_list.h"
16 #include "third_party/skia/include/core/SkPath.h"
16 #include "third_party/skia/include/utils/SkNWayCanvas.h" 17 #include "third_party/skia/include/utils/SkNWayCanvas.h"
17 #include "ui/gfx/geometry/rect_conversions.h" 18 #include "ui/gfx/geometry/rect_conversions.h"
18 #include "ui/gfx/skia_util.h" 19 #include "ui/gfx/skia_util.h"
19 20
20 namespace cc { 21 namespace cc {
21 22
22 SkRect MapRect(const SkMatrix& matrix, const SkRect& src) { 23 SkRect MapRect(const SkMatrix& matrix, const SkRect& src) {
23 SkRect dst; 24 SkRect dst;
24 matrix.mapRect(&dst, src); 25 matrix.mapRect(&dst, src);
25 return dst; 26 return dst;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 108 }
108 109
109 void onDrawImageNine(const SkImage* image, 110 void onDrawImageNine(const SkImage* image,
110 const SkIRect& center, 111 const SkIRect& center,
111 const SkRect& dst, 112 const SkRect& dst,
112 const SkPaint* paint) override { 113 const SkPaint* paint) override {
113 // No cc embedder issues image nine calls. 114 // No cc embedder issues image nine calls.
114 NOTREACHED(); 115 NOTREACHED();
115 } 116 }
116 117
118 void onDrawRect(const SkRect& r, const SkPaint& paint) override {
119 AddPaintImage(r, paint);
120 }
121
122 void onDrawPath(const SkPath& path, const SkPaint& paint) override {
123 AddPaintImage(path.getBounds(), paint);
124 }
125
126 void onDrawOval(const SkRect& r, const SkPaint& paint) override {
127 AddPaintImage(r, paint);
128 }
129
130 void onDrawArc(const SkRect& r,
131 SkScalar start_angle,
132 SkScalar sweep_angle,
133 bool use_center,
134 const SkPaint& paint) override {
135 AddPaintImage(r, paint);
136 }
137
138 void onDrawRRect(const SkRRect& rr, const SkPaint& paint) override {
139 AddPaintImage(rr.rect(), paint);
140 }
141
117 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override { 142 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override {
118 saved_paints_.push_back(*rec.fPaint); 143 saved_paints_.push_back(*rec.fPaint);
119 return SkNWayCanvas::getSaveLayerStrategy(rec); 144 return SkNWayCanvas::getSaveLayerStrategy(rec);
120 } 145 }
121 146
122 void willSave() override { 147 void willSave() override {
123 saved_paints_.push_back(SkPaint()); 148 saved_paints_.push_back(SkPaint());
124 return SkNWayCanvas::willSave(); 149 return SkNWayCanvas::willSave();
125 } 150 }
126 151
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 gfx::Rect image_rect = SafeClampPaintRectToSize(paint_rect, canvas_size_); 203 gfx::Rect image_rect = SafeClampPaintRectToSize(paint_rect, canvas_size_);
179 204
180 Region& region = (*image_id_to_region_)[image->uniqueID()]; 205 Region& region = (*image_id_to_region_)[image->uniqueID()];
181 region.Union(image_rect); 206 region.Union(image_rect);
182 207
183 image_set_->push_back(std::make_pair( 208 image_set_->push_back(std::make_pair(
184 DrawImage(std::move(image), src_irect, filter_quality, matrix), 209 DrawImage(std::move(image), src_irect, filter_quality, matrix),
185 image_rect)); 210 image_rect));
186 } 211 }
187 212
213 // Currently this function only handles extracting images from SkImageShaders
214 // embedded in SkPaints. Other embedded image cases, such as SkPictures,
215 // are not yet handled.
216 void AddPaintImage(const SkRect& rect, const SkPaint& paint) {
217 SkShader* shader = paint.getShader();
218 if (shader) {
219 SkMatrix matrix;
220 SkShader::TileMode xy[2];
221 SkImage* image = shader->isAImage(&matrix, xy);
222 if (image) {
223 const SkMatrix& ctm = getTotalMatrix();
224 matrix.postConcat(ctm);
225 // TODO(ericrk): Handle cases where we only need a sub-rect from the
226 // image.
227 AddImage(sk_ref_sp(image), SkRect::MakeFromIRect(image->bounds()),
228 MapRect(ctm, rect), matrix, &paint);
229 }
230 }
231 }
232
188 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set_; 233 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set_;
189 DiscardableImageMap::ImageToRegionMap* image_id_to_region_; 234 DiscardableImageMap::ImageToRegionMap* image_id_to_region_;
190 const SkRect canvas_bounds_; 235 const SkRect canvas_bounds_;
191 const gfx::Size canvas_size_; 236 const gfx::Size canvas_size_;
192 std::vector<SkPaint> saved_paints_; 237 std::vector<SkPaint> saved_paints_;
193 }; 238 };
194 239
195 } // namespace 240 } // namespace
196 241
197 DiscardableImageMap::DiscardableImageMap() {} 242 DiscardableImageMap::DiscardableImageMap() {}
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 DiscardableImageMap* image_map, 276 DiscardableImageMap* image_map,
232 const gfx::Size& bounds) 277 const gfx::Size& bounds)
233 : image_map_(image_map), 278 : image_map_(image_map),
234 metadata_canvas_(image_map->BeginGeneratingMetadata(bounds)) {} 279 metadata_canvas_(image_map->BeginGeneratingMetadata(bounds)) {}
235 280
236 DiscardableImageMap::ScopedMetadataGenerator::~ScopedMetadataGenerator() { 281 DiscardableImageMap::ScopedMetadataGenerator::~ScopedMetadataGenerator() {
237 image_map_->EndGeneratingMetadata(); 282 image_map_->EndGeneratingMetadata();
238 } 283 }
239 284
240 } // namespace cc 285 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/playback/discardable_image_map_unittest.cc » ('j') | cc/playback/image_hijack_canvas.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698