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

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

Issue 1695823002: Get OffsetImageFilter really working with SkSpecialImages (Closed) Base URL: https://skia.googlesource.com/skia.git@use-special
Patch Set: Fix bug Created 4 years, 10 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 | « include/effects/SkOffsetImageFilter.h ('k') | src/effects/SkOffsetImageFilter.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 2012 The Android Open Source Project 2 * Copyright 2012 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 "SkImageFilter.h" 8 #include "SkImageFilter.h"
9 #include "SkImageFilterCacheKey.h" 9 #include "SkImageFilterCacheKey.h"
10 10
11 #include "SkBitmap.h" 11 #include "SkBitmap.h"
12 #include "SkBitmapDevice.h" 12 #include "SkBitmapDevice.h"
13 #include "SkChecksum.h" 13 #include "SkChecksum.h"
14 #include "SkDevice.h" 14 #include "SkDevice.h"
15 #include "SkLocalMatrixImageFilter.h" 15 #include "SkLocalMatrixImageFilter.h"
16 #include "SkMatrixImageFilter.h" 16 #include "SkMatrixImageFilter.h"
17 #include "SkOncePtr.h" 17 #include "SkOncePtr.h"
18 #include "SkReadBuffer.h" 18 #include "SkReadBuffer.h"
19 #include "SkRect.h" 19 #include "SkRect.h"
20 #include "SkSpecialImage.h" 20 #include "SkSpecialImage.h"
21 #include "SkSpecialSurface.h"
21 #include "SkTDynamicHash.h" 22 #include "SkTDynamicHash.h"
22 #include "SkTInternalLList.h" 23 #include "SkTInternalLList.h"
23 #include "SkValidationUtils.h" 24 #include "SkValidationUtils.h"
24 #include "SkWriteBuffer.h" 25 #include "SkWriteBuffer.h"
25 #if SK_SUPPORT_GPU 26 #if SK_SUPPORT_GPU
26 #include "GrContext.h" 27 #include "GrContext.h"
27 #include "GrDrawContext.h" 28 #include "GrDrawContext.h"
28 #include "SkGrPixelRef.h" 29 #include "SkGrPixelRef.h"
29 #include "SkGr.h" 30 #include "SkGr.h"
30 #endif 31 #endif
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 SkImageFilter* input = this->getInput(i); 207 SkImageFilter* input = this->getInput(i);
207 buffer.writeBool(input != nullptr); 208 buffer.writeBool(input != nullptr);
208 if (input != nullptr) { 209 if (input != nullptr) {
209 buffer.writeFlattenable(input); 210 buffer.writeFlattenable(input);
210 } 211 }
211 } 212 }
212 buffer.writeRect(fCropRect.rect()); 213 buffer.writeRect(fCropRect.rect());
213 buffer.writeUInt(fCropRect.flags()); 214 buffer.writeUInt(fCropRect.flags());
214 } 215 }
215 216
217 SkSpecialImage* SkImageFilter::filterImage(SkSpecialImage* src, const Context& c ontext,
218 SkIPoint* offset) const {
219 SkASSERT(src && offset);
220
221 uint32_t srcGenID = fUsesSrcInput ? src->uniqueID() : 0;
222 const SkIRect srcSubset = fUsesSrcInput ? src->subset() : SkIRect::MakeWH(0, 0);
223 Cache::Key key(fUniqueID, context.ctm(), context.clipBounds(), srcGenID, src Subset);
224 if (context.cache()) {
225 SkSpecialImage* result = context.cache()->get(key, offset);
226 if (result) {
227 return SkRef(result);
228 }
229 }
230
231 SkSpecialImage* result = this->onFilterImage(src, context, offset);
232 if (result && context.cache()) {
233 context.cache()->set(key, result, *offset);
234 }
235
236 return result;
237 }
238
216 bool SkImageFilter::filterImageDeprecated(Proxy* proxy, const SkBitmap& src, 239 bool SkImageFilter::filterImageDeprecated(Proxy* proxy, const SkBitmap& src,
217 const Context& context, 240 const Context& context,
218 SkBitmap* result, SkIPoint* offset) co nst { 241 SkBitmap* result, SkIPoint* offset) co nst {
219 SkASSERT(result); 242 SkASSERT(result);
220 SkASSERT(offset); 243 SkASSERT(offset);
221 uint32_t srcGenID = fUsesSrcInput ? src.getGenerationID() : 0; 244 uint32_t srcGenID = fUsesSrcInput ? src.getGenerationID() : 0;
222 Cache::Key key(fUniqueID, context.ctm(), context.clipBounds(), 245 Cache::Key key(fUniqueID, context.ctm(), context.clipBounds(),
223 srcGenID, SkIRect::MakeWH(0, 0)); 246 srcGenID, SkIRect::MakeWH(0, 0));
224 if (context.cache()) { 247 if (context.cache()) {
225 if (context.cache()->get(key, result, offset)) { 248 if (context.cache()->get(key, result, offset)) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 323 }
301 } 324 }
302 return true; 325 return true;
303 } 326 }
304 327
305 bool SkImageFilter::onFilterImageDeprecated(Proxy*, const SkBitmap&, const Conte xt&, 328 bool SkImageFilter::onFilterImageDeprecated(Proxy*, const SkBitmap&, const Conte xt&,
306 SkBitmap*, SkIPoint*) const { 329 SkBitmap*, SkIPoint*) const {
307 return false; 330 return false;
308 } 331 }
309 332
333 SkSpecialImage* SkImageFilter::onFilterImage(SkSpecialImage* src, const Context& ctx,
334 SkIPoint* offset) const {
335 SkBitmap tmpSrc, result;
336
337 if (!src->internal_getBM(&tmpSrc)) {
338 return nullptr;
339 }
340
341 if (!this->filterImageDeprecated(src->internal_getProxy(), tmpSrc,
342 this->mapContext(ctx), &result, offset)) {
343 return nullptr;
344 }
345
346 return SkSpecialImage::internal_fromBM(src->internal_getProxy(), result);
347 }
348
310 bool SkImageFilter::canFilterImageGPU() const { 349 bool SkImageFilter::canFilterImageGPU() const {
311 return this->asFragmentProcessor(nullptr, nullptr, SkMatrix::I(), SkIRect()) ; 350 return this->asFragmentProcessor(nullptr, nullptr, SkMatrix::I(), SkIRect()) ;
312 } 351 }
313 352
314 bool SkImageFilter::filterImageGPUDeprecated(Proxy* proxy, const SkBitmap& src, const Context& ctx, 353 bool SkImageFilter::filterImageGPUDeprecated(Proxy* proxy, const SkBitmap& src, const Context& ctx,
315 SkBitmap* result, SkIPoint* offset) const { 354 SkBitmap* result, SkIPoint* offset) const {
316 #if SK_SUPPORT_GPU 355 #if SK_SUPPORT_GPU
317 SkBitmap input = src; 356 SkBitmap input = src;
318 SkASSERT(fInputCount == 1); 357 SkASSERT(fInputCount == 1);
319 SkIPoint srcOffset = SkIPoint::Make(0, 0); 358 SkIPoint srcOffset = SkIPoint::Make(0, 0);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 451 }
413 SkCanvas canvas(device); 452 SkCanvas canvas(device);
414 canvas.clear(0x00000000); 453 canvas.clear(0x00000000);
415 canvas.drawBitmap(src, srcOffset->x() - bounds->x(), srcOffset->y() - bo unds->y()); 454 canvas.drawBitmap(src, srcOffset->x() - bounds->x(), srcOffset->y() - bo unds->y());
416 *srcOffset = SkIPoint::Make(bounds->x(), bounds->y()); 455 *srcOffset = SkIPoint::Make(bounds->x(), bounds->y());
417 *dst = device->accessBitmap(false); 456 *dst = device->accessBitmap(false);
418 return true; 457 return true;
419 } 458 }
420 } 459 }
421 460
461 // Return a larger (newWidth x newHeight) copy of 'src' with black padding
462 // around it.
463 static SkSpecialImage* pad_image(SkSpecialImage* src,
464 int newWidth, int newHeight, int offX, int offY ) {
465
466 SkImageInfo info = SkImageInfo::MakeN32Premul(newWidth, newHeight);
467 SkAutoTUnref<SkSpecialSurface> surf(src->newSurface(info));
468 if (!surf) {
469 return nullptr;
470 }
471
472 SkCanvas* canvas = surf->getCanvas();
473 if (!canvas) {
474 return nullptr;
475 }
476
477 canvas->clear(0x0);
478
479 src->draw(canvas, offX, offY, nullptr);
480
481 return surf->newImageSnapshot();
482 }
483
484 SkSpecialImage* SkImageFilter::applyCropRect(const Context& ctx,
485 SkSpecialImage* src,
486 SkIPoint* srcOffset,
487 SkIRect* bounds) const {
488 SkIRect srcBounds;
489 srcBounds = SkIRect::MakeXYWH(srcOffset->fX, srcOffset->fY, src->width(), sr c->height());
490
491 SkIRect dstBounds;
492 this->onFilterNodeBounds(srcBounds, ctx.ctm(), &dstBounds, kForward_MapDirec tion);
493 fCropRect.applyTo(dstBounds, ctx.ctm(), bounds);
494 if (!bounds->intersect(ctx.clipBounds())) {
495 return nullptr;
496 }
497
498 if (srcBounds.contains(*bounds)) {
499 return SkRef(src);
500 } else {
501 SkSpecialImage* img = pad_image(src,
502 bounds->width(), bounds->height(),
503 srcOffset->x() - bounds->x(),
504 srcOffset->y() - bounds->y());
505 *srcOffset = SkIPoint::Make(bounds->x(), bounds->y());
506 return img;
507 }
508 }
509
422 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, 510 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm,
423 SkIRect* dst, MapDirection direction) const { 511 SkIRect* dst, MapDirection direction) const {
424 if (fInputCount < 1) { 512 if (fInputCount < 1) {
425 *dst = src; 513 *dst = src;
426 return true; 514 return true;
427 } 515 }
428 516
429 SkIRect totalBounds; 517 SkIRect totalBounds;
430 for (int i = 0; i < fInputCount; ++i) { 518 for (int i = 0; i < fInputCount; ++i) {
431 SkImageFilter* filter = this->getInput(i); 519 SkImageFilter* filter = this->getInput(i);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 return SkMatrixImageFilter::Create(matrix, filterQuality, input); 558 return SkMatrixImageFilter::Create(matrix, filterQuality, input);
471 } 559 }
472 560
473 SkImageFilter* SkImageFilter::newWithLocalMatrix(const SkMatrix& matrix) const { 561 SkImageFilter* SkImageFilter::newWithLocalMatrix(const SkMatrix& matrix) const {
474 // SkLocalMatrixImageFilter takes SkImage* in its factory, but logically tha t parameter 562 // SkLocalMatrixImageFilter takes SkImage* in its factory, but logically tha t parameter
475 // is *always* treated as a const ptr. Hence the const-cast here. 563 // is *always* treated as a const ptr. Hence the const-cast here.
476 // 564 //
477 return SkLocalMatrixImageFilter::Create(matrix, const_cast<SkImageFilter*>(t his)); 565 return SkLocalMatrixImageFilter::Create(matrix, const_cast<SkImageFilter*>(t his));
478 } 566 }
479 567
568 SkSpecialImage* SkImageFilter::filterInput(int index,
569 SkSpecialImage* src,
570 const Context& ctx,
571 SkIPoint* offset) const {
572 SkImageFilter* input = this->getInput(index);
573 if (!input) {
574 return SkRef(src);
575 }
576
577 return input->filterImage(src, this->mapContext(ctx), offset);
578 }
579
480 #if SK_SUPPORT_GPU 580 #if SK_SUPPORT_GPU
481 581
482 bool SkImageFilter::filterInputGPUDeprecated(int index, SkImageFilter::Proxy* pr oxy, 582 bool SkImageFilter::filterInputGPUDeprecated(int index, SkImageFilter::Proxy* pr oxy,
483 const SkBitmap& src, const Context& ctx, 583 const SkBitmap& src, const Context& ctx,
484 SkBitmap* result, SkIPoint* offset) const { 584 SkBitmap* result, SkIPoint* offset) const {
485 SkImageFilter* input = this->getInput(index); 585 SkImageFilter* input = this->getInput(index);
486 if (!input) { 586 if (!input) {
487 return true; 587 return true;
488 } 588 }
489 // Ensure that GrContext calls under filterImage and filterImageGPU below wi ll see an identity 589 // Ensure that GrContext calls under filterImage and filterImageGPU below wi ll see an identity
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 } 777 }
678 return dev; 778 return dev;
679 } 779 }
680 780
681 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const SkBitmap& src, 781 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const SkBitmap& src,
682 const SkImageFilter::Context& ctx, 782 const SkImageFilter::Context& ctx,
683 SkBitmap* result, SkIPoint* offset) { 783 SkBitmap* result, SkIPoint* offset) {
684 return fDevice->filterImage(filter, src, ctx, result, offset); 784 return fDevice->filterImage(filter, src, ctx, result, offset);
685 } 785 }
686 786
OLDNEW
« no previous file with comments | « include/effects/SkOffsetImageFilter.h ('k') | src/effects/SkOffsetImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698