OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkAnnotation.h" | 8 #include "SkAnnotation.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColorFilter.h" | 10 #include "SkColorFilter.h" |
11 #include "SkDrawLooper.h" | 11 #include "SkDrawLooper.h" |
12 #include "SkImage.h" | |
12 #include "SkImageFilter.h" | 13 #include "SkImageFilter.h" |
13 #include "SkMaskFilter.h" | 14 #include "SkMaskFilter.h" |
14 #include "SkPath.h" | 15 #include "SkPath.h" |
15 #include "SkPathEffect.h" | 16 #include "SkPathEffect.h" |
16 #include "SkRasterizer.h" | 17 #include "SkRasterizer.h" |
17 #include "SkRect.h" | 18 #include "SkRect.h" |
18 #include "SkRemote.h" | 19 #include "SkRemote.h" |
19 #include "SkShader.h" | 20 #include "SkShader.h" |
20 #include "SkTHash.h" | 21 #include "SkTHash.h" |
21 | 22 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 Encoder::CommonIDs fIDs; | 154 Encoder::CommonIDs fIDs; |
154 }; | 155 }; |
155 | 156 |
156 template <typename T> | 157 template <typename T> |
157 AutoID id(const T& val) { return AutoID(fEncoder, val); } | 158 AutoID id(const T& val) { return AutoID(fEncoder, val); } |
158 | 159 |
159 AutoCommonIDs commonIDs(const SkPaint& paint) { return AutoCommonIDs(fEn coder, paint); } | 160 AutoCommonIDs commonIDs(const SkPaint& paint) { return AutoCommonIDs(fEn coder, paint); } |
160 | 161 |
161 void willSave() override { fEncoder-> save(); } | 162 void willSave() override { fEncoder-> save(); } |
162 void didRestore() override { fEncoder->restore(); } | 163 void didRestore() override { fEncoder->restore(); } |
164 SaveLayerStrategy willSaveLayer(const SkRect* bounds, | |
165 const SkPaint* paint, | |
166 SaveFlags flags) override { | |
167 // TODO | |
168 return kNoLayer_SaveLayerStrategy; | |
169 } | |
163 | 170 |
164 void didConcat(const SkMatrix&) override { this->didSetMatrix(this->g etTotalMatrix()); } | 171 void didConcat(const SkMatrix&) override { this->didSetMatrix(this->g etTotalMatrix()); } |
165 void didSetMatrix(const SkMatrix& matrix) override { | 172 void didSetMatrix(const SkMatrix& matrix) override { |
166 fEncoder->setMatrix(this->id(matrix)); | 173 fEncoder->setMatrix(this->id(matrix)); |
167 } | 174 } |
168 | 175 |
169 void onDrawOval(const SkRect& oval, const SkPaint& paint) override { | 176 void onDrawOval(const SkRect& oval, const SkPaint& paint) override { |
170 SkPath path; | 177 SkPath path; |
171 path.addOval(oval); | 178 path.addOval(oval); |
172 this->onDrawPath(path, paint); | 179 this->onDrawPath(path, paint); |
(...skipping 30 matching lines...) Expand all Loading... | |
203 fEncoder->strokePath(p, common, this->id(Stroke::CreateFrom(pain t))); | 210 fEncoder->strokePath(p, common, this->id(Stroke::CreateFrom(pain t))); |
204 } | 211 } |
205 } | 212 } |
206 | 213 |
207 void onDrawPaint(const SkPaint& paint) override { | 214 void onDrawPaint(const SkPaint& paint) override { |
208 SkPath path; | 215 SkPath path; |
209 path.setFillType(SkPath::kInverseWinding_FillType); // Either inver se FillType is fine. | 216 path.setFillType(SkPath::kInverseWinding_FillType); // Either inver se FillType is fine. |
210 this->onDrawPath(path, paint); | 217 this->onDrawPath(path, paint); |
211 } | 218 } |
212 | 219 |
220 void onDrawPoints(PointMode mode, | |
221 size_t count, | |
222 const SkPoint pts[], | |
223 const SkPaint& paint) override { | |
224 // TODO | |
225 } | |
226 | |
227 void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) overri de { | |
228 // TODO | |
229 } | |
230 | |
231 void onDrawPicture(const SkPicture* pic, | |
232 const SkMatrix* matrix, | |
233 const SkPaint* paint) override { | |
234 // TODO | |
hal.canary
2015/11/03 15:09:56
Isn't
this->INHERITED::onDrawPicture(pic, m
mtklein
2015/11/03 15:24:30
Done.
| |
235 } | |
236 | |
237 void onDrawVertices(VertexMode vmode, | |
238 int vertexCount, | |
239 const SkPoint vertices[], | |
240 const SkPoint texs[], | |
241 const SkColor colors[], | |
242 SkXfermode* xmode, | |
243 const uint16_t indices[], | |
244 int indexCount, | |
245 const SkPaint& paint) override { | |
246 // TODO | |
247 } | |
248 | |
249 void onDrawPatch(const SkPoint cubics[12], | |
250 const SkColor colors[4], | |
251 const SkPoint texCoords[4], | |
252 SkXfermode* xmode, | |
253 const SkPaint& paint) override { | |
254 // TODO | |
255 } | |
256 | |
257 void onDrawAtlas(const SkImage* atlas, | |
258 const SkRSXform xform[], | |
259 const SkRect tex[], | |
260 const SkColor colors[], | |
261 int count, | |
262 SkXfermode::Mode mode, | |
263 const SkRect* cull, | |
264 const SkPaint* paint) override { | |
265 // TODO | |
266 } | |
267 | |
268 void onDrawBitmap(const SkBitmap& bitmap, | |
269 SkScalar left, | |
270 SkScalar top, | |
271 const SkPaint* paint) override { | |
272 auto src = SkRect::MakeWH(bitmap.width(), bitmap.height()), | |
273 dst = src.makeOffset(left, top); | |
274 this->onDrawBitmapRect(bitmap, &src, dst, paint, kStrict_SrcRectCons traint); | |
275 } | |
276 | |
277 void onDrawBitmapRect(const SkBitmap& bitmap, | |
278 const SkRect* src, | |
279 const SkRect& dst, | |
280 const SkPaint* paint, | |
281 SrcRectConstraint constraint) override { | |
282 SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bitmap)); | |
283 this->onDrawImageRect(image, src, dst, paint, constraint); | |
284 } | |
285 | |
286 void onDrawImage(const SkImage* image, | |
287 SkScalar left, | |
288 SkScalar top, | |
289 const SkPaint* paint) override { | |
290 if (!image) { | |
291 return; | |
292 } | |
293 auto src = SkRect::MakeWH(image->width(), image->height()), | |
294 dst = src.makeOffset(left, top); | |
295 this->onDrawImageRect(image, &src, dst, paint, kStrict_SrcRectConstr aint); | |
296 } | |
297 | |
298 void onDrawImageRect(const SkImage* image, | |
299 const SkRect* src, | |
300 const SkRect& dst, | |
301 const SkPaint* paint, | |
302 SrcRectConstraint constraint) override { | |
303 // TODO: this is all a (likely buggy) hack to get images drawing qui ckly. | |
304 if (!image) { | |
305 return; | |
306 } | |
307 | |
308 auto bounds = SkRect::MakeWH(image->width(), image->height()); | |
309 if (!src) { | |
310 src = &bounds; | |
311 } | |
312 auto matrix = SkMatrix::MakeRectToRect(*src, dst, SkMatrix::kFill_Sc aleToFit); | |
313 | |
314 SkAutoTUnref<SkImage> subset; | |
315 if (src) { | |
316 if (!bounds.intersect(*src)) { | |
317 return; | |
318 } | |
319 subset.reset(image->newSubset(bounds.roundOut())); | |
320 image = subset; | |
321 } | |
322 | |
323 auto paintWithShader = paint ? *paint : SkPaint(); | |
324 SkAutoTUnref<SkShader> shader( | |
325 image->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_Til eMode, &matrix)); | |
326 paintWithShader.setShader(shader); | |
327 | |
328 this->onDrawRect(dst, paintWithShader); | |
329 } | |
330 | |
331 void onDrawBitmapNine(const SkBitmap& bitmap, | |
332 const SkIRect& center, | |
333 const SkRect& dst, | |
334 const SkPaint* paint) override { | |
335 // TODO | |
hal.canary
2015/11/03 15:04:01
SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap
mtklein
2015/11/03 15:24:31
Done.
| |
336 } | |
337 | |
338 void onDrawImageNine(const SkImage* image, | |
339 const SkIRect& center, | |
340 const SkRect& dst, | |
341 const SkPaint* paint) override { | |
342 // TODO | |
hal.canary
2015/11/03 15:04:01
SkNinePatchIter iter(image->width(), image->height
mtklein
2015/11/03 15:24:31
Done.
| |
343 } | |
344 | |
213 void onDrawText(const void* text, size_t byteLength, | 345 void onDrawText(const void* text, size_t byteLength, |
214 SkScalar x, SkScalar y, const SkPaint& paint) override { | 346 SkScalar x, SkScalar y, const SkPaint& paint) override { |
215 // Text-as-paths is a temporary hack. | 347 // Text-as-paths is a temporary hack. |
216 // TODO: send SkTextBlobs and SkTypefaces | 348 // TODO: send SkTextBlobs and SkTypefaces |
217 SkPath path; | 349 SkPath path; |
218 paint.getTextPath(text, byteLength, x, y, &path); | 350 paint.getTextPath(text, byteLength, x, y, &path); |
219 this->onDrawPath(path, paint); | 351 this->onDrawPath(path, paint); |
220 } | 352 } |
221 | 353 |
222 void onDrawPosText(const void* text, size_t byteLength, | 354 void onDrawPosText(const void* text, size_t byteLength, |
223 const SkPoint pos[], const SkPaint& paint) override { | 355 const SkPoint pos[], const SkPaint& paint) override { |
224 // Text-as-paths is a temporary hack. | 356 // Text-as-paths is a temporary hack. |
225 // TODO: send SkTextBlobs and SkTypefaces | 357 // TODO: send SkTextBlobs and SkTypefaces |
226 SkPath path; | 358 SkPath path; |
227 paint.getPosTextPath(text, byteLength, pos, &path); | 359 paint.getPosTextPath(text, byteLength, pos, &path); |
228 this->onDrawPath(path, paint); | 360 this->onDrawPath(path, paint); |
229 } | 361 } |
230 | 362 |
231 void onDrawPosTextH(const void* text, size_t byteLength, | 363 void onDrawPosTextH(const void* text, size_t byteLength, |
232 const SkScalar xpos[], SkScalar constY, const SkPain t& paint) override { | 364 const SkScalar xpos[], SkScalar constY, const SkPain t& paint) override { |
233 size_t length = paint.countText(text, byteLength); | 365 size_t length = paint.countText(text, byteLength); |
234 SkAutoTArray<SkPoint> pos(length); | 366 SkAutoTArray<SkPoint> pos(length); |
235 for(size_t i = 0; i < length; ++i) { | 367 for(size_t i = 0; i < length; ++i) { |
236 pos[i].set(xpos[i], constY); | 368 pos[i].set(xpos[i], constY); |
237 } | 369 } |
238 this->onDrawPosText(text, byteLength, &pos[0], paint); | 370 this->onDrawPosText(text, byteLength, &pos[0], paint); |
239 } | 371 } |
240 | 372 |
241 void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeS tyle) override { | 373 void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeS tyle) override { |
374 this->INHERITED::onClipRect(rect, op, edgeStyle); | |
hal.canary
2015/11/03 15:04:01
// Please add comment explaining why we need this.
mtklein
2015/11/03 15:24:31
// Done.
| |
242 SkPath path; | 375 SkPath path; |
243 path.addRect(rect); | 376 path.addRect(rect); |
244 this->onClipPath(path, op, edgeStyle); | 377 this->onClipPath(path, op, edgeStyle); |
245 } | 378 } |
246 | 379 |
247 void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle ed geStyle) override { | 380 void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle ed geStyle) override { |
381 this->INHERITED::onClipRRect(rrect, op, edgeStyle); | |
248 SkPath path; | 382 SkPath path; |
249 path.addRRect(rrect); | 383 path.addRRect(rrect); |
250 this->onClipPath(path, op, edgeStyle); | 384 this->onClipPath(path, op, edgeStyle); |
251 } | 385 } |
252 | 386 |
253 void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeS tyle) override { | 387 void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeS tyle) override { |
388 this->INHERITED::onClipPath(path, op, edgeStyle); | |
254 fEncoder->clipPath(this->id(path), op, edgeStyle == kSoft_ClipEdgeSt yle); | 389 fEncoder->clipPath(this->id(path), op, edgeStyle == kSoft_ClipEdgeSt yle); |
255 } | 390 } |
256 | 391 |
392 void onClipRegion(const SkRegion& region, SkRegion::Op op) override { | |
393 this->INHERITED::onClipRegion(region, op); | |
394 // TODO | |
395 } | |
396 | |
257 Encoder* fEncoder; | 397 Encoder* fEncoder; |
398 typedef SkCanvas INHERITED; | |
258 }; | 399 }; |
259 | 400 |
260 SkCanvas* NewCanvas(Encoder* encoder) { return new Canvas(encoder); } | 401 SkCanvas* NewCanvas(Encoder* encoder) { return new Canvas(encoder); } |
261 | 402 |
262 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // | 403 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // |
263 | 404 |
264 class Decoder final : public Encoder { | 405 class Decoder final : public Encoder { |
265 public: | 406 public: |
266 explicit Decoder(SkCanvas* canvas) : fCanvas(canvas) {} | 407 explicit Decoder(SkCanvas* canvas) : fCanvas(canvas) {} |
267 | 408 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 RefKeyMap<SkDrawLooper , Type::kDrawLooper > fDrawLooper; | 682 RefKeyMap<SkDrawLooper , Type::kDrawLooper > fDrawLooper; |
542 RefKeyMap<SkImageFilter, Type::kImageFilter> fImageFilter; | 683 RefKeyMap<SkImageFilter, Type::kImageFilter> fImageFilter; |
543 RefKeyMap<SkAnnotation , Type::kAnnotation > fAnnotation; | 684 RefKeyMap<SkAnnotation , Type::kAnnotation > fAnnotation; |
544 | 685 |
545 Encoder* fWrapped; | 686 Encoder* fWrapped; |
546 }; | 687 }; |
547 | 688 |
548 Encoder* NewCachingEncoder(Encoder* wrapped) { return new CachingEncoder(wra pped); } | 689 Encoder* NewCachingEncoder(Encoder* wrapped) { return new CachingEncoder(wra pped); } |
549 | 690 |
550 } // namespace SkRemote | 691 } // namespace SkRemote |
OLD | NEW |