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

Side by Side Diff: src/effects/SkImageSource.cpp

Issue 1812023002: Switch SkSpecialImage & SkSpecialSurface classes over to smart pointers (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix build Created 4 years, 9 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/core/SkSpecialSurface.cpp ('k') | src/effects/SkMergeImageFilter.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 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 "SkImageSource.h" 8 #include "SkImageSource.h"
9 9
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkImage.h" 11 #include "SkImage.h"
12 #include "SkReadBuffer.h" 12 #include "SkReadBuffer.h"
13 #include "SkSpecialImage.h" 13 #include "SkSpecialImage.h"
14 #include "SkSpecialSurface.h" 14 #include "SkSpecialSurface.h"
15 #include "SkWriteBuffer.h" 15 #include "SkWriteBuffer.h"
16 #include "SkString.h" 16 #include "SkString.h"
17 17
18 SkImageFilter* SkImageSource::Create(const SkImage* image) { 18 SkImageFilter* SkImageSource::Create(SkImage* image) {
19 return image ? new SkImageSource(image) : nullptr; 19 return image ? new SkImageSource(image) : nullptr;
20 } 20 }
21 21
22 SkImageFilter* SkImageSource::Create(const SkImage* image, 22 SkImageFilter* SkImageSource::Create(SkImage* image,
23 const SkRect& srcRect, 23 const SkRect& srcRect,
24 const SkRect& dstRect, 24 const SkRect& dstRect,
25 SkFilterQuality filterQuality) { 25 SkFilterQuality filterQuality) {
26 return image ? new SkImageSource(image, srcRect, dstRect, filterQuality) : n ullptr; 26 return image ? new SkImageSource(image, srcRect, dstRect, filterQuality) : n ullptr;
27 } 27 }
28 28
29 SkImageSource::SkImageSource(const SkImage* image) 29 SkImageSource::SkImageSource(SkImage* image)
30 : INHERITED(0, nullptr) 30 : INHERITED(0, nullptr)
31 , fImage(SkRef(image)) 31 , fImage(SkRef(image))
32 , fSrcRect(SkRect::MakeIWH(image->width(), image->height())) 32 , fSrcRect(SkRect::MakeIWH(image->width(), image->height()))
33 , fDstRect(fSrcRect) 33 , fDstRect(fSrcRect)
34 , fFilterQuality(kHigh_SkFilterQuality) { } 34 , fFilterQuality(kHigh_SkFilterQuality) { }
35 35
36 SkImageSource::SkImageSource(const SkImage* image, 36 SkImageSource::SkImageSource(SkImage* image,
37 const SkRect& srcRect, 37 const SkRect& srcRect,
38 const SkRect& dstRect, 38 const SkRect& dstRect,
39 SkFilterQuality filterQuality) 39 SkFilterQuality filterQuality)
40 : INHERITED(0, nullptr) 40 : INHERITED(0, nullptr)
41 , fImage(SkRef(image)) 41 , fImage(SkRef(image))
42 , fSrcRect(srcRect) 42 , fSrcRect(srcRect)
43 , fDstRect(dstRect) 43 , fDstRect(dstRect)
44 , fFilterQuality(filterQuality) { } 44 , fFilterQuality(filterQuality) { }
45 45
46 SkFlattenable* SkImageSource::CreateProc(SkReadBuffer& buffer) { 46 SkFlattenable* SkImageSource::CreateProc(SkReadBuffer& buffer) {
47 SkFilterQuality filterQuality = (SkFilterQuality)buffer.readInt(); 47 SkFilterQuality filterQuality = (SkFilterQuality)buffer.readInt();
48 48
49 SkRect src, dst; 49 SkRect src, dst;
50 buffer.readRect(&src); 50 buffer.readRect(&src);
51 buffer.readRect(&dst); 51 buffer.readRect(&dst);
52 52
53 SkAutoTUnref<SkImage> image(buffer.readImage()); 53 SkAutoTUnref<SkImage> image(buffer.readImage());
54 if (!image) { 54 if (!image) {
55 return nullptr; 55 return nullptr;
56 } 56 }
57 57
58 return SkImageSource::Create(image, src, dst, filterQuality); 58 return SkImageSource::Create(image, src, dst, filterQuality);
59 } 59 }
60 60
61 void SkImageSource::flatten(SkWriteBuffer& buffer) const { 61 void SkImageSource::flatten(SkWriteBuffer& buffer) const {
62 buffer.writeInt(fFilterQuality); 62 buffer.writeInt(fFilterQuality);
63 buffer.writeRect(fSrcRect); 63 buffer.writeRect(fSrcRect);
64 buffer.writeRect(fDstRect); 64 buffer.writeRect(fDstRect);
65 buffer.writeImage(fImage); 65 buffer.writeImage(fImage.get());
66 } 66 }
67 67
68 SkSpecialImage* SkImageSource::onFilterImage(SkSpecialImage* source, const Conte xt& ctx, 68 SkSpecialImage* SkImageSource::onFilterImage(SkSpecialImage* source, const Conte xt& ctx,
69 SkIPoint* offset) const { 69 SkIPoint* offset) const {
70 SkRect dstRect; 70 SkRect dstRect;
71 ctx.ctm().mapRect(&dstRect, fDstRect); 71 ctx.ctm().mapRect(&dstRect, fDstRect);
72 72
73 SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height()); 73 SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height());
74 if (fSrcRect == bounds && dstRect == bounds) { 74 if (fSrcRect == bounds && dstRect == bounds) {
75 // No regions cropped out or resized; return entire image. 75 // No regions cropped out or resized; return entire image.
76 offset->fX = offset->fY = 0; 76 offset->fX = offset->fY = 0;
77 return SkSpecialImage::NewFromImage(source->internal_getProxy(), 77 return SkSpecialImage::MakeFromImage(source->internal_getProxy(),
78 SkIRect::MakeWH(fImage->width(), fIm age->height()), 78 SkIRect::MakeWH(fImage->width(), fI mage->height()),
79 fImage); 79 fImage).release();
80 } 80 }
81 81
82 const SkIRect dstIRect = dstRect.roundOut(); 82 const SkIRect dstIRect = dstRect.roundOut();
83 83
84 const SkImageInfo info = SkImageInfo::MakeN32(dstIRect.width(), dstIRect.hei ght(), 84 const SkImageInfo info = SkImageInfo::MakeN32(dstIRect.width(), dstIRect.hei ght(),
85 kPremul_SkAlphaType); 85 kPremul_SkAlphaType);
86 86
87 SkAutoTUnref<SkSpecialSurface> surf(source->newSurface(info)); 87 sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
88 if (!surf) { 88 if (!surf) {
89 return nullptr; 89 return nullptr;
90 } 90 }
91 91
92 SkCanvas* canvas = surf->getCanvas(); 92 SkCanvas* canvas = surf->getCanvas();
93 SkASSERT(canvas); 93 SkASSERT(canvas);
94 94
95 // TODO: it seems like this clear shouldn't be necessary (see skbug.com/5075 ) 95 // TODO: it seems like this clear shouldn't be necessary (see skbug.com/5075 )
96 canvas->clear(0x0); 96 canvas->clear(0x0);
97 97
98 SkPaint paint; 98 SkPaint paint;
99 99
100 // Subtract off the integer component of the translation (will be applied in offset, below). 100 // Subtract off the integer component of the translation (will be applied in offset, below).
101 dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop) ); 101 dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop) );
102 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 102 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
103 // FIXME: this probably shouldn't be necessary, but drawImageRect asserts 103 // FIXME: this probably shouldn't be necessary, but drawImageRect asserts
104 // None filtering when it's translate-only 104 // None filtering when it's translate-only
105 paint.setFilterQuality( 105 paint.setFilterQuality(
106 fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.heig ht() ? 106 fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.heig ht() ?
107 kNone_SkFilterQuality : fFilterQuality); 107 kNone_SkFilterQuality : fFilterQuality);
108 canvas->drawImageRect(fImage, fSrcRect, dstRect, &paint, SkCanvas::kStrict_S rcRectConstraint); 108 canvas->drawImageRect(fImage.get(), fSrcRect, dstRect, &paint,
109 SkCanvas::kStrict_SrcRectConstraint);
109 110
110 offset->fX = dstIRect.fLeft; 111 offset->fX = dstIRect.fLeft;
111 offset->fY = dstIRect.fTop; 112 offset->fY = dstIRect.fTop;
112 return surf->newImageSnapshot(); 113 return surf->makeImageSnapshot().release();
113 } 114 }
114 115
115 void SkImageSource::computeFastBounds(const SkRect& src, SkRect* dst) const { 116 void SkImageSource::computeFastBounds(const SkRect& src, SkRect* dst) const {
116 *dst = fDstRect; 117 *dst = fDstRect;
117 } 118 }
118 119
119 #ifndef SK_IGNORE_TO_STRING 120 #ifndef SK_IGNORE_TO_STRING
120 void SkImageSource::toString(SkString* str) const { 121 void SkImageSource::toString(SkString* str) const {
121 str->appendf("SkImageSource: ("); 122 str->appendf("SkImageSource: (");
122 str->appendf("src: (%f,%f,%f,%f) dst: (%f,%f,%f,%f) ", 123 str->appendf("src: (%f,%f,%f,%f) dst: (%f,%f,%f,%f) ",
123 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto m, 124 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto m,
124 fDstRect.fLeft, fDstRect.fTop, fDstRect.fRight, fDstRect.fBotto m); 125 fDstRect.fLeft, fDstRect.fTop, fDstRect.fRight, fDstRect.fBotto m);
125 str->appendf("image: (%d,%d)", 126 str->appendf("image: (%d,%d)",
126 fImage->width(), fImage->height()); 127 fImage->width(), fImage->height());
127 str->append(")"); 128 str->append(")");
128 } 129 }
129 #endif 130 #endif
OLDNEW
« no previous file with comments | « src/core/SkSpecialSurface.cpp ('k') | src/effects/SkMergeImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698