| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright 2013 Google Inc. | 2  * Copyright 2013 Google Inc. | 
| 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 "SkTileImageFilter.h" | 8 #include "SkTileImageFilter.h" | 
| 9 | 9 | 
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 48         return nullptr; | 48         return nullptr; | 
| 49     } | 49     } | 
| 50 | 50 | 
| 51     SkRect dstRect; | 51     SkRect dstRect; | 
| 52     ctx.ctm().mapRect(&dstRect, fDstRect); | 52     ctx.ctm().mapRect(&dstRect, fDstRect); | 
| 53     if (!dstRect.intersect(SkRect::Make(ctx.clipBounds()))) { | 53     if (!dstRect.intersect(SkRect::Make(ctx.clipBounds()))) { | 
| 54         return nullptr; | 54         return nullptr; | 
| 55     } | 55     } | 
| 56 | 56 | 
| 57     const SkIRect dstIRect = dstRect.roundOut(); | 57     const SkIRect dstIRect = dstRect.roundOut(); | 
| 58     if (!fSrcRect.width() || !fSrcRect.height() || !dstIRect.width() || !dstIRec
     t.height()) { | 58     int dstWidth = dstIRect.width(); | 
|  | 59     int dstHeight = dstIRect.height(); | 
|  | 60     if (!fSrcRect.width() || !fSrcRect.height() || !dstWidth || !dstHeight) { | 
| 59         return nullptr; | 61         return nullptr; | 
| 60     } | 62     } | 
| 61 | 63 | 
| 62     SkRect srcRect; | 64     SkRect srcRect; | 
| 63     ctx.ctm().mapRect(&srcRect, fSrcRect); | 65     ctx.ctm().mapRect(&srcRect, fSrcRect); | 
| 64     SkIRect srcIRect; | 66     SkIRect srcIRect; | 
| 65     srcRect.roundOut(&srcIRect); | 67     srcRect.roundOut(&srcIRect); | 
| 66     srcIRect.offset(-inputOffset); | 68     srcIRect.offset(-inputOffset); | 
| 67     const SkIRect inputBounds = SkIRect::MakeWH(input->width(), input->height())
     ; | 69     const SkIRect inputBounds = SkIRect::MakeWH(input->width(), input->height())
     ; | 
| 68 | 70 | 
| 69     if (!SkIRect::Intersects(srcIRect, inputBounds)) { | 71     if (!SkIRect::Intersects(srcIRect, inputBounds)) { | 
| 70         return nullptr; | 72         return nullptr; | 
| 71     } | 73     } | 
| 72 | 74 | 
| 73     // We create an SkImage here b.c. it needs to be a tight fit for the tiling | 75     // We create an SkImage here b.c. it needs to be a tight fit for the tiling | 
| 74     sk_sp<SkImage> subset; | 76     sk_sp<SkImage> subset; | 
| 75     if (inputBounds.contains(srcIRect)) { | 77     if (inputBounds.contains(srcIRect)) { | 
| 76         subset = input->makeTightSubset(srcIRect); | 78         subset = input->makeTightSubset(srcIRect); | 
| 77         if (!subset) { | 79         if (!subset) { | 
| 78             return nullptr; | 80             return nullptr; | 
| 79         } | 81         } | 
| 80     } else { | 82     } else { | 
| 81         sk_sp<SkSurface> surf(input->makeTightSurface(ctx.outputProperties(), sr
     cIRect.size())); | 83         const SkImageInfo info = SkImageInfo::MakeN32(srcIRect.width(), srcIRect
     .height(), | 
|  | 84                                                       kPremul_SkAlphaType); | 
|  | 85         sk_sp<SkSurface> surf(input->makeTightSurface(info)); | 
| 82         if (!surf) { | 86         if (!surf) { | 
| 83             return nullptr; | 87             return nullptr; | 
| 84         } | 88         } | 
| 85 | 89 | 
| 86         SkCanvas* canvas = surf->getCanvas(); | 90         SkCanvas* canvas = surf->getCanvas(); | 
| 87         SkASSERT(canvas); | 91         SkASSERT(canvas); | 
| 88 | 92 | 
| 89         SkPaint paint; | 93         SkPaint paint; | 
| 90         paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 94         paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 
| 91 | 95 | 
| 92         input->draw(canvas, | 96         input->draw(canvas, | 
| 93                     SkIntToScalar(inputOffset.x()), SkIntToScalar(inputOffset.y(
     )), | 97                     SkIntToScalar(inputOffset.x()), SkIntToScalar(inputOffset.y(
     )), | 
| 94                     &paint); | 98                     &paint); | 
| 95 | 99 | 
| 96         subset = surf->makeImageSnapshot(); | 100         subset = surf->makeImageSnapshot(); | 
| 97     } | 101     } | 
| 98     SkASSERT(subset->width() == srcIRect.width()); | 102     SkASSERT(subset->width() == srcIRect.width()); | 
| 99     SkASSERT(subset->height() == srcIRect.height()); | 103     SkASSERT(subset->height() == srcIRect.height()); | 
| 100 | 104 | 
| 101     sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), dst
     IRect.size())); | 105     const SkImageInfo info = SkImageInfo::MakeN32(dstWidth, dstHeight, kPremul_S
     kAlphaType); | 
|  | 106 | 
|  | 107     sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); | 
| 102     if (!surf) { | 108     if (!surf) { | 
| 103         return nullptr; | 109         return nullptr; | 
| 104     } | 110     } | 
| 105 | 111 | 
| 106     SkCanvas* canvas = surf->getCanvas(); | 112     SkCanvas* canvas = surf->getCanvas(); | 
| 107     SkASSERT(canvas); | 113     SkASSERT(canvas); | 
| 108 | 114 | 
| 109     SkPaint paint; | 115     SkPaint paint; | 
| 110     paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 116     paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 
| 111     paint.setShader(subset->makeShader(SkShader::kRepeat_TileMode, SkShader::kRe
     peat_TileMode)); | 117     paint.setShader(subset->makeShader(SkShader::kRepeat_TileMode, SkShader::kRe
     peat_TileMode)); | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 154     str->appendf(" dst: %.2f %.2f %.2f %.2f", | 160     str->appendf(" dst: %.2f %.2f %.2f %.2f", | 
| 155                  fDstRect.fLeft, fDstRect.fTop, fDstRect.fRight, fDstRect.fBotto
     m); | 161                  fDstRect.fLeft, fDstRect.fTop, fDstRect.fRight, fDstRect.fBotto
     m); | 
| 156     if (this->getInput(0)) { | 162     if (this->getInput(0)) { | 
| 157         str->appendf("input: ("); | 163         str->appendf("input: ("); | 
| 158         this->getInput(0)->toString(str); | 164         this->getInput(0)->toString(str); | 
| 159         str->appendf(")"); | 165         str->appendf(")"); | 
| 160     } | 166     } | 
| 161     str->append(")"); | 167     str->append(")"); | 
| 162 } | 168 } | 
| 163 #endif | 169 #endif | 
| OLD | NEW | 
|---|