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

Side by Side Diff: src/pipe/SkGPipeWrite.cpp

Issue 1129843003: Make drawImage a virtual on SkDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 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 | « src/pipe/SkGPipeRead.cpp ('k') | src/utils/SkDeferredCanvas.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkAnnotation.h" 9 #include "SkAnnotation.h"
10 #include "SkBitmapDevice.h" 10 #include "SkBitmapDevice.h"
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 const SkPaint& paint) override; 265 const SkPaint& paint) override;
266 void onDrawPaint(const SkPaint&) override; 266 void onDrawPaint(const SkPaint&) override;
267 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPain t&) override; 267 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPain t&) override;
268 void onDrawRect(const SkRect&, const SkPaint&) override; 268 void onDrawRect(const SkRect&, const SkPaint&) override;
269 void onDrawOval(const SkRect&, const SkPaint&) override; 269 void onDrawOval(const SkRect&, const SkPaint&) override;
270 void onDrawRRect(const SkRRect&, const SkPaint&) override; 270 void onDrawRRect(const SkRRect&, const SkPaint&) override;
271 void onDrawPath(const SkPath&, const SkPaint&) override; 271 void onDrawPath(const SkPath&, const SkPaint&) override;
272 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPain t*) override; 272 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPain t*) override;
273 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*, 273 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
274 DrawBitmapRectFlags flags) override; 274 DrawBitmapRectFlags flags) override;
275 #if 0
276 // rely on decomposition into bitmap (for now)
277 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint* ) override; 275 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint* ) override;
278 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst, 276 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
279 const SkPaint*) override; 277 const SkPaint*) override;
280 #endif
281 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, 278 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
282 const SkPaint*) override; 279 const SkPaint*) override;
283 void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*) overri de; 280 void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*) overri de;
284 void onDrawVertices(VertexMode vmode, int vertexCount, 281 void onDrawVertices(VertexMode vmode, int vertexCount,
285 const SkPoint vertices[], const SkPoint texs[], 282 const SkPoint vertices[], const SkPoint texs[],
286 const SkColor colors[], SkXfermode* xmode, 283 const SkColor colors[], SkXfermode* xmode,
287 const uint16_t indices[], int indexCount, 284 const uint16_t indices[], int indexCount,
288 const SkPaint&) override; 285 const SkPaint&) override;
289 void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) override; 286 void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) override;
290 void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override; 287 void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override;
291 void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) override; 288 void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) override;
292 void onClipRegion(const SkRegion&, SkRegion::Op) override; 289 void onClipRegion(const SkRegion&, SkRegion::Op) override;
293 290
294 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) overri de; 291 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) overri de;
295 292
296 private: 293 private:
297 void recordTranslate(const SkMatrix&); 294 void recordTranslate(const SkMatrix&);
298 void recordScale(const SkMatrix&); 295 void recordScale(const SkMatrix&);
299 void recordConcat(const SkMatrix&); 296 void recordConcat(const SkMatrix&);
300 297
301 SkNamedFactorySet* fFactorySet; 298 SkNamedFactorySet* fFactorySet;
302 SkBitmapHeap* fBitmapHeap; 299 SkBitmapHeap* fBitmapHeap;
300 SkImageHeap* fImageHeap;
303 SkGPipeController* fController; 301 SkGPipeController* fController;
304 SkWriter32& fWriter; 302 SkWriter32& fWriter;
305 size_t fBlockSize; // amount allocated for writer 303 size_t fBlockSize; // amount allocated for writer
306 size_t fBytesNotified; 304 size_t fBytesNotified;
307 bool fDone; 305 bool fDone;
308 const uint32_t fFlags; 306 const uint32_t fFlags;
309 307
310 SkRefCntSet fTypefaceSet; 308 SkRefCntSet fTypefaceSet;
311 309
312 uint32_t getTypefaceID(SkTypeface*); 310 uint32_t getTypefaceID(SkTypeface*);
(...skipping 28 matching lines...) Expand all
341 339
342 FlattenableHeap fFlattenableHeap; 340 FlattenableHeap fFlattenableHeap;
343 FlatDictionary fFlatDictionary; 341 FlatDictionary fFlatDictionary;
344 SkAutoTUnref<BitmapShuttle> fBitmapShuttle; 342 SkAutoTUnref<BitmapShuttle> fBitmapShuttle;
345 int fCurrFlatIndex[kCount_PaintFlats]; 343 int fCurrFlatIndex[kCount_PaintFlats];
346 344
347 int flattenToIndex(SkFlattenable* obj, PaintFlats); 345 int flattenToIndex(SkFlattenable* obj, PaintFlats);
348 346
349 // Common code used by drawBitmap*. Behaves differently depending on the 347 // Common code used by drawBitmap*. Behaves differently depending on the
350 // type of SkBitmapHeap being used, which is determined by the flags used. 348 // type of SkBitmapHeap being used, which is determined by the flags used.
351 bool commonDrawBitmap(const SkBitmap& bm, DrawOps op, unsigned flags, 349 bool commonDrawBitmap(const SkBitmap&, DrawOps, unsigned flags, size_t bytes , const SkPaint*);
352 size_t opBytesNeeded, const SkPaint* paint); 350 bool commonDrawImage(const SkImage*, DrawOps, unsigned flags, size_t bytes, const SkPaint*);
353 351
354 SkPaint fPaint; 352 SkPaint fPaint;
355 void writePaint(const SkPaint&); 353 void writePaint(const SkPaint&);
356 354
357 class AutoPipeNotify { 355 class AutoPipeNotify {
358 public: 356 public:
359 AutoPipeNotify(SkGPipeCanvas* canvas) : fCanvas(canvas) {} 357 AutoPipeNotify(SkGPipeCanvas* canvas) : fCanvas(canvas) {}
360 ~AutoPipeNotify() { fCanvas->doNotify(); } 358 ~AutoPipeNotify() { fCanvas->doNotify(); }
361 private: 359 private:
362 SkGPipeCanvas* fCanvas; 360 SkGPipeCanvas* fCanvas;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, (fBitmapShuttle.get(), BITMAPS_TO _KEEP)); 453 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, (fBitmapShuttle.get(), BITMAPS_TO _KEEP));
456 } else { 454 } else {
457 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, 455 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap,
458 (BITMAPS_TO_KEEP, controller->numberOfReaders() )); 456 (BITMAPS_TO_KEEP, controller->numberOfReaders() ));
459 if (this->needOpBytes(sizeof(void*))) { 457 if (this->needOpBytes(sizeof(void*))) {
460 this->writeOp(kShareBitmapHeap_DrawOp); 458 this->writeOp(kShareBitmapHeap_DrawOp);
461 fWriter.writePtr(static_cast<void*>(fBitmapHeap)); 459 fWriter.writePtr(static_cast<void*>(fBitmapHeap));
462 } 460 }
463 } 461 }
464 fFlattenableHeap.setBitmapStorage(fBitmapHeap); 462 fFlattenableHeap.setBitmapStorage(fBitmapHeap);
463
464 fImageHeap = SkNEW(SkImageHeap);
465 if (this->needOpBytes(sizeof(void*))) {
466 this->writeOp(kShareImageHeap_DrawOp);
467 fWriter.writePtr(static_cast<void*>(fImageHeap));
468 }
469
465 this->doNotify(); 470 this->doNotify();
466 } 471 }
467 472
468 SkGPipeCanvas::~SkGPipeCanvas() { 473 SkGPipeCanvas::~SkGPipeCanvas() {
469 this->finish(true); 474 this->finish(true);
470 SkSafeUnref(fFactorySet); 475 SkSafeUnref(fFactorySet);
471 SkSafeUnref(fBitmapHeap); 476 SkSafeUnref(fBitmapHeap);
477 SkSafeUnref(fImageHeap);
472 } 478 }
473 479
474 bool SkGPipeCanvas::needOpBytes(size_t needed) { 480 bool SkGPipeCanvas::needOpBytes(size_t needed) {
475 if (fDone) { 481 if (fDone) {
476 return false; 482 return false;
477 } 483 }
478 484
479 needed += 4; // size of DrawOp atom 485 needed += 4; // size of DrawOp atom
480 needed = SkAlign4(needed); 486 needed = SkAlign4(needed);
481 if (fWriter.bytesWritten() + needed > fBlockSize) { 487 if (fWriter.bytesWritten() + needed > fBlockSize) {
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 void SkGPipeCanvas::onDrawSprite(const SkBitmap& bm, int left, int top, const Sk Paint* paint) { 822 void SkGPipeCanvas::onDrawSprite(const SkBitmap& bm, int left, int top, const Sk Paint* paint) {
817 NOTIFY_SETUP(this); 823 NOTIFY_SETUP(this);
818 size_t opBytesNeeded = sizeof(int32_t) * 2; 824 size_t opBytesNeeded = sizeof(int32_t) * 2;
819 825
820 if (this->commonDrawBitmap(bm, kDrawSprite_DrawOp, 0, opBytesNeeded, paint)) { 826 if (this->commonDrawBitmap(bm, kDrawSprite_DrawOp, 0, opBytesNeeded, paint)) {
821 fWriter.write32(left); 827 fWriter.write32(left);
822 fWriter.write32(top); 828 fWriter.write32(top);
823 } 829 }
824 } 830 }
825 831
832 bool SkGPipeCanvas::commonDrawImage(const SkImage* image, DrawOps op, unsigned f lags,
833 size_t opBytesNeeded, const SkPaint* paint) {
834 if (fDone) {
835 return false;
836 }
837
838 if (paint != NULL) {
839 flags |= kDrawBitmap_HasPaint_DrawOpFlag;
840 this->writePaint(*paint);
841 }
842 // This needs to run first so its calls to needOpBytes() and its writes
843 // don't interlace with the needOpBytes() and write below.
844 int32_t slot = fImageHeap->insert(image);
845 SkASSERT(slot != 0);
846 if (this->needOpBytes(opBytesNeeded)) {
847 this->writeOp(op, flags, slot);
848 return true;
849 }
850 return false;
851 }
852
853 void SkGPipeCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y,
854 const SkPaint* paint) {
855 NOTIFY_SETUP(this);
856 if (this->commonDrawImage(image, kDrawImage_DrawOp, 0, sizeof(SkScalar) * 2, paint)) {
857 fWriter.writeScalar(x);
858 fWriter.writeScalar(y);
859 }
860 }
861
862 void SkGPipeCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, con st SkRect& dst,
863 const SkPaint* paint) {
864 NOTIFY_SETUP(this);
865 unsigned flags = 0;
866 size_t opBytesNeeded = sizeof(SkRect); // dst
867 if (src) {
868 flags |= kDrawBitmap_HasSrcRect_DrawOpFlag;
869 opBytesNeeded += sizeof(SkRect); // src
870 }
871 if (this->commonDrawImage(image, kDrawImageRect_DrawOp, flags, opBytesNeeded , paint)) {
872 if (src) {
873 fWriter.writeRect(*src);
874 }
875 fWriter.writeRect(dst);
876 }
877 }
878
826 void SkGPipeCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, 879 void SkGPipeCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
827 const SkPaint& paint) { 880 const SkPaint& paint) {
828 if (byteLength) { 881 if (byteLength) {
829 NOTIFY_SETUP(this); 882 NOTIFY_SETUP(this);
830 this->writePaint(paint); 883 this->writePaint(paint);
831 if (this->needOpBytes(4 + SkAlign4(byteLength) + 2 * sizeof(SkScalar))) { 884 if (this->needOpBytes(4 + SkAlign4(byteLength) + 2 * sizeof(SkScalar))) {
832 this->writeOp(kDrawText_DrawOp); 885 this->writeOp(kDrawText_DrawOp);
833 fWriter.write32(SkToU32(byteLength)); 886 fWriter.write32(SkToU32(byteLength));
834 fWriter.writePad(text, byteLength); 887 fWriter.writePad(text, byteLength);
835 fWriter.writeScalar(x); 888 fWriter.writeScalar(x);
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 return fCanvas->shuttleBitmap(bitmap, slot); 1383 return fCanvas->shuttleBitmap(bitmap, slot);
1331 } 1384 }
1332 1385
1333 void BitmapShuttle::removeCanvas() { 1386 void BitmapShuttle::removeCanvas() {
1334 if (NULL == fCanvas) { 1387 if (NULL == fCanvas) {
1335 return; 1388 return;
1336 } 1389 }
1337 fCanvas->unref(); 1390 fCanvas->unref();
1338 fCanvas = NULL; 1391 fCanvas = NULL;
1339 } 1392 }
1393
1394 //////////////////////////////////////////////////////////////////////////////// ///////////////////
1395
1396 SkImageHeap::SkImageHeap() {}
1397
1398 SkImageHeap::~SkImageHeap() {
1399 fArray.unrefAll();
1400 }
1401
1402 const SkImage* SkImageHeap::get(int32_t slot) const {
1403 SkASSERT(slot > 0);
1404 return fArray[slot - 1];
1405 }
1406
1407 int32_t SkImageHeap::find(const SkImage* img) const {
1408 int index = fArray.find(img);
1409 if (index >= 0) {
1410 return index + 1; // found
1411 }
1412 return 0; // not found
1413 }
1414
1415 int32_t SkImageHeap::insert(const SkImage* img) {
1416 int32_t slot = this->find(img);
1417 if (slot) {
1418 return slot;
1419 }
1420 *fArray.append() = SkRef(img);
1421 return fArray.count(); // slot is always index+1
1422 }
1423
OLDNEW
« no previous file with comments | « src/pipe/SkGPipeRead.cpp ('k') | src/utils/SkDeferredCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698