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

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

Issue 1772933002: Switch SkImageSource image filter over to new onFilterImage interface (Closed) Base URL: https://skia.googlesource.com/skia.git@if-follow-on
Patch Set: update to ToT again 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/SkSpecialImage.cpp ('k') | tests/ImageFilterCacheTest.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 "SkDevice.h"
12 #include "SkImage.h" 11 #include "SkImage.h"
13 #include "SkReadBuffer.h" 12 #include "SkReadBuffer.h"
13 #include "SkSpecialImage.h"
14 #include "SkSpecialSurface.h"
14 #include "SkWriteBuffer.h" 15 #include "SkWriteBuffer.h"
15 #include "SkString.h" 16 #include "SkString.h"
16 17
17 SkImageFilter* SkImageSource::Create(const SkImage* image) { 18 SkImageFilter* SkImageSource::Create(const SkImage* image) {
18 return image ? new SkImageSource(image) : nullptr; 19 return image ? new SkImageSource(image) : nullptr;
19 } 20 }
20 21
21 SkImageFilter* SkImageSource::Create(const SkImage* image, 22 SkImageFilter* SkImageSource::Create(const SkImage* image,
22 const SkRect& srcRect, 23 const SkRect& srcRect,
23 const SkRect& dstRect, 24 const SkRect& dstRect,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 return SkImageSource::Create(image, src, dst, filterQuality); 58 return SkImageSource::Create(image, src, dst, filterQuality);
58 } 59 }
59 60
60 void SkImageSource::flatten(SkWriteBuffer& buffer) const { 61 void SkImageSource::flatten(SkWriteBuffer& buffer) const {
61 buffer.writeInt(fFilterQuality); 62 buffer.writeInt(fFilterQuality);
62 buffer.writeRect(fSrcRect); 63 buffer.writeRect(fSrcRect);
63 buffer.writeRect(fDstRect); 64 buffer.writeRect(fDstRect);
64 buffer.writeImage(fImage); 65 buffer.writeImage(fImage);
65 } 66 }
66 67
67 bool SkImageSource::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& src, c onst Context& ctx, 68 SkSpecialImage* SkImageSource::onFilterImage(SkSpecialImage* source, const Conte xt& ctx,
68 SkBitmap* result, SkIPoint* offset) const { 69 SkIPoint* offset) const {
69 SkRect dstRect; 70 SkRect dstRect;
70 ctx.ctm().mapRect(&dstRect, fDstRect); 71 ctx.ctm().mapRect(&dstRect, fDstRect);
72
71 SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height()); 73 SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height());
72 if (fSrcRect == bounds && dstRect == bounds) { 74 if (fSrcRect == bounds && dstRect == bounds) {
73 // No regions cropped out or resized; return entire image. 75 // No regions cropped out or resized; return entire image.
74 offset->fX = offset->fY = 0; 76 offset->fX = offset->fY = 0;
75 return fImage->asLegacyBitmap(result, SkImage::kRO_LegacyBitmapMode); 77 return SkSpecialImage::NewFromImage(source->internal_getProxy(),
78 SkIRect::MakeWH(fImage->width(), fIm age->height()),
79 fImage);
76 } 80 }
77 81
78 const SkIRect dstIRect = dstRect.roundOut(); 82 const SkIRect dstIRect = dstRect.roundOut();
79 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstIRect.width(), dstI Rect.height())); 83
80 if (nullptr == device.get()) { 84 const SkImageInfo info = SkImageInfo::MakeN32(dstIRect.width(), dstIRect.hei ght(),
81 return false; 85 kPremul_SkAlphaType);
86
87 SkAutoTUnref<SkSpecialSurface> surf(source->newSurface(info));
88 if (!surf) {
89 return nullptr;
82 } 90 }
83 91
84 SkCanvas canvas(device.get()); 92 SkCanvas* canvas = surf->getCanvas();
93 SkASSERT(canvas);
94
95 // TODO: it seems like this clear shouldn't be necessary (see skbug.com/5075 )
96 canvas->clear(0x0);
97
85 SkPaint paint; 98 SkPaint paint;
86 99
87 // Subtract off the integer component of the translation (will be applied in loc, below). 100 // Subtract off the integer component of the translation (will be applied in offset, below).
88 dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop) ); 101 dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop) );
89 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 102 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
90 // FIXME: this probably shouldn't be necessary, but drawImageRect asserts 103 // FIXME: this probably shouldn't be necessary, but drawImageRect asserts
91 // None filtering when it's translate-only 104 // None filtering when it's translate-only
92 paint.setFilterQuality( 105 paint.setFilterQuality(
93 fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.heig ht() ? 106 fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.heig ht() ?
94 kNone_SkFilterQuality : fFilterQuality); 107 kNone_SkFilterQuality : fFilterQuality);
95 canvas.drawImageRect(fImage, fSrcRect, dstRect, &paint, SkCanvas::kStrict_Sr cRectConstraint); 108 canvas->drawImageRect(fImage, fSrcRect, dstRect, &paint, SkCanvas::kStrict_S rcRectConstraint);
96 109
97 *result = device.get()->accessBitmap(false);
98 offset->fX = dstIRect.fLeft; 110 offset->fX = dstIRect.fLeft;
99 offset->fY = dstIRect.fTop; 111 offset->fY = dstIRect.fTop;
100 112 return surf->newImageSnapshot();
101 return true;
102 } 113 }
103 114
104 void SkImageSource::computeFastBounds(const SkRect& src, SkRect* dst) const { 115 void SkImageSource::computeFastBounds(const SkRect& src, SkRect* dst) const {
105 *dst = fDstRect; 116 *dst = fDstRect;
106 } 117 }
107 118
108 #ifndef SK_IGNORE_TO_STRING 119 #ifndef SK_IGNORE_TO_STRING
109 void SkImageSource::toString(SkString* str) const { 120 void SkImageSource::toString(SkString* str) const {
110 str->appendf("SkImageSource: ("); 121 str->appendf("SkImageSource: (");
111 str->appendf("src: (%f,%f,%f,%f) dst: (%f,%f,%f,%f) ", 122 str->appendf("src: (%f,%f,%f,%f) dst: (%f,%f,%f,%f) ",
112 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto m, 123 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto m,
113 fDstRect.fLeft, fDstRect.fTop, fDstRect.fRight, fDstRect.fBotto m); 124 fDstRect.fLeft, fDstRect.fTop, fDstRect.fRight, fDstRect.fBotto m);
114 str->appendf("image: (%d,%d)", 125 str->appendf("image: (%d,%d)",
115 fImage->width(), fImage->height()); 126 fImage->width(), fImage->height());
116 str->append(")"); 127 str->append(")");
117 } 128 }
118 #endif 129 #endif
OLDNEW
« no previous file with comments | « src/core/SkSpecialImage.cpp ('k') | tests/ImageFilterCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698