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

Side by Side Diff: skia/ext/lazy_pixel_ref_utils.cc

Issue 15981008: skia/ext: Updated lazy_pixel_ref_utils style. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 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
« no previous file with comments | « skia/ext/lazy_pixel_ref_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "lazy_pixel_ref_utils.h" 5 #include "lazy_pixel_ref_utils.h"
6 6
7 #include "SkCanvas.h" 7 #include "SkCanvas.h"
8 #include "SkData.h" 8 #include "SkData.h"
9 #include "SkDevice.h" 9 #include "SkDevice.h"
10 #include "SkDraw.h" 10 #include "SkDraw.h"
(...skipping 11 matching lines...) Expand all
22 22
23 // URI label for a lazily decoded SkPixelRef. 23 // URI label for a lazily decoded SkPixelRef.
24 const char kLabelLazyDecoded[] = "lazy"; 24 const char kLabelLazyDecoded[] = "lazy";
25 25
26 class LazyPixelRefSet { 26 class LazyPixelRefSet {
27 public: 27 public:
28 LazyPixelRefSet( 28 LazyPixelRefSet(
29 std::vector<LazyPixelRefUtils::PositionLazyPixelRef>* pixel_refs) 29 std::vector<LazyPixelRefUtils::PositionLazyPixelRef>* pixel_refs)
30 : pixel_refs_(pixel_refs) {} 30 : pixel_refs_(pixel_refs) {}
31 31
32 void add(SkPixelRef* pixel_ref, const SkRect& rect) { 32 void Add(SkPixelRef* pixel_ref, const SkRect& rect) {
33 // Only save lazy pixel refs. 33 // Only save lazy pixel refs.
34 if (pixel_ref->getURI() && 34 if (pixel_ref->getURI() &&
35 !strcmp(pixel_ref->getURI(), kLabelLazyDecoded)) { 35 !strcmp(pixel_ref->getURI(), kLabelLazyDecoded)) {
36 LazyPixelRefUtils::PositionLazyPixelRef position_pixel_ref; 36 LazyPixelRefUtils::PositionLazyPixelRef position_pixel_ref;
37 position_pixel_ref.lazy_pixel_ref = 37 position_pixel_ref.lazy_pixel_ref =
38 static_cast<skia::LazyPixelRef*>(pixel_ref); 38 static_cast<skia::LazyPixelRef*>(pixel_ref);
39 position_pixel_ref.pixel_ref_rect = rect; 39 position_pixel_ref.pixel_ref_rect = rect;
40 pixel_refs_->push_back(position_pixel_ref); 40 pixel_refs_->push_back(position_pixel_ref);
41 } 41 }
42 } 42 }
43 43
44 private: 44 private:
45 std::vector<LazyPixelRefUtils::PositionLazyPixelRef>* pixel_refs_; 45 std::vector<LazyPixelRefUtils::PositionLazyPixelRef>* pixel_refs_;
46 }; 46 };
47 47
48 class GatherPixelRefDevice : public SkDevice { 48 class GatherPixelRefDevice : public SkDevice {
49 public: 49 public:
50 GatherPixelRefDevice(const SkBitmap& bm, LazyPixelRefSet* lazy_pixel_ref_set) 50 GatherPixelRefDevice(const SkBitmap& bm, LazyPixelRefSet* lazy_pixel_ref_set)
51 : SkDevice(bm), lazy_pixel_ref_set_(lazy_pixel_ref_set) {} 51 : SkDevice(bm), lazy_pixel_ref_set_(lazy_pixel_ref_set) {}
52 52
53 virtual void clear(SkColor color) SK_OVERRIDE {} 53 virtual void clear(SkColor color) SK_OVERRIDE {}
54 virtual void writePixels(const SkBitmap& bitmap, 54 virtual void writePixels(const SkBitmap& bitmap,
55 int x, 55 int x,
56 int y, 56 int y,
57 SkCanvas::Config8888 config8888) SK_OVERRIDE {} 57 SkCanvas::Config8888 config8888) SK_OVERRIDE {}
58 58
59 virtual void drawPaint(const SkDraw& draw, const SkPaint& paint) SK_OVERRIDE { 59 virtual void drawPaint(const SkDraw& draw, const SkPaint& paint) SK_OVERRIDE {
60 SkBitmap bitmap; 60 SkBitmap bitmap;
61 if (getBitmapFromPaint(paint, &bitmap)) { 61 if (GetBitmapFromPaint(paint, &bitmap)) {
62 SkRect clip_rect = SkRect::Make(draw.fRC->getBounds()); 62 SkRect clip_rect = SkRect::Make(draw.fRC->getBounds());
63 SkRect canvas_rect = SkRect::MakeWH(width(), height()); 63 SkRect canvas_rect = SkRect::MakeWH(width(), height());
64 SkRect paint_rect = SkRect::MakeEmpty(); 64 SkRect paint_rect = SkRect::MakeEmpty();
65 paint_rect.intersect(canvas_rect, clip_rect); 65 paint_rect.intersect(canvas_rect, clip_rect);
66 66
67 addBitmap(bitmap, paint_rect); 67 AddBitmap(bitmap, paint_rect);
68 } 68 }
69 } 69 }
70 70
71 virtual void drawPoints(const SkDraw& draw, 71 virtual void drawPoints(const SkDraw& draw,
72 SkCanvas::PointMode mode, 72 SkCanvas::PointMode mode,
73 size_t count, 73 size_t count,
74 const SkPoint points[], 74 const SkPoint points[],
75 const SkPaint& paint) SK_OVERRIDE { 75 const SkPaint& paint) SK_OVERRIDE {
76 SkBitmap bitmap; 76 SkBitmap bitmap;
77 if (!getBitmapFromPaint(paint, &bitmap)) 77 if (!GetBitmapFromPaint(paint, &bitmap))
78 return; 78 return;
79 79
80 if (count == 0) 80 if (count == 0)
81 return; 81 return;
82 82
83 SkPoint min_point = points[0]; 83 SkPoint min_point = points[0];
84 SkPoint max_point = points[0]; 84 SkPoint max_point = points[0];
85 for (size_t i = 1; i < count; ++i) { 85 for (size_t i = 1; i < count; ++i) {
86 const SkPoint& point = points[i]; 86 const SkPoint& point = points[i];
87 min_point.set(std::min(min_point.x(), point.x()), 87 min_point.set(std::min(min_point.x(), point.x()),
88 std::min(min_point.y(), point.y())); 88 std::min(min_point.y(), point.y()));
89 max_point.set(std::max(max_point.x(), point.x()), 89 max_point.set(std::max(max_point.x(), point.x()),
90 std::max(max_point.y(), point.y())); 90 std::max(max_point.y(), point.y()));
91 } 91 }
92 92
93 SkRect bounds = SkRect::MakeLTRB( 93 SkRect bounds = SkRect::MakeLTRB(
94 min_point.x(), min_point.y(), max_point.x(), max_point.y()); 94 min_point.x(), min_point.y(), max_point.x(), max_point.y());
95 95
96 GatherPixelRefDevice::drawRect(draw, bounds, paint); 96 GatherPixelRefDevice::drawRect(draw, bounds, paint);
97 } 97 }
98 virtual void drawRect(const SkDraw& draw, 98 virtual void drawRect(const SkDraw& draw,
99 const SkRect& rect, 99 const SkRect& rect,
100 const SkPaint& paint) SK_OVERRIDE { 100 const SkPaint& paint) SK_OVERRIDE {
101 SkBitmap bitmap; 101 SkBitmap bitmap;
102 if (getBitmapFromPaint(paint, &bitmap)) { 102 if (GetBitmapFromPaint(paint, &bitmap)) {
103 SkRect mapped_rect; 103 SkRect mapped_rect;
104 draw.fMatrix->mapRect(&mapped_rect, rect); 104 draw.fMatrix->mapRect(&mapped_rect, rect);
105 mapped_rect.intersect(SkRect::Make(draw.fRC->getBounds())); 105 mapped_rect.intersect(SkRect::Make(draw.fRC->getBounds()));
106 addBitmap(bitmap, mapped_rect); 106 AddBitmap(bitmap, mapped_rect);
107 } 107 }
108 } 108 }
109 virtual void drawOval(const SkDraw& draw, 109 virtual void drawOval(const SkDraw& draw,
110 const SkRect& rect, 110 const SkRect& rect,
111 const SkPaint& paint) SK_OVERRIDE { 111 const SkPaint& paint) SK_OVERRIDE {
112 GatherPixelRefDevice::drawRect(draw, rect, paint); 112 GatherPixelRefDevice::drawRect(draw, rect, paint);
113 } 113 }
114 virtual void drawRRect(const SkDraw& draw, 114 virtual void drawRRect(const SkDraw& draw,
115 const SkRRect& rect, 115 const SkRRect& rect,
116 const SkPaint& paint) SK_OVERRIDE { 116 const SkPaint& paint) SK_OVERRIDE {
117 GatherPixelRefDevice::drawRect(draw, rect.rect(), paint); 117 GatherPixelRefDevice::drawRect(draw, rect.rect(), paint);
118 } 118 }
119 virtual void drawPath(const SkDraw& draw, 119 virtual void drawPath(const SkDraw& draw,
120 const SkPath& path, 120 const SkPath& path,
121 const SkPaint& paint, 121 const SkPaint& paint,
122 const SkMatrix* prePathMatrix, 122 const SkMatrix* pre_path_matrix,
123 bool pathIsMutable) SK_OVERRIDE { 123 bool path_is_mutable) SK_OVERRIDE {
124 SkBitmap bitmap; 124 SkBitmap bitmap;
125 if (!getBitmapFromPaint(paint, &bitmap)) 125 if (!GetBitmapFromPaint(paint, &bitmap))
126 return; 126 return;
127 127
128 SkRect path_bounds = path.getBounds(); 128 SkRect path_bounds = path.getBounds();
129 SkRect final_rect; 129 SkRect final_rect;
130 if (prePathMatrix != NULL) 130 if (pre_path_matrix != NULL)
131 prePathMatrix->mapRect(&final_rect, path_bounds); 131 pre_path_matrix->mapRect(&final_rect, path_bounds);
132 else 132 else
133 final_rect = path_bounds; 133 final_rect = path_bounds;
134 134
135 GatherPixelRefDevice::drawRect(draw, final_rect, paint); 135 GatherPixelRefDevice::drawRect(draw, final_rect, paint);
136 } 136 }
137 virtual void drawBitmap(const SkDraw& draw, 137 virtual void drawBitmap(const SkDraw& draw,
138 const SkBitmap& bitmap, 138 const SkBitmap& bitmap,
139 const SkIRect* srcRectOrNull, 139 const SkIRect* src_rect_or_null,
140 const SkMatrix& matrix, 140 const SkMatrix& matrix,
141 const SkPaint& paint) SK_OVERRIDE { 141 const SkPaint& paint) SK_OVERRIDE {
142 SkMatrix total_matrix; 142 SkMatrix total_matrix;
143 total_matrix.setConcat(*draw.fMatrix, matrix); 143 total_matrix.setConcat(*draw.fMatrix, matrix);
144 144
145 SkRect bitmap_rect = SkRect::MakeWH(bitmap.width(), bitmap.height()); 145 SkRect bitmap_rect = SkRect::MakeWH(bitmap.width(), bitmap.height());
146 SkRect mapped_rect; 146 SkRect mapped_rect;
147 total_matrix.mapRect(&mapped_rect, bitmap_rect); 147 total_matrix.mapRect(&mapped_rect, bitmap_rect);
148 addBitmap(bitmap, mapped_rect); 148 AddBitmap(bitmap, mapped_rect);
149 149
150 SkBitmap paint_bitmap; 150 SkBitmap paint_bitmap;
151 if (getBitmapFromPaint(paint, &paint_bitmap)) 151 if (GetBitmapFromPaint(paint, &paint_bitmap))
152 addBitmap(paint_bitmap, mapped_rect); 152 AddBitmap(paint_bitmap, mapped_rect);
153 } 153 }
154 virtual void drawBitmapRect(const SkDraw& draw, 154 virtual void drawBitmapRect(const SkDraw& draw,
155 const SkBitmap& bitmap, 155 const SkBitmap& bitmap,
156 const SkRect* srcOrNull, 156 const SkRect* src_or_null,
157 const SkRect& dst, 157 const SkRect& dst,
158 const SkPaint& paint) SK_OVERRIDE { 158 const SkPaint& paint) SK_OVERRIDE {
159 SkRect bitmap_rect = SkRect::MakeWH(bitmap.width(), bitmap.height()); 159 SkRect bitmap_rect = SkRect::MakeWH(bitmap.width(), bitmap.height());
160 SkMatrix matrix; 160 SkMatrix matrix;
161 matrix.setRectToRect(bitmap_rect, dst, SkMatrix::kFill_ScaleToFit); 161 matrix.setRectToRect(bitmap_rect, dst, SkMatrix::kFill_ScaleToFit);
162 GatherPixelRefDevice::drawBitmap(draw, bitmap, NULL, matrix, paint); 162 GatherPixelRefDevice::drawBitmap(draw, bitmap, NULL, matrix, paint);
163 } 163 }
164 virtual void drawSprite(const SkDraw& draw, 164 virtual void drawSprite(const SkDraw& draw,
165 const SkBitmap& bitmap, 165 const SkBitmap& bitmap,
166 int x, 166 int x,
167 int y, 167 int y,
168 const SkPaint& paint) SK_OVERRIDE { 168 const SkPaint& paint) SK_OVERRIDE {
169 // Sprites aren't affected by current matrix, so we can't reuse drawRect. 169 // Sprites aren't affected by current matrix, so we can't reuse drawRect.
170 SkMatrix matrix; 170 SkMatrix matrix;
171 matrix.setTranslate(x, y); 171 matrix.setTranslate(x, y);
172 172
173 SkRect bitmap_rect = SkRect::MakeWH(bitmap.width(), bitmap.height()); 173 SkRect bitmap_rect = SkRect::MakeWH(bitmap.width(), bitmap.height());
174 SkRect mapped_rect; 174 SkRect mapped_rect;
175 matrix.mapRect(&mapped_rect, bitmap_rect); 175 matrix.mapRect(&mapped_rect, bitmap_rect);
176 176
177 addBitmap(bitmap, mapped_rect); 177 AddBitmap(bitmap, mapped_rect);
178 SkBitmap paint_bitmap; 178 SkBitmap paint_bitmap;
179 if (getBitmapFromPaint(paint, &paint_bitmap)) 179 if (GetBitmapFromPaint(paint, &paint_bitmap))
180 addBitmap(paint_bitmap, mapped_rect); 180 AddBitmap(paint_bitmap, mapped_rect);
181 } 181 }
182 virtual void drawText(const SkDraw& draw, 182 virtual void drawText(const SkDraw& draw,
183 const void* text, 183 const void* text,
184 size_t len, 184 size_t len,
185 SkScalar x, 185 SkScalar x,
186 SkScalar y, 186 SkScalar y,
187 const SkPaint& paint) SK_OVERRIDE { 187 const SkPaint& paint) SK_OVERRIDE {
188 SkBitmap bitmap; 188 SkBitmap bitmap;
189 if (!getBitmapFromPaint(paint, &bitmap)) 189 if (!GetBitmapFromPaint(paint, &bitmap))
190 return; 190 return;
191 191
192 // Math is borrowed from SkBBoxRecord 192 // Math is borrowed from SkBBoxRecord
193 SkRect bounds; 193 SkRect bounds;
194 paint.measureText(text, len, &bounds); 194 paint.measureText(text, len, &bounds);
195 SkPaint::FontMetrics metrics; 195 SkPaint::FontMetrics metrics;
196 paint.getFontMetrics(&metrics); 196 paint.getFontMetrics(&metrics);
197 197
198 if (paint.isVerticalText()) { 198 if (paint.isVerticalText()) {
199 SkScalar h = bounds.fBottom - bounds.fTop; 199 SkScalar h = bounds.fBottom - bounds.fTop;
200 if (paint.getTextAlign() == SkPaint::kCenter_Align) { 200 if (paint.getTextAlign() == SkPaint::kCenter_Align) {
201 bounds.fTop -= h / 2; 201 bounds.fTop -= h / 2;
202 bounds.fBottom -= h / 2; 202 bounds.fBottom -= h / 2;
203 } 203 }
204 bounds.fBottom += metrics.fBottom; 204 bounds.fBottom += metrics.fBottom;
205 bounds.fTop += metrics.fTop; 205 bounds.fTop += metrics.fTop;
206 } 206 } else {
207 else {
208 SkScalar w = bounds.fRight - bounds.fLeft; 207 SkScalar w = bounds.fRight - bounds.fLeft;
209 if (paint.getTextAlign() == SkPaint::kCenter_Align) { 208 if (paint.getTextAlign() == SkPaint::kCenter_Align) {
210 bounds.fLeft -= w / 2; 209 bounds.fLeft -= w / 2;
211 bounds.fRight -= w / 2; 210 bounds.fRight -= w / 2;
212 } else if (paint.getTextAlign() == SkPaint::kRight_Align) { 211 } else if (paint.getTextAlign() == SkPaint::kRight_Align) {
213 bounds.fLeft -= w; 212 bounds.fLeft -= w;
214 bounds.fRight -= w; 213 bounds.fRight -= w;
215 } 214 }
216 bounds.fTop = metrics.fTop; 215 bounds.fTop = metrics.fTop;
217 bounds.fBottom = metrics.fBottom; 216 bounds.fBottom = metrics.fBottom;
218 } 217 }
219 218
220 SkScalar pad = (metrics.fBottom - metrics.fTop) / 2; 219 SkScalar pad = (metrics.fBottom - metrics.fTop) / 2;
221 bounds.fLeft -= pad; 220 bounds.fLeft -= pad;
222 bounds.fRight += pad; 221 bounds.fRight += pad;
223 bounds.fLeft += x; 222 bounds.fLeft += x;
224 bounds.fRight += x; 223 bounds.fRight += x;
225 bounds.fTop += y; 224 bounds.fTop += y;
226 bounds.fBottom += y; 225 bounds.fBottom += y;
227 226
228 GatherPixelRefDevice::drawRect(draw, bounds, paint); 227 GatherPixelRefDevice::drawRect(draw, bounds, paint);
229 } 228 }
230 virtual void drawPosText(const SkDraw& draw, 229 virtual void drawPosText(const SkDraw& draw,
231 const void* text, 230 const void* text,
232 size_t len, 231 size_t len,
233 const SkScalar pos[], 232 const SkScalar pos[],
234 SkScalar constY, 233 SkScalar const_y,
235 int scalarsPerPos, 234 int scalars_per_pos,
236 const SkPaint& paint) SK_OVERRIDE { 235 const SkPaint& paint) SK_OVERRIDE {
237 SkBitmap bitmap; 236 SkBitmap bitmap;
238 if (!getBitmapFromPaint(paint, &bitmap)) 237 if (!GetBitmapFromPaint(paint, &bitmap))
239 return; 238 return;
240 239
241 if (len == 0) 240 if (len == 0)
242 return; 241 return;
243 242
244 // Similar to SkDraw asserts. 243 // Similar to SkDraw asserts.
245 SkASSERT(scalarsPerPos == 1 || scalarsPerPos == 2); 244 SkASSERT(scalars_per_pos == 1 || scalars_per_pos == 2);
246 245
247 SkPoint min_point; 246 SkPoint min_point;
248 SkPoint max_point; 247 SkPoint max_point;
249 if (scalarsPerPos == 1) { 248 if (scalars_per_pos == 1) {
250 min_point.set(pos[0], constY); 249 min_point.set(pos[0], const_y);
251 max_point.set(pos[0], constY); 250 max_point.set(pos[0], const_y);
252 } else if (scalarsPerPos == 2) { 251 } else if (scalars_per_pos == 2) {
253 min_point.set(pos[0], constY + pos[1]); 252 min_point.set(pos[0], const_y + pos[1]);
254 max_point.set(pos[0], constY + pos[1]); 253 max_point.set(pos[0], const_y + pos[1]);
255 } 254 }
256 255
257 for (size_t i = 0; i < len; ++i) { 256 for (size_t i = 0; i < len; ++i) {
258 SkScalar x = pos[i * scalarsPerPos]; 257 SkScalar x = pos[i * scalars_per_pos];
259 SkScalar y = constY; 258 SkScalar y = const_y;
260 if (scalarsPerPos == 2) 259 if (scalars_per_pos == 2)
261 y += pos[i * scalarsPerPos + 1]; 260 y += pos[i * scalars_per_pos + 1];
262 261
263 min_point.set( 262 min_point.set(std::min(x, min_point.x()), std::min(y, min_point.y()));
264 std::min(x, min_point.x()), 263 max_point.set(std::max(x, max_point.x()), std::max(y, max_point.y()));
265 std::min(y, min_point.y()));
266 max_point.set(
267 std::max(x, max_point.x()),
268 std::max(y, max_point.y()));
269 } 264 }
270 265
271 SkRect bounds = SkRect::MakeLTRB( 266 SkRect bounds = SkRect::MakeLTRB(
272 min_point.x(), min_point.y(), max_point.x(), max_point.y()); 267 min_point.x(), min_point.y(), max_point.x(), max_point.y());
273 268
274 // Math is borrowed from SkBBoxRecord 269 // Math is borrowed from SkBBoxRecord
275 SkPaint::FontMetrics metrics; 270 SkPaint::FontMetrics metrics;
276 paint.getFontMetrics(&metrics); 271 paint.getFontMetrics(&metrics);
277 272
278 bounds.fTop += metrics.fTop; 273 bounds.fTop += metrics.fTop;
279 bounds.fBottom += metrics.fBottom; 274 bounds.fBottom += metrics.fBottom;
280 275
281 SkScalar pad = (metrics.fTop - metrics.fBottom) / 2; 276 SkScalar pad = (metrics.fTop - metrics.fBottom) / 2;
282 bounds.fLeft += pad; 277 bounds.fLeft += pad;
283 bounds.fRight -= pad; 278 bounds.fRight -= pad;
284 279
285 GatherPixelRefDevice::drawRect(draw, bounds, paint); 280 GatherPixelRefDevice::drawRect(draw, bounds, paint);
286 } 281 }
287 virtual void drawTextOnPath(const SkDraw& draw, 282 virtual void drawTextOnPath(const SkDraw& draw,
288 const void* text, 283 const void* text,
289 size_t len, 284 size_t len,
290 const SkPath& path, 285 const SkPath& path,
291 const SkMatrix* matrix, 286 const SkMatrix* matrix,
292 const SkPaint& paint) SK_OVERRIDE { 287 const SkPaint& paint) SK_OVERRIDE {
293 SkBitmap bitmap; 288 SkBitmap bitmap;
294 if (!getBitmapFromPaint(paint, &bitmap)) 289 if (!GetBitmapFromPaint(paint, &bitmap))
295 return; 290 return;
296 291
297 // Math is borrowed from SkBBoxRecord 292 // Math is borrowed from SkBBoxRecord
298 SkRect bounds = path.getBounds(); 293 SkRect bounds = path.getBounds();
299 SkPaint::FontMetrics metrics; 294 SkPaint::FontMetrics metrics;
300 paint.getFontMetrics(&metrics); 295 paint.getFontMetrics(&metrics);
301 296
302 SkScalar pad = metrics.fTop; 297 SkScalar pad = metrics.fTop;
303 bounds.fLeft += pad; 298 bounds.fLeft += pad;
304 bounds.fRight -= pad; 299 bounds.fRight -= pad;
305 bounds.fTop += pad; 300 bounds.fTop += pad;
306 bounds.fBottom -= pad; 301 bounds.fBottom -= pad;
307 302
308 GatherPixelRefDevice::drawRect(draw, bounds, paint); 303 GatherPixelRefDevice::drawRect(draw, bounds, paint);
309 } 304 }
310 virtual void drawVertices(const SkDraw& draw, 305 virtual void drawVertices(const SkDraw& draw,
311 SkCanvas::VertexMode, 306 SkCanvas::VertexMode,
312 int vertexCount, 307 int vertex_count,
313 const SkPoint verts[], 308 const SkPoint verts[],
314 const SkPoint texs[], 309 const SkPoint texs[],
315 const SkColor colors[], 310 const SkColor colors[],
316 SkXfermode* xmode, 311 SkXfermode* xmode,
317 const uint16_t indices[], 312 const uint16_t indices[],
318 int indexCount, 313 int index_count,
319 const SkPaint& paint) SK_OVERRIDE { 314 const SkPaint& paint) SK_OVERRIDE {
320 GatherPixelRefDevice::drawPoints( 315 GatherPixelRefDevice::drawPoints(
321 draw, SkCanvas::kPolygon_PointMode, vertexCount, verts, paint); 316 draw, SkCanvas::kPolygon_PointMode, vertex_count, verts, paint);
322 } 317 }
323 virtual void drawDevice(const SkDraw&, 318 virtual void drawDevice(const SkDraw&,
324 SkDevice*, 319 SkDevice*,
325 int x, 320 int x,
326 int y, 321 int y,
327 const SkPaint&) SK_OVERRIDE {} 322 const SkPaint&) SK_OVERRIDE {}
328 323
329 protected: 324 protected:
330 virtual bool onReadPixels(const SkBitmap& bitmap, 325 virtual bool onReadPixels(const SkBitmap& bitmap,
331 int x, 326 int x,
332 int y, 327 int y,
333 SkCanvas::Config8888 config8888) SK_OVERRIDE { 328 SkCanvas::Config8888 config8888) SK_OVERRIDE {
334 return false; 329 return false;
335 } 330 }
336 331
337 private: 332 private:
338 LazyPixelRefSet* lazy_pixel_ref_set_; 333 LazyPixelRefSet* lazy_pixel_ref_set_;
339 334
340 void addBitmap(const SkBitmap& bm, const SkRect& rect) { 335 void AddBitmap(const SkBitmap& bm, const SkRect& rect) {
341 lazy_pixel_ref_set_->add(bm.pixelRef(), rect); 336 lazy_pixel_ref_set_->Add(bm.pixelRef(), rect);
342 } 337 }
343 338
344 bool getBitmapFromPaint(const SkPaint& paint, SkBitmap* bm) { 339 bool GetBitmapFromPaint(const SkPaint& paint, SkBitmap* bm) {
345 SkShader* shader = paint.getShader(); 340 SkShader* shader = paint.getShader();
346 if (shader) { 341 if (shader) {
347 // Check whether the shader is a gradient in order to prevent generation 342 // Check whether the shader is a gradient in order to prevent generation
348 // of bitmaps from gradient shaders, which implement asABitmap. 343 // of bitmaps from gradient shaders, which implement asABitmap.
349 if (SkShader::kNone_GradientType == shader->asAGradient(NULL)) 344 if (SkShader::kNone_GradientType == shader->asAGradient(NULL))
350 return shader->asABitmap(bm, NULL, NULL); 345 return shader->asABitmap(bm, NULL, NULL);
351 } 346 }
352 return false; 347 return false;
353 } 348 }
354
355 }; 349 };
356 350
357 class NoSaveLayerCanvas : public SkCanvas { 351 class NoSaveLayerCanvas : public SkCanvas {
358 public: 352 public:
359 NoSaveLayerCanvas(SkDevice* device) : INHERITED(device) {} 353 NoSaveLayerCanvas(SkDevice* device) : INHERITED(device) {}
360 354
361 // Turn saveLayer() into save() for speed, should not affect correctness. 355 // Turn saveLayer() into save() for speed, should not affect correctness.
362 virtual int saveLayer(const SkRect* bounds, 356 virtual int saveLayer(const SkRect* bounds,
363 const SkPaint* paint, 357 const SkPaint* paint,
364 SaveFlags flags) SK_OVERRIDE { 358 SaveFlags flags) SK_OVERRIDE {
(...skipping 29 matching lines...) Expand all
394 }; 388 };
395 389
396 } // namespace 390 } // namespace
397 391
398 void LazyPixelRefUtils::GatherPixelRefs( 392 void LazyPixelRefUtils::GatherPixelRefs(
399 SkPicture* picture, 393 SkPicture* picture,
400 std::vector<PositionLazyPixelRef>* lazy_pixel_refs) { 394 std::vector<PositionLazyPixelRef>* lazy_pixel_refs) {
401 lazy_pixel_refs->clear(); 395 lazy_pixel_refs->clear();
402 LazyPixelRefSet pixel_ref_set(lazy_pixel_refs); 396 LazyPixelRefSet pixel_ref_set(lazy_pixel_refs);
403 397
404 SkBitmap emptyBitmap; 398 SkBitmap empty_bitmap;
405 emptyBitmap.setConfig( 399 empty_bitmap.setConfig(
406 SkBitmap::kNo_Config, picture->width(), picture->height()); 400 SkBitmap::kNo_Config, picture->width(), picture->height());
407 401
408 GatherPixelRefDevice device(emptyBitmap, &pixel_ref_set); 402 GatherPixelRefDevice device(empty_bitmap, &pixel_ref_set);
409 NoSaveLayerCanvas canvas(&device); 403 NoSaveLayerCanvas canvas(&device);
410 404
411 canvas.clipRect(SkRect::MakeWH(picture->width(), picture->height()), 405 canvas.clipRect(SkRect::MakeWH(picture->width(), picture->height()),
412 SkRegion::kIntersect_Op, 406 SkRegion::kIntersect_Op,
413 false); 407 false);
414 canvas.drawPicture(*picture); 408 canvas.drawPicture(*picture);
415 } 409 }
416 410
417 } // namespace skia 411 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/lazy_pixel_ref_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698