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

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

Issue 1888243003: Remove deprecated paths from image filter infrastructure. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove some spurious printfs 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 /* 259 if (this->onFilterImageDeprecated(proxy, src, context, result, offset)) {
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)) {
265 if (context.cache()) { 260 if (context.cache()) {
266 context.cache()->set(key, *result, *offset); 261 context.cache()->set(key, *result, *offset);
267 SkAutoMutexAcquire mutex(fMutex); 262 SkAutoMutexAcquire mutex(fMutex);
268 fCacheKeys.push_back(key); 263 fCacheKeys.push_back(key);
269 } 264 }
270 return true; 265 return true;
271 } 266 }
272 return false; 267 return false;
273 } 268 }
274 269
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 SkIRect temp = this->onFilterNodeBounds(srcBounds, ctx.ctm(), kForward_MapDi rection); 416 SkIRect temp = this->onFilterNodeBounds(srcBounds, ctx.ctm(), kForward_MapDi rection);
422 fCropRect.applyTo(temp, ctx.ctm(), this->affectsTransparentBlack(), dstBound s); 417 fCropRect.applyTo(temp, ctx.ctm(), this->affectsTransparentBlack(), dstBound s);
423 // Intersect against the clip bounds, in case the crop rect has 418 // Intersect against the clip bounds, in case the crop rect has
424 // grown the bounds beyond the original clip. This can happen for 419 // grown the bounds beyond the original clip. This can happen for
425 // example in tiling, where the clip is much smaller than the filtered 420 // example in tiling, where the clip is much smaller than the filtered
426 // primitive. If we didn't do this, we would be processing the filter 421 // primitive. If we didn't do this, we would be processing the filter
427 // at the full crop rect size in every tile. 422 // at the full crop rect size in every tile.
428 return dstBounds->intersect(ctx.clipBounds()); 423 return dstBounds->intersect(ctx.clipBounds());
429 } 424 }
430 425
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
460 // Return a larger (newWidth x newHeight) copy of 'src' with black padding 426 // Return a larger (newWidth x newHeight) copy of 'src' with black padding
461 // around it. 427 // around it.
462 static sk_sp<SkSpecialImage> pad_image(SkSpecialImage* src, 428 static sk_sp<SkSpecialImage> pad_image(SkSpecialImage* src,
463 int newWidth, int newHeight, int offX, in t offY) { 429 int newWidth, int newHeight, int offX, in t offY) {
464 430
465 SkImageInfo info = SkImageInfo::MakeN32Premul(newWidth, newHeight); 431 SkImageInfo info = SkImageInfo::MakeN32Premul(newWidth, newHeight);
466 sk_sp<SkSpecialSurface> surf(src->makeSurface(info)); 432 sk_sp<SkSpecialSurface> surf(src->makeSurface(info));
467 if (!surf) { 433 if (!surf) {
468 return nullptr; 434 return nullptr;
469 } 435 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 return sk_sp<SkSpecialImage>(SkRef(src)); 523 return sk_sp<SkSpecialImage>(SkRef(src));
558 } 524 }
559 525
560 sk_sp<SkSpecialImage> result(input->filterImage(src, this->mapContext(ctx), offset)); 526 sk_sp<SkSpecialImage> result(input->filterImage(src, this->mapContext(ctx), offset));
561 527
562 SkASSERT(!result || src->isTextureBacked() == result->isTextureBacked()); 528 SkASSERT(!result || src->isTextureBacked() == result->isTextureBacked());
563 529
564 return result; 530 return result;
565 } 531 }
566 532
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
613 namespace { 533 namespace {
614 534
615 class CacheImpl : public SkImageFilter::Cache { 535 class CacheImpl : public SkImageFilter::Cache {
616 public: 536 public:
617 CacheImpl(size_t maxBytes) : fMaxBytes(maxBytes), fCurrentBytes(0) { } 537 CacheImpl(size_t maxBytes) : fMaxBytes(maxBytes), fCurrentBytes(0) { }
618 ~CacheImpl() override { 538 ~CacheImpl() override {
619 SkTDynamicHash<Value, Key>::Iter iter(&fLookup); 539 SkTDynamicHash<Value, Key>::Iter iter(&fLookup);
620 540
621 while (!iter.done()) { 541 while (!iter.done()) {
622 Value* v = &*iter; 542 Value* v = &*iter;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 false, /* preserveLCDText */ 690 false, /* preserveLCDText */
771 true /*forImageFilter*/); 691 true /*forImageFilter*/);
772 SkBaseDevice* dev = fDevice->onCreateDevice(cinfo, nullptr); 692 SkBaseDevice* dev = fDevice->onCreateDevice(cinfo, nullptr);
773 if (nullptr == dev) { 693 if (nullptr == dev) {
774 const SkSurfaceProps surfaceProps(fDevice->fSurfaceProps.flags(), 694 const SkSurfaceProps surfaceProps(fDevice->fSurfaceProps.flags(),
775 kUnknown_SkPixelGeometry); 695 kUnknown_SkPixelGeometry);
776 dev = SkBitmapDevice::Create(cinfo.fInfo, surfaceProps); 696 dev = SkBitmapDevice::Create(cinfo.fInfo, surfaceProps);
777 } 697 }
778 return dev; 698 return dev;
779 } 699 }
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