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

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

Issue 1893993002: Revert of Remove deprecated paths from image filter infrastructure. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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/SkDevice.cpp ('k') | src/gpu/SkGpuDevice.h » ('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
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 SkASSERT(result); 249 SkASSERT(result);
250 SkASSERT(offset); 250 SkASSERT(offset);
251 uint32_t srcGenID = fUsesSrcInput ? src.getGenerationID() : 0; 251 uint32_t srcGenID = fUsesSrcInput ? src.getGenerationID() : 0;
252 Cache::Key key(fUniqueID, context.ctm(), context.clipBounds(), 252 Cache::Key key(fUniqueID, context.ctm(), context.clipBounds(),
253 srcGenID, SkIRect::MakeWH(0, 0)); 253 srcGenID, SkIRect::MakeWH(0, 0));
254 if (context.cache()) { 254 if (context.cache()) {
255 if (context.cache()->get(key, result, offset)) { 255 if (context.cache()->get(key, result, offset)) {
256 return true; 256 return true;
257 } 257 }
258 } 258 }
259 if (this->onFilterImageDeprecated(proxy, src, context, result, offset)) { 259 /*
260 * Give the proxy first shot at the filter. If it returns false, ask
261 * the filter to do it.
262 */
263 if ((proxy && proxy->filterImage(this, src, context, result, offset)) ||
264 this->onFilterImageDeprecated(proxy, src, context, result, offset)) {
260 if (context.cache()) { 265 if (context.cache()) {
261 context.cache()->set(key, *result, *offset); 266 context.cache()->set(key, *result, *offset);
262 SkAutoMutexAcquire mutex(fMutex); 267 SkAutoMutexAcquire mutex(fMutex);
263 fCacheKeys.push_back(key); 268 fCacheKeys.push_back(key);
264 } 269 }
265 return true; 270 return true;
266 } 271 }
267 return false; 272 return false;
268 } 273 }
269 274
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 SkIRect temp = this->onFilterNodeBounds(srcBounds, ctx.ctm(), kForward_MapDi rection); 421 SkIRect temp = this->onFilterNodeBounds(srcBounds, ctx.ctm(), kForward_MapDi rection);
417 fCropRect.applyTo(temp, ctx.ctm(), this->affectsTransparentBlack(), dstBound s); 422 fCropRect.applyTo(temp, ctx.ctm(), this->affectsTransparentBlack(), dstBound s);
418 // Intersect against the clip bounds, in case the crop rect has 423 // Intersect against the clip bounds, in case the crop rect has
419 // grown the bounds beyond the original clip. This can happen for 424 // grown the bounds beyond the original clip. This can happen for
420 // example in tiling, where the clip is much smaller than the filtered 425 // example in tiling, where the clip is much smaller than the filtered
421 // primitive. If we didn't do this, we would be processing the filter 426 // primitive. If we didn't do this, we would be processing the filter
422 // at the full crop rect size in every tile. 427 // at the full crop rect size in every tile.
423 return dstBounds->intersect(ctx.clipBounds()); 428 return dstBounds->intersect(ctx.clipBounds());
424 } 429 }
425 430
431 bool SkImageFilter::applyCropRectDeprecated(const Context& ctx, Proxy* proxy, co nst SkBitmap& src,
432 SkIPoint* srcOffset, SkIRect* bounds ,
433 SkBitmap* dst) const {
434 SkIRect srcBounds;
435 src.getBounds(&srcBounds);
436 srcBounds.offset(*srcOffset);
437 SkIRect dstBounds = this->onFilterNodeBounds(srcBounds, ctx.ctm(), kForward_ MapDirection);
438 fCropRect.applyTo(dstBounds, ctx.ctm(), this->affectsTransparentBlack(), bou nds);
439 if (!bounds->intersect(ctx.clipBounds())) {
440 return false;
441 }
442
443 if (srcBounds.contains(*bounds)) {
444 *dst = src;
445 return true;
446 } else {
447 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds->width(), b ounds->height()));
448 if (!device) {
449 return false;
450 }
451 SkCanvas canvas(device);
452 canvas.clear(0x00000000);
453 canvas.drawBitmap(src, srcOffset->x() - bounds->x(), srcOffset->y() - bo unds->y());
454 *srcOffset = SkIPoint::Make(bounds->x(), bounds->y());
455 *dst = device->accessBitmap(false);
456 return true;
457 }
458 }
459
426 // Return a larger (newWidth x newHeight) copy of 'src' with black padding 460 // Return a larger (newWidth x newHeight) copy of 'src' with black padding
427 // around it. 461 // around it.
428 static sk_sp<SkSpecialImage> pad_image(SkSpecialImage* src, 462 static sk_sp<SkSpecialImage> pad_image(SkSpecialImage* src,
429 int newWidth, int newHeight, int offX, in t offY) { 463 int newWidth, int newHeight, int offX, in t offY) {
430 464
431 SkImageInfo info = SkImageInfo::MakeN32Premul(newWidth, newHeight); 465 SkImageInfo info = SkImageInfo::MakeN32Premul(newWidth, newHeight);
432 sk_sp<SkSpecialSurface> surf(src->makeSurface(info)); 466 sk_sp<SkSpecialSurface> surf(src->makeSurface(info));
433 if (!surf) { 467 if (!surf) {
434 return nullptr; 468 return nullptr;
435 } 469 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 return sk_sp<SkSpecialImage>(SkRef(src)); 557 return sk_sp<SkSpecialImage>(SkRef(src));
524 } 558 }
525 559
526 sk_sp<SkSpecialImage> result(input->filterImage(src, this->mapContext(ctx), offset)); 560 sk_sp<SkSpecialImage> result(input->filterImage(src, this->mapContext(ctx), offset));
527 561
528 SkASSERT(!result || src->isTextureBacked() == result->isTextureBacked()); 562 SkASSERT(!result || src->isTextureBacked() == result->isTextureBacked());
529 563
530 return result; 564 return result;
531 } 565 }
532 566
567 #if SK_SUPPORT_GPU
568
569 bool SkImageFilter::filterInputGPUDeprecated(int index, SkImageFilter::Proxy* pr oxy,
570 const SkBitmap& src, const Context& ctx,
571 SkBitmap* result, SkIPoint* offset) const {
572 SkImageFilter* input = this->getInput(index);
573 if (!input) {
574 return true;
575 }
576
577 // SRGBTODO: Don't handle sRGB here, in anticipation of this code path being deleted.
578 sk_sp<SkSpecialImage> specialSrc(SkSpecialImage::internal_fromBM(proxy, src, nullptr));
579 if (!specialSrc) {
580 return false;
581 }
582
583 sk_sp<SkSpecialImage> tmp(input->onFilterImage(specialSrc.get(),
584 this->mapContext(ctx),
585 offset));
586 if (!tmp) {
587 return false;
588 }
589
590 if (!tmp->internal_getBM(result)) {
591 return false;
592 }
593
594 if (!result->getTexture()) {
595 GrContext* context = src.getTexture()->getContext();
596
597 const SkImageInfo info = result->info();
598 if (kUnknown_SkColorType == info.colorType()) {
599 return false;
600 }
601 SkAutoTUnref<GrTexture> resultTex(
602 GrRefCachedBitmapTexture(context, *result, GrTextureParams::ClampNoF ilter()));
603 if (!resultTex) {
604 return false;
605 }
606 result->setPixelRef(new SkGrPixelRef(info, resultTex))->unref();
607 }
608
609 return true;
610 }
611 #endif
612
533 namespace { 613 namespace {
534 614
535 class CacheImpl : public SkImageFilter::Cache { 615 class CacheImpl : public SkImageFilter::Cache {
536 public: 616 public:
537 CacheImpl(size_t maxBytes) : fMaxBytes(maxBytes), fCurrentBytes(0) { } 617 CacheImpl(size_t maxBytes) : fMaxBytes(maxBytes), fCurrentBytes(0) { }
538 ~CacheImpl() override { 618 ~CacheImpl() override {
539 SkTDynamicHash<Value, Key>::Iter iter(&fLookup); 619 SkTDynamicHash<Value, Key>::Iter iter(&fLookup);
540 620
541 while (!iter.done()) { 621 while (!iter.done()) {
542 Value* v = &*iter; 622 Value* v = &*iter;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 false, /* preserveLCDText */ 770 false, /* preserveLCDText */
691 true /*forImageFilter*/); 771 true /*forImageFilter*/);
692 SkBaseDevice* dev = fDevice->onCreateDevice(cinfo, nullptr); 772 SkBaseDevice* dev = fDevice->onCreateDevice(cinfo, nullptr);
693 if (nullptr == dev) { 773 if (nullptr == dev) {
694 const SkSurfaceProps surfaceProps(fDevice->fSurfaceProps.flags(), 774 const SkSurfaceProps surfaceProps(fDevice->fSurfaceProps.flags(),
695 kUnknown_SkPixelGeometry); 775 kUnknown_SkPixelGeometry);
696 dev = SkBitmapDevice::Create(cinfo.fInfo, surfaceProps); 776 dev = SkBitmapDevice::Create(cinfo.fInfo, surfaceProps);
697 } 777 }
698 return dev; 778 return dev;
699 } 779 }
780
781 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const SkBitmap& src,
782 const SkImageFilter::Context& ctx,
783 SkBitmap* result, SkIPoint* offset) {
784 return fDevice->filterImage(filter, src, ctx, result, offset);
785 }
OLDNEW
« no previous file with comments | « src/core/SkDevice.cpp ('k') | src/gpu/SkGpuDevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698