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

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

Issue 1124003002: Revert of 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)
275 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint* ) override; 277 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint* ) override;
276 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst, 278 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
277 const SkPaint*) override; 279 const SkPaint*) override;
280 #endif
278 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, 281 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
279 const SkPaint*) override; 282 const SkPaint*) override;
280 void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*) overri de; 283 void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*) overri de;
281 void onDrawVertices(VertexMode vmode, int vertexCount, 284 void onDrawVertices(VertexMode vmode, int vertexCount,
282 const SkPoint vertices[], const SkPoint texs[], 285 const SkPoint vertices[], const SkPoint texs[],
283 const SkColor colors[], SkXfermode* xmode, 286 const SkColor colors[], SkXfermode* xmode,
284 const uint16_t indices[], int indexCount, 287 const uint16_t indices[], int indexCount,
285 const SkPaint&) override; 288 const SkPaint&) override;
286 void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) override; 289 void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) override;
287 void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override; 290 void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override;
288 void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) override; 291 void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) override;
289 void onClipRegion(const SkRegion&, SkRegion::Op) override; 292 void onClipRegion(const SkRegion&, SkRegion::Op) override;
290 293
291 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) overri de; 294 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) overri de;
292 295
293 private: 296 private:
294 void recordTranslate(const SkMatrix&); 297 void recordTranslate(const SkMatrix&);
295 void recordScale(const SkMatrix&); 298 void recordScale(const SkMatrix&);
296 void recordConcat(const SkMatrix&); 299 void recordConcat(const SkMatrix&);
297 300
298 SkNamedFactorySet* fFactorySet; 301 SkNamedFactorySet* fFactorySet;
299 SkBitmapHeap* fBitmapHeap; 302 SkBitmapHeap* fBitmapHeap;
300 SkImageHeap* fImageHeap;
301 SkGPipeController* fController; 303 SkGPipeController* fController;
302 SkWriter32& fWriter; 304 SkWriter32& fWriter;
303 size_t fBlockSize; // amount allocated for writer 305 size_t fBlockSize; // amount allocated for writer
304 size_t fBytesNotified; 306 size_t fBytesNotified;
305 bool fDone; 307 bool fDone;
306 const uint32_t fFlags; 308 const uint32_t fFlags;
307 309
308 SkRefCntSet fTypefaceSet; 310 SkRefCntSet fTypefaceSet;
309 311
310 uint32_t getTypefaceID(SkTypeface*); 312 uint32_t getTypefaceID(SkTypeface*);
(...skipping 28 matching lines...) Expand all
339 341
340 FlattenableHeap fFlattenableHeap; 342 FlattenableHeap fFlattenableHeap;
341 FlatDictionary fFlatDictionary; 343 FlatDictionary fFlatDictionary;
342 SkAutoTUnref<BitmapShuttle> fBitmapShuttle; 344 SkAutoTUnref<BitmapShuttle> fBitmapShuttle;
343 int fCurrFlatIndex[kCount_PaintFlats]; 345 int fCurrFlatIndex[kCount_PaintFlats];
344 346
345 int flattenToIndex(SkFlattenable* obj, PaintFlats); 347 int flattenToIndex(SkFlattenable* obj, PaintFlats);
346 348
347 // Common code used by drawBitmap*. Behaves differently depending on the 349 // Common code used by drawBitmap*. Behaves differently depending on the
348 // type of SkBitmapHeap being used, which is determined by the flags used. 350 // type of SkBitmapHeap being used, which is determined by the flags used.
349 bool commonDrawBitmap(const SkBitmap&, DrawOps, unsigned flags, size_t bytes , const SkPaint*); 351 bool commonDrawBitmap(const SkBitmap& bm, DrawOps op, unsigned flags,
350 bool commonDrawImage(const SkImage*, DrawOps, unsigned flags, size_t bytes, const SkPaint*); 352 size_t opBytesNeeded, const SkPaint* paint);
351 353
352 SkPaint fPaint; 354 SkPaint fPaint;
353 void writePaint(const SkPaint&); 355 void writePaint(const SkPaint&);
354 356
355 class AutoPipeNotify { 357 class AutoPipeNotify {
356 public: 358 public:
357 AutoPipeNotify(SkGPipeCanvas* canvas) : fCanvas(canvas) {} 359 AutoPipeNotify(SkGPipeCanvas* canvas) : fCanvas(canvas) {}
358 ~AutoPipeNotify() { fCanvas->doNotify(); } 360 ~AutoPipeNotify() { fCanvas->doNotify(); }
359 private: 361 private:
360 SkGPipeCanvas* fCanvas; 362 SkGPipeCanvas* fCanvas;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, (fBitmapShuttle.get(), BITMAPS_TO _KEEP)); 455 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, (fBitmapShuttle.get(), BITMAPS_TO _KEEP));
454 } else { 456 } else {
455 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, 457 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap,
456 (BITMAPS_TO_KEEP, controller->numberOfReaders() )); 458 (BITMAPS_TO_KEEP, controller->numberOfReaders() ));
457 if (this->needOpBytes(sizeof(void*))) { 459 if (this->needOpBytes(sizeof(void*))) {
458 this->writeOp(kShareBitmapHeap_DrawOp); 460 this->writeOp(kShareBitmapHeap_DrawOp);
459 fWriter.writePtr(static_cast<void*>(fBitmapHeap)); 461 fWriter.writePtr(static_cast<void*>(fBitmapHeap));
460 } 462 }
461 } 463 }
462 fFlattenableHeap.setBitmapStorage(fBitmapHeap); 464 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
470 this->doNotify(); 465 this->doNotify();
471 } 466 }
472 467
473 SkGPipeCanvas::~SkGPipeCanvas() { 468 SkGPipeCanvas::~SkGPipeCanvas() {
474 this->finish(true); 469 this->finish(true);
475 SkSafeUnref(fFactorySet); 470 SkSafeUnref(fFactorySet);
476 SkSafeUnref(fBitmapHeap); 471 SkSafeUnref(fBitmapHeap);
477 SkSafeUnref(fImageHeap);
478 } 472 }
479 473
480 bool SkGPipeCanvas::needOpBytes(size_t needed) { 474 bool SkGPipeCanvas::needOpBytes(size_t needed) {
481 if (fDone) { 475 if (fDone) {
482 return false; 476 return false;
483 } 477 }
484 478
485 needed += 4; // size of DrawOp atom 479 needed += 4; // size of DrawOp atom
486 needed = SkAlign4(needed); 480 needed = SkAlign4(needed);
487 if (fWriter.bytesWritten() + needed > fBlockSize) { 481 if (fWriter.bytesWritten() + needed > fBlockSize) {
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 void SkGPipeCanvas::onDrawSprite(const SkBitmap& bm, int left, int top, const Sk Paint* paint) { 816 void SkGPipeCanvas::onDrawSprite(const SkBitmap& bm, int left, int top, const Sk Paint* paint) {
823 NOTIFY_SETUP(this); 817 NOTIFY_SETUP(this);
824 size_t opBytesNeeded = sizeof(int32_t) * 2; 818 size_t opBytesNeeded = sizeof(int32_t) * 2;
825 819
826 if (this->commonDrawBitmap(bm, kDrawSprite_DrawOp, 0, opBytesNeeded, paint)) { 820 if (this->commonDrawBitmap(bm, kDrawSprite_DrawOp, 0, opBytesNeeded, paint)) {
827 fWriter.write32(left); 821 fWriter.write32(left);
828 fWriter.write32(top); 822 fWriter.write32(top);
829 } 823 }
830 } 824 }
831 825
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
879 void SkGPipeCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, 826 void SkGPipeCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
880 const SkPaint& paint) { 827 const SkPaint& paint) {
881 if (byteLength) { 828 if (byteLength) {
882 NOTIFY_SETUP(this); 829 NOTIFY_SETUP(this);
883 this->writePaint(paint); 830 this->writePaint(paint);
884 if (this->needOpBytes(4 + SkAlign4(byteLength) + 2 * sizeof(SkScalar))) { 831 if (this->needOpBytes(4 + SkAlign4(byteLength) + 2 * sizeof(SkScalar))) {
885 this->writeOp(kDrawText_DrawOp); 832 this->writeOp(kDrawText_DrawOp);
886 fWriter.write32(SkToU32(byteLength)); 833 fWriter.write32(SkToU32(byteLength));
887 fWriter.writePad(text, byteLength); 834 fWriter.writePad(text, byteLength);
888 fWriter.writeScalar(x); 835 fWriter.writeScalar(x);
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 return fCanvas->shuttleBitmap(bitmap, slot); 1330 return fCanvas->shuttleBitmap(bitmap, slot);
1384 } 1331 }
1385 1332
1386 void BitmapShuttle::removeCanvas() { 1333 void BitmapShuttle::removeCanvas() {
1387 if (NULL == fCanvas) { 1334 if (NULL == fCanvas) {
1388 return; 1335 return;
1389 } 1336 }
1390 fCanvas->unref(); 1337 fCanvas->unref();
1391 fCanvas = NULL; 1338 fCanvas = NULL;
1392 } 1339 }
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