OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapCache.h" | 9 #include "SkBitmapCache.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 // For now, and to maintain parity w/ previous pixelref behavior, we just fo rce the image | 60 // For now, and to maintain parity w/ previous pixelref behavior, we just fo rce the image |
61 // to produce a cached raster-bitmap form, so that drawing to a raster canva s should be fast. | 61 // to produce a cached raster-bitmap form, so that drawing to a raster canva s should be fast. |
62 // | 62 // |
63 SkBitmap bm; | 63 SkBitmap bm; |
64 if (as_IB(this)->getROPixels(&bm)) { | 64 if (as_IB(this)->getROPixels(&bm)) { |
65 bm.lockPixels(); | 65 bm.lockPixels(); |
66 bm.unlockPixels(); | 66 bm.unlockPixels(); |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 SkImage* SkImage::applyFilter(SkImageFilter* filter, SkIPoint* offset, | |
71 bool forceResultToOriginalSize) const { | |
72 if (!filter) { | |
robertphillips
2015/10/12 16:43:32
Just return this with offset set to 0,0 ?
reed1
2015/10/12 17:08:45
Will update dox to say out-params are undefined if
| |
73 return nullptr; | |
74 } | |
75 | |
76 SkIPoint offsetStorage; | |
77 if (!offset) { | |
robertphillips
2015/10/12 16:43:32
init offsetStorage to 0,0 here ?
reed1
2015/10/12 18:02:19
Not needed.
| |
78 offset = &offsetStorage; | |
79 } | |
80 return as_IB(this)->onApplyFilter(filter, offset, forceResultToOriginalSize) ; | |
81 } | |
82 | |
83 //////////////////////////////////////////////////////////////////////////////// /////////////////// | |
84 | |
85 #include "SkImageFilter.h" | |
86 #include "SkBitmapDevice.h" | |
87 | |
robertphillips
2015/10/12 16:43:32
const SkIRect& srcBounds ?
reed1
2015/10/12 18:02:19
Done.
| |
88 static SkIRect compute_fast_ibounds(SkImageFilter* filter, const SkIRect srcBoun ds) { | |
89 SkRect fastBounds; | |
90 fastBounds.set(srcBounds); | |
91 filter->computeFastBounds(fastBounds, &fastBounds); | |
92 return fastBounds.roundOut(); | |
93 } | |
94 | |
95 class SkRasterImageFilterProxy : public SkImageFilter::Proxy { | |
96 public: | |
97 SkBaseDevice* createDevice(int width, int height) override { | |
98 return SkBitmapDevice::Create(SkImageInfo::MakeN32Premul(width, height)) ; | |
99 } | |
100 | |
101 bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter: :Context&, | |
102 SkBitmap*, SkIPoint*) override { | |
103 return false; | |
104 } | |
105 }; | |
106 | |
107 SkImage* SkImage_Base::onApplyFilter(SkImageFilter* filter, SkIPoint* offsetResu lt, | |
108 bool forceResultToOriginalSize) const { | |
109 SkBitmap src; | |
110 if (!this->getROPixels(&src)) { | |
111 return nullptr; | |
112 } | |
113 | |
114 const SkIRect srcBounds = SkIRect::MakeWH(this->width(), this->height()); | |
115 | |
116 if (forceResultToOriginalSize) { | |
117 const SkIRect clipBounds = srcBounds; | |
118 SkRasterImageFilterProxy proxy; | |
119 SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, SkImageFilter::Cac he::Get()); | |
120 | |
121 SkBitmap dst; | |
122 if (filter->filterImage(&proxy, src, ctx, &dst, offsetResult)) { | |
123 dst.setImmutable(); | |
124 return SkImage::NewFromBitmap(dst); | |
125 } | |
126 } else { | |
127 const SkIRect dstR = compute_fast_ibounds(filter, srcBounds); | |
128 | |
129 SkImageInfo info = SkImageInfo::MakeN32Premul(dstR.width(), dstR.height( )); | |
130 SkAutoTUnref<SkSurface> surface(this->onNewSurface(info)); | |
131 | |
132 SkPaint paint; | |
133 paint.setImageFilter(filter); | |
134 surface->getCanvas()->drawImage(this, SkIntToScalar(-dstR.x()), SkIntToS calar(-dstR.y()), | |
135 &paint); | |
136 | |
137 offsetResult->set(dstR.x(), dstR.y()); | |
138 return surface->newImageSnapshot(); | |
139 } | |
140 return nullptr; | |
141 } | |
142 | |
143 //////////////////////////////////////////////////////////////////////////////// /////////////////// | |
144 | |
70 SkShader* SkImage::newShader(SkShader::TileMode tileX, | 145 SkShader* SkImage::newShader(SkShader::TileMode tileX, |
71 SkShader::TileMode tileY, | 146 SkShader::TileMode tileY, |
72 const SkMatrix* localMatrix) const { | 147 const SkMatrix* localMatrix) const { |
73 return SkImageShader::Create(this, tileX, tileY, localMatrix); | 148 return SkImageShader::Create(this, tileX, tileY, localMatrix); |
74 } | 149 } |
75 | 150 |
76 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { | 151 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { |
77 SkBitmap bm; | 152 SkBitmap bm; |
78 if (as_IB(this)->getROPixels(&bm)) { | 153 if (as_IB(this)->getROPixels(&bm)) { |
79 return SkImageEncoder::EncodeData(bm, type, quality); | 154 return SkImageEncoder::EncodeData(bm, type, quality); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 | 395 |
321 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) { | 396 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) { |
322 return nullptr; | 397 return nullptr; |
323 } | 398 } |
324 | 399 |
325 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { | 400 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { |
326 return nullptr; | 401 return nullptr; |
327 } | 402 } |
328 | 403 |
329 #endif | 404 #endif |
OLD | NEW |