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

Side by Side Diff: src/core/SkCanvas.cpp

Issue 583453002: SkCanvas::drawImage is the new way for drawing an SkImage to a Canvas (Closed) Base URL: https://skia.googlesource.com/skia.git@refactor_skImage
Patch Set: Again Created 6 years, 2 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 | « samplecode/SampleTextureDomain.cpp ('k') | src/gpu/GrRecordReplaceDraw.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 * Copyright 2008 The Android Open Source Project 2 * Copyright 2008 The Android Open Source Project
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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkCanvasPriv.h" 9 #include "SkCanvasPriv.h"
10 #include "SkBitmapDevice.h" 10 #include "SkBitmapDevice.h"
11 #include "SkDeviceImageFilterProxy.h" 11 #include "SkDeviceImageFilterProxy.h"
12 #include "SkDraw.h" 12 #include "SkDraw.h"
13 #include "SkDrawFilter.h" 13 #include "SkDrawFilter.h"
14 #include "SkDrawLooper.h" 14 #include "SkDrawLooper.h"
15 #include "SkImage_Base.h"
reed1 2014/09/23 12:29:44 Can we just include SkImage.h ?
Rémi Piotaix 2014/09/23 19:47:24 Done.
15 #include "SkMetaData.h" 16 #include "SkMetaData.h"
16 #include "SkPathOps.h" 17 #include "SkPathOps.h"
17 #include "SkPatchUtils.h" 18 #include "SkPatchUtils.h"
18 #include "SkPicture.h" 19 #include "SkPicture.h"
19 #include "SkRasterClip.h" 20 #include "SkRasterClip.h"
20 #include "SkRRect.h" 21 #include "SkRRect.h"
21 #include "SkSmallAllocator.h" 22 #include "SkSmallAllocator.h"
22 #include "SkSurface_Base.h" 23 #include "SkSurface_Base.h"
23 #include "SkTemplates.h" 24 #include "SkTemplates.h"
24 #include "SkTextBlob.h" 25 #include "SkTextBlob.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 reference counted, since the real owner is either our fLayer field, 177 reference counted, since the real owner is either our fLayer field,
177 or a previous one in a lower level.) 178 or a previous one in a lower level.)
178 */ 179 */
179 DeviceCM* fTopLayer; 180 DeviceCM* fTopLayer;
180 181
181 MCRec(bool conservativeRasterClip) : fRasterClip(conservativeRasterClip) { 182 MCRec(bool conservativeRasterClip) : fRasterClip(conservativeRasterClip) {
182 fMatrix.reset(); 183 fMatrix.reset();
183 fFilter = NULL; 184 fFilter = NULL;
184 fLayer = NULL; 185 fLayer = NULL;
185 fTopLayer = NULL; 186 fTopLayer = NULL;
186 187
187 // don't bother initializing fNext 188 // don't bother initializing fNext
188 inc_rec(); 189 inc_rec();
189 } 190 }
190 MCRec(const MCRec& prev) : fRasterClip(prev.fRasterClip) { 191 MCRec(const MCRec& prev) : fRasterClip(prev.fRasterClip) {
191 fMatrix = prev.fMatrix; 192 fMatrix = prev.fMatrix;
192 fFilter = SkSafeRef(prev.fFilter); 193 fFilter = SkSafeRef(prev.fFilter);
193 fLayer = NULL; 194 fLayer = NULL;
194 fTopLayer = prev.fTopLayer; 195 fTopLayer = prev.fTopLayer;
195 196
196 // don't bother initializing fNext 197 // don't bother initializing fNext
197 inc_rec(); 198 inc_rec();
198 } 199 }
199 ~MCRec() { 200 ~MCRec() {
200 SkSafeUnref(fFilter); 201 SkSafeUnref(fFilter);
201 SkDELETE(fLayer); 202 SkDELETE(fLayer);
202 dec_rec(); 203 dec_rec();
203 } 204 }
204 }; 205 };
205 206
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 if (SkDrawLooper* looper = paint.getLooper()) { 286 if (SkDrawLooper* looper = paint.getLooper()) {
286 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>( 287 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>(
287 looper->contextSize()); 288 looper->contextSize());
288 fLooperContext = looper->createContext(canvas, buffer); 289 fLooperContext = looper->createContext(canvas, buffer);
289 fIsSimple = false; 290 fIsSimple = false;
290 } else { 291 } else {
291 fLooperContext = NULL; 292 fLooperContext = NULL;
292 // can we be marked as simple? 293 // can we be marked as simple?
293 fIsSimple = !fFilter && !fDoClearImageFilter; 294 fIsSimple = !fFilter && !fDoClearImageFilter;
294 } 295 }
295 296
296 uint32_t oldFlags = paint.getFlags(); 297 uint32_t oldFlags = paint.getFlags();
297 fNewPaintFlags = filter_paint_flags(props, oldFlags); 298 fNewPaintFlags = filter_paint_flags(props, oldFlags);
298 if (fIsSimple && (fNewPaintFlags != oldFlags)) { 299 if (fIsSimple && (fNewPaintFlags != oldFlags)) {
299 SkPaint* paint = fLazyPaint.set(fOrigPaint); 300 SkPaint* paint = fLazyPaint.set(fOrigPaint);
300 paint->setFlags(fNewPaintFlags); 301 paint->setFlags(fNewPaintFlags);
301 fPaint = paint; 302 fPaint = paint;
302 // if we're not simple, doNext() will take care of calling setFlags( ) 303 // if we're not simple, doNext() will take care of calling setFlags( )
303 } 304 }
304 } 305 }
305 306
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 SkBitmap bitmap; 451 SkBitmap bitmap;
451 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); 452 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height));
452 return bitmap; 453 return bitmap;
453 } 454 }
454 455
455 class SkNoPixelsBitmapDevice : public SkBitmapDevice { 456 class SkNoPixelsBitmapDevice : public SkBitmapDevice {
456 public: 457 public:
457 SkNoPixelsBitmapDevice(int width, int height) : INHERITED(make_nopixels(widt h, height)) {} 458 SkNoPixelsBitmapDevice(int width, int height) : INHERITED(make_nopixels(widt h, height)) {}
458 459
459 private: 460 private:
460 461
461 typedef SkBitmapDevice INHERITED; 462 typedef SkBitmapDevice INHERITED;
462 }; 463 };
463 464
464 SkCanvas::SkCanvas(int width, int height) 465 SkCanvas::SkCanvas(int width, int height)
465 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 466 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
466 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 467 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
467 { 468 {
468 inc_canvas(); 469 inc_canvas();
469 470
470 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (width, height)), kDefault_Ini tFlags)->unref(); 471 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (width, height)), kDefault_Ini tFlags)->unref();
471 } 472 }
472 473
473 SkCanvas::SkCanvas(int width, int height, InitFlags flags) 474 SkCanvas::SkCanvas(int width, int height, InitFlags flags)
474 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 475 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
475 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 476 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
476 { 477 {
477 inc_canvas(); 478 inc_canvas();
478 479
479 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (width, height)), flags)->unre f(); 480 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (width, height)), flags)->unre f();
480 } 481 }
481 482
482 SkCanvas::SkCanvas(SkBaseDevice* device, const SkSurfaceProps* props, InitFlags flags) 483 SkCanvas::SkCanvas(SkBaseDevice* device, const SkSurfaceProps* props, InitFlags flags)
483 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 484 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
484 , fProps(SkSurfacePropsCopyOrDefault(props)) 485 , fProps(SkSurfacePropsCopyOrDefault(props))
485 { 486 {
486 inc_canvas(); 487 inc_canvas();
487 488
488 this->init(device, flags); 489 this->init(device, flags);
489 } 490 }
490 491
491 SkCanvas::SkCanvas(SkBaseDevice* device) 492 SkCanvas::SkCanvas(SkBaseDevice* device)
492 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 493 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
493 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 494 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
494 { 495 {
495 inc_canvas(); 496 inc_canvas();
496 497
497 this->init(device, kDefault_InitFlags); 498 this->init(device, kDefault_InitFlags);
498 } 499 }
499 500
500 SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) 501 SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props)
501 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 502 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
502 , fProps(props) 503 , fProps(props)
503 { 504 {
504 inc_canvas(); 505 inc_canvas();
505 506
506 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap))); 507 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap)));
507 this->init(device, kDefault_InitFlags); 508 this->init(device, kDefault_InitFlags);
508 } 509 }
509 510
510 SkCanvas::SkCanvas(const SkBitmap& bitmap) 511 SkCanvas::SkCanvas(const SkBitmap& bitmap)
511 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 512 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
512 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 513 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
513 { 514 {
514 inc_canvas(); 515 inc_canvas();
515 516
516 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap))); 517 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap)));
517 this->init(device, kDefault_InitFlags); 518 this->init(device, kDefault_InitFlags);
518 } 519 }
519 520
520 SkCanvas::~SkCanvas() { 521 SkCanvas::~SkCanvas() {
521 // free up the contents of our deque 522 // free up the contents of our deque
522 this->restoreToCount(1); // restore everything but the last 523 this->restoreToCount(1); // restore everything but the last
523 SkASSERT(0 == fSaveLayerCount); 524 SkASSERT(0 == fSaveLayerCount);
524 525
525 this->internalRestore(); // restore the last, since we're going away 526 this->internalRestore(); // restore the last, since we're going away
(...skipping 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1878 1879
1879 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, bounds) 1880 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, bounds)
1880 1881
1881 while (iter.next()) { 1882 while (iter.next()) {
1882 iter.fDevice->drawPath(iter, path, looper.paint()); 1883 iter.fDevice->drawPath(iter, path, looper.paint());
1883 } 1884 }
1884 1885
1885 LOOPER_END 1886 LOOPER_END
1886 } 1887 }
1887 1888
1889 void SkCanvas::drawImage(const SkImage* image, SkScalar left, SkScalar top,
1890 const SkPaint* paint) {
1891 image->draw(this, left, top, paint);
1892 }
1893
1894 void SkCanvas::drawImageRect(const SkImage* image, const SkRect* src,
1895 const SkRect& dst,
1896 const SkPaint* paint) {
1897 image->draw(this, src, dst, paint);
1898 }
1899
1888 void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, 1900 void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
1889 const SkPaint* paint) { 1901 const SkPaint* paint) {
1890 SkDEBUGCODE(bitmap.validate();) 1902 SkDEBUGCODE(bitmap.validate();)
1891 1903
1892 if (NULL == paint || paint->canComputeFastBounds()) { 1904 if (NULL == paint || paint->canComputeFastBounds()) {
1893 SkRect bounds = { 1905 SkRect bounds = {
1894 x, y, 1906 x, y,
1895 x + SkIntToScalar(bitmap.width()), 1907 x + SkIntToScalar(bitmap.width()),
1896 y + SkIntToScalar(bitmap.height()) 1908 y + SkIntToScalar(bitmap.height())
1897 }; 1909 };
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
2536 } 2548 }
2537 2549
2538 if (matrix) { 2550 if (matrix) {
2539 canvas->concat(*matrix); 2551 canvas->concat(*matrix);
2540 } 2552 }
2541 } 2553 }
2542 2554
2543 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 2555 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2544 fCanvas->restoreToCount(fSaveCount); 2556 fCanvas->restoreToCount(fSaveCount);
2545 } 2557 }
OLDNEW
« no previous file with comments | « samplecode/SampleTextureDomain.cpp ('k') | src/gpu/GrRecordReplaceDraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698