Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "SkMorphologyImageFilter.h" | 8 #include "SkMorphologyImageFilter.h" |
| 9 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 , fRadius(SkISize::Make(radiusX, radiusY)) { | 36 , fRadius(SkISize::Make(radiusX, radiusY)) { |
| 37 } | 37 } |
| 38 | 38 |
| 39 void SkMorphologyImageFilter::flatten(SkWriteBuffer& buffer) const { | 39 void SkMorphologyImageFilter::flatten(SkWriteBuffer& buffer) const { |
| 40 this->INHERITED::flatten(buffer); | 40 this->INHERITED::flatten(buffer); |
| 41 buffer.writeInt(fRadius.fWidth); | 41 buffer.writeInt(fRadius.fWidth); |
| 42 buffer.writeInt(fRadius.fHeight); | 42 buffer.writeInt(fRadius.fHeight); |
| 43 } | 43 } |
| 44 | 44 |
| 45 static void call_proc_X(SkMorphologyImageFilter::Proc procX, | 45 static void call_proc_X(SkMorphologyImageFilter::Proc procX, |
| 46 const SkPixmap& src, SkBitmap* dst, | 46 const SkBitmap& src, SkBitmap* dst, |
| 47 int radiusX, const SkIRect& bounds) { | 47 int radiusX, const SkIRect& bounds) { |
| 48 procX(src.addr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), | 48 procX(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), |
| 49 radiusX, bounds.width(), bounds.height(), | 49 radiusX, bounds.width(), bounds.height(), |
| 50 src.rowBytesAsPixels(), dst->rowBytesAsPixels()); | 50 src.rowBytesAsPixels(), dst->rowBytesAsPixels()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 static void call_proc_Y(SkMorphologyImageFilter::Proc procY, | 53 static void call_proc_Y(SkMorphologyImageFilter::Proc procY, |
| 54 const SkPMColor* src, int srcRowBytesAsPixels, SkBitmap* dst, | 54 const SkPMColor* src, int srcRowBytesAsPixels, SkBitmap* dst, |
| 55 int radiusY, const SkIRect& bounds) { | 55 int radiusY, const SkIRect& bounds) { |
| 56 procY(src, dst->getAddr32(0, 0), | 56 procY(src, dst->getAddr32(0, 0), |
| 57 radiusY, bounds.height(), bounds.width(), | 57 radiusY, bounds.height(), bounds.width(), |
| 58 srcRowBytesAsPixels, dst->rowBytesAsPixels()); | 58 srcRowBytesAsPixels, dst->rowBytesAsPixels()); |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 543 SkIRect srcBounds = bounds; | 543 SkIRect srcBounds = bounds; |
| 544 srcBounds.offset(-inputOffset); | 544 srcBounds.offset(-inputOffset); |
| 545 | 545 |
| 546 if (0 == width && 0 == height) { | 546 if (0 == width && 0 == height) { |
| 547 offset->fX = bounds.left(); | 547 offset->fX = bounds.left(); |
| 548 offset->fY = bounds.top(); | 548 offset->fY = bounds.top(); |
| 549 return input->makeSubset(srcBounds); | 549 return input->makeSubset(srcBounds); |
| 550 } | 550 } |
| 551 | 551 |
| 552 #if SK_SUPPORT_GPU | 552 #if SK_SUPPORT_GPU |
| 553 if (input->peekTexture() && input->peekTexture()->getContext()) { | 553 if (source->peekTexture() && source->peekTexture()->getContext()) { |
| 554 GrTexture* inputTexture = input->asTextureRef(source->peekTexture()->get Context()); | |
| 555 if (!inputTexture) { | |
|
Stephen White
2016/04/06 16:21:23
I find this API somewhat error-prone, in that it's
robertphillips
2016/04/06 17:19:53
I have updated the SkSpecialImage API to cleave mo
| |
| 556 return nullptr; | |
| 557 } | |
| 558 | |
| 554 auto type = (kDilate_Op == this->op()) ? GrMorphologyEffect::kDilate_Mor phologyType | 559 auto type = (kDilate_Op == this->op()) ? GrMorphologyEffect::kDilate_Mor phologyType |
| 555 : GrMorphologyEffect::kErode_Morp hologyType; | 560 : GrMorphologyEffect::kErode_Morp hologyType; |
| 556 sk_sp<SkSpecialImage> result(apply_morphology(input.get(), srcBounds, ty pe, | 561 sk_sp<SkSpecialImage> result(apply_morphology(input.get(), srcBounds, ty pe, |
| 557 SkISize::Make(width, heigh t))); | 562 SkISize::Make(width, heigh t))); |
| 558 if (result) { | 563 if (result) { |
| 559 offset->fX = bounds.left(); | 564 offset->fX = bounds.left(); |
| 560 offset->fY = bounds.top(); | 565 offset->fY = bounds.top(); |
| 561 } | 566 } |
| 562 return result; | 567 return result; |
| 563 } | 568 } |
| 564 #endif | 569 #endif |
| 565 | 570 |
| 566 SkPixmap inputPixmap; | 571 SkBitmap inputBM; |
| 567 | 572 |
| 568 if (!input->peekPixels(&inputPixmap)) { | 573 if (!input->getROPixels(&inputBM)) { |
| 569 return nullptr; | 574 return nullptr; |
| 570 } | 575 } |
| 571 | 576 |
| 572 if (inputPixmap.colorType() != kN32_SkColorType) { | 577 if (inputBM.colorType() != kN32_SkColorType) { |
| 573 return nullptr; | 578 return nullptr; |
| 574 } | 579 } |
| 575 | 580 |
| 576 SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), | 581 SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), |
| 577 inputPixmap.colorType(), inputPixmap.al phaType()); | 582 inputBM.colorType(), inputBM.alphaType( )); |
| 578 | 583 |
| 579 SkBitmap dst; | 584 SkBitmap dst; |
| 580 if (!dst.tryAllocPixels(info)) { | 585 if (!dst.tryAllocPixels(info)) { |
| 581 return nullptr; | 586 return nullptr; |
| 582 } | 587 } |
| 583 | 588 |
| 584 SkAutoLockPixels dstLock(dst); | 589 SkAutoLockPixels inputLock(inputBM), dstLock(dst); |
| 585 | 590 |
| 586 SkMorphologyImageFilter::Proc procX, procY; | 591 SkMorphologyImageFilter::Proc procX, procY; |
| 587 | 592 |
| 588 if (kDilate_Op == this->op()) { | 593 if (kDilate_Op == this->op()) { |
| 589 procX = SkOpts::dilate_x; | 594 procX = SkOpts::dilate_x; |
| 590 procY = SkOpts::dilate_y; | 595 procY = SkOpts::dilate_y; |
| 591 } else { | 596 } else { |
| 592 procX = SkOpts::erode_x; | 597 procX = SkOpts::erode_x; |
| 593 procY = SkOpts::erode_y; | 598 procY = SkOpts::erode_y; |
| 594 } | 599 } |
| 595 | 600 |
| 596 if (width > 0 && height > 0) { | 601 if (width > 0 && height > 0) { |
| 597 SkBitmap tmp; | 602 SkBitmap tmp; |
| 598 if (!tmp.tryAllocPixels(info)) { | 603 if (!tmp.tryAllocPixels(info)) { |
| 599 return nullptr; | 604 return nullptr; |
| 600 } | 605 } |
| 601 | 606 |
| 602 SkAutoLockPixels tmpLock(tmp); | 607 SkAutoLockPixels tmpLock(tmp); |
| 603 | 608 |
| 604 call_proc_X(procX, inputPixmap, &tmp, width, srcBounds); | 609 call_proc_X(procX, inputBM, &tmp, width, srcBounds); |
| 605 SkIRect tmpBounds = SkIRect::MakeWH(srcBounds.width(), srcBounds.height( )); | 610 SkIRect tmpBounds = SkIRect::MakeWH(srcBounds.width(), srcBounds.height( )); |
| 606 call_proc_Y(procY, | 611 call_proc_Y(procY, |
| 607 tmp.getAddr32(tmpBounds.left(), tmpBounds.top()), tmp.rowByt esAsPixels(), | 612 tmp.getAddr32(tmpBounds.left(), tmpBounds.top()), tmp.rowByt esAsPixels(), |
| 608 &dst, height, tmpBounds); | 613 &dst, height, tmpBounds); |
| 609 } else if (width > 0) { | 614 } else if (width > 0) { |
| 610 call_proc_X(procX, inputPixmap, &dst, width, srcBounds); | 615 call_proc_X(procX, inputBM, &dst, width, srcBounds); |
| 611 } else if (height > 0) { | 616 } else if (height > 0) { |
| 612 call_proc_Y(procY, | 617 call_proc_Y(procY, |
| 613 inputPixmap.addr32(srcBounds.left(), srcBounds.top()), | 618 inputBM.getAddr32(srcBounds.left(), srcBounds.top()), |
| 614 inputPixmap.rowBytesAsPixels(), | 619 inputBM.rowBytesAsPixels(), |
| 615 &dst, height, srcBounds); | 620 &dst, height, srcBounds); |
| 616 } | 621 } |
| 617 offset->fX = bounds.left(); | 622 offset->fX = bounds.left(); |
| 618 offset->fY = bounds.top(); | 623 offset->fY = bounds.top(); |
| 619 | 624 |
| 620 return SkSpecialImage::MakeFromRaster(source->internal_getProxy(), | 625 return SkSpecialImage::MakeFromRaster(source->internal_getProxy(), |
| 621 SkIRect::MakeWH(bounds.width(), bounds .height()), | 626 SkIRect::MakeWH(bounds.width(), bounds .height()), |
| 622 dst); | 627 dst); |
| 623 } | 628 } |
| OLD | NEW |