| 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 "SkOffsetImageFilter.h" | 8 #include "SkOffsetImageFilter.h" |
| 9 | 9 |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 } else { | 34 } else { |
| 35 SkIRect bounds; | 35 SkIRect bounds; |
| 36 SkIRect srcBounds = SkIRect::MakeWH(input->width(), input->height()); | 36 SkIRect srcBounds = SkIRect::MakeWH(input->width(), input->height()); |
| 37 srcBounds.offset(srcOffset); | 37 srcBounds.offset(srcOffset); |
| 38 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { | 38 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { |
| 39 return nullptr; | 39 return nullptr; |
| 40 } | 40 } |
| 41 | 41 |
| 42 SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), | 42 SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), |
| 43 kPremul_SkAlphaType); | 43 kPremul_SkAlphaType); |
| 44 SkAutoTUnref<SkSpecialSurface> surf(source->newSurface(info)); | 44 sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); |
| 45 if (!surf) { | 45 if (!surf) { |
| 46 return nullptr; | 46 return nullptr; |
| 47 } | 47 } |
| 48 | 48 |
| 49 SkCanvas* canvas = surf->getCanvas(); | 49 SkCanvas* canvas = surf->getCanvas(); |
| 50 SkASSERT(canvas); | 50 SkASSERT(canvas); |
| 51 | 51 |
| 52 // TODO: it seems like this clear shouldn't be necessary (see skbug.com/
5075) | 52 // TODO: it seems like this clear shouldn't be necessary (see skbug.com/
5075) |
| 53 canvas->clear(0x0); | 53 canvas->clear(0x0); |
| 54 | 54 |
| 55 SkPaint paint; | 55 SkPaint paint; |
| 56 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 56 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 57 canvas->translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), | 57 canvas->translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), |
| 58 SkIntToScalar(srcOffset.fY - bounds.fTop)); | 58 SkIntToScalar(srcOffset.fY - bounds.fTop)); |
| 59 | 59 |
| 60 input->draw(canvas, vec.x(), vec.y(), &paint); | 60 input->draw(canvas, vec.x(), vec.y(), &paint); |
| 61 | 61 |
| 62 offset->fX = bounds.fLeft; | 62 offset->fX = bounds.fLeft; |
| 63 offset->fY = bounds.fTop; | 63 offset->fY = bounds.fTop; |
| 64 return surf->newImageSnapshot(); | 64 return surf->makeImageSnapshot().release(); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 void SkOffsetImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) cons
t { | 68 void SkOffsetImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) cons
t { |
| 69 if (getInput(0)) { | 69 if (getInput(0)) { |
| 70 getInput(0)->computeFastBounds(src, dst); | 70 getInput(0)->computeFastBounds(src, dst); |
| 71 } else { | 71 } else { |
| 72 *dst = src; | 72 *dst = src; |
| 73 } | 73 } |
| 74 dst->offset(fOffset.fX, fOffset.fY); | 74 dst->offset(fOffset.fX, fOffset.fY); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 void SkOffsetImageFilter::toString(SkString* str) const { | 108 void SkOffsetImageFilter::toString(SkString* str) const { |
| 109 str->appendf("SkOffsetImageFilter: ("); | 109 str->appendf("SkOffsetImageFilter: ("); |
| 110 str->appendf("offset: (%f, %f) ", fOffset.fX, fOffset.fY); | 110 str->appendf("offset: (%f, %f) ", fOffset.fX, fOffset.fY); |
| 111 str->append("input: ("); | 111 str->append("input: ("); |
| 112 if (this->getInput(0)) { | 112 if (this->getInput(0)) { |
| 113 this->getInput(0)->toString(str); | 113 this->getInput(0)->toString(str); |
| 114 } | 114 } |
| 115 str->append("))"); | 115 str->append("))"); |
| 116 } | 116 } |
| 117 #endif | 117 #endif |
| OLD | NEW |