| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 The Android Open Source Project | 2 * Copyright 2013 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 "SkXfermodeImageFilter.h" | 8 #include "SkXfermodeImageFilter.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 fMode = buffer.readXfermode(); | 37 fMode = buffer.readXfermode(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void SkXfermodeImageFilter::flatten(SkWriteBuffer& buffer) const { | 40 void SkXfermodeImageFilter::flatten(SkWriteBuffer& buffer) const { |
| 41 this->INHERITED::flatten(buffer); | 41 this->INHERITED::flatten(buffer); |
| 42 buffer.writeFlattenable(fMode); | 42 buffer.writeFlattenable(fMode); |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool SkXfermodeImageFilter::onFilterImage(Proxy* proxy, | 45 bool SkXfermodeImageFilter::onFilterImage(Proxy* proxy, |
| 46 const SkBitmap& src, | 46 const SkBitmap& src, |
| 47 const SkMatrix& ctm, | 47 const Context& ctx, |
| 48 SkBitmap* dst, | 48 SkBitmap* dst, |
| 49 SkIPoint* offset) const { | 49 SkIPoint* offset) const { |
| 50 SkBitmap background = src, foreground = src; | 50 SkBitmap background = src, foreground = src; |
| 51 SkImageFilter* backgroundInput = getInput(0); | 51 SkImageFilter* backgroundInput = getInput(0); |
| 52 SkImageFilter* foregroundInput = getInput(1); | 52 SkImageFilter* foregroundInput = getInput(1); |
| 53 SkIPoint backgroundOffset = SkIPoint::Make(0, 0); | 53 SkIPoint backgroundOffset = SkIPoint::Make(0, 0); |
| 54 if (backgroundInput && | 54 if (backgroundInput && |
| 55 !backgroundInput->filterImage(proxy, src, ctm, &background, &backgroundO
ffset)) { | 55 !backgroundInput->filterImage(proxy, src, ctx, &background, &backgroundO
ffset)) { |
| 56 return false; | 56 return false; |
| 57 } | 57 } |
| 58 SkIPoint foregroundOffset = SkIPoint::Make(0, 0); | 58 SkIPoint foregroundOffset = SkIPoint::Make(0, 0); |
| 59 if (foregroundInput && | 59 if (foregroundInput && |
| 60 !foregroundInput->filterImage(proxy, src, ctm, &foreground, &foregroundO
ffset)) { | 60 !foregroundInput->filterImage(proxy, src, ctx, &foreground, &foregroundO
ffset)) { |
| 61 return false; | 61 return false; |
| 62 } | 62 } |
| 63 | 63 |
| 64 SkIRect bounds, foregroundBounds; | 64 SkIRect bounds, foregroundBounds; |
| 65 background.getBounds(&bounds); | 65 background.getBounds(&bounds); |
| 66 bounds.offset(backgroundOffset); | 66 bounds.offset(backgroundOffset); |
| 67 foreground.getBounds(&foregroundBounds); | 67 foreground.getBounds(&foregroundBounds); |
| 68 foregroundBounds.offset(foregroundOffset); | 68 foregroundBounds.offset(foregroundOffset); |
| 69 bounds.join(foregroundBounds); | 69 bounds.join(foregroundBounds); |
| 70 if (!applyCropRect(&bounds, ctm)) { | 70 if (!applyCropRect(&bounds, ctx.ctm())) { |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 | 73 |
| 74 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); | 74 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); |
| 75 if (NULL == device.get()) { | 75 if (NULL == device.get()) { |
| 76 return false; | 76 return false; |
| 77 } | 77 } |
| 78 SkCanvas canvas(device); | 78 SkCanvas canvas(device); |
| 79 canvas.translate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top())
); | 79 canvas.translate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top())
); |
| 80 SkPaint paint; | 80 SkPaint paint; |
| 81 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 81 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 82 canvas.drawBitmap(background, SkIntToScalar(backgroundOffset.fX), | 82 canvas.drawBitmap(background, SkIntToScalar(backgroundOffset.fX), |
| 83 SkIntToScalar(backgroundOffset.fY), &paint); | 83 SkIntToScalar(backgroundOffset.fY), &paint); |
| 84 paint.setXfermode(fMode); | 84 paint.setXfermode(fMode); |
| 85 canvas.drawBitmap(foreground, SkIntToScalar(foregroundOffset.fX), | 85 canvas.drawBitmap(foreground, SkIntToScalar(foregroundOffset.fX), |
| 86 SkIntToScalar(foregroundOffset.fY), &paint); | 86 SkIntToScalar(foregroundOffset.fY), &paint); |
| 87 canvas.clipRect(SkRect::Make(foregroundBounds), SkRegion::kDifference_Op); | 87 canvas.clipRect(SkRect::Make(foregroundBounds), SkRegion::kDifference_Op); |
| 88 paint.setColor(SK_ColorTRANSPARENT); | 88 paint.setColor(SK_ColorTRANSPARENT); |
| 89 canvas.drawPaint(paint); | 89 canvas.drawPaint(paint); |
| 90 *dst = device->accessBitmap(false); | 90 *dst = device->accessBitmap(false); |
| 91 offset->fX = bounds.left(); | 91 offset->fX = bounds.left(); |
| 92 offset->fY = bounds.top(); | 92 offset->fY = bounds.top(); |
| 93 return true; | 93 return true; |
| 94 } | 94 } |
| 95 | 95 |
| 96 #if SK_SUPPORT_GPU | 96 #if SK_SUPPORT_GPU |
| 97 | 97 |
| 98 bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, | 98 bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, |
| 99 const SkBitmap& src, | 99 const SkBitmap& src, |
| 100 const SkMatrix& ctm, | 100 const Context& ctx, |
| 101 SkBitmap* result, | 101 SkBitmap* result, |
| 102 SkIPoint* offset) const { | 102 SkIPoint* offset) const { |
| 103 SkBitmap background = src; | 103 SkBitmap background = src; |
| 104 SkIPoint backgroundOffset = SkIPoint::Make(0, 0); | 104 SkIPoint backgroundOffset = SkIPoint::Make(0, 0); |
| 105 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctm, &backgro
und, | 105 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &backgro
und, |
| 106 &backgroundOffset)) { | 106 &backgroundOffset)) { |
| 107 return false; | 107 return false; |
| 108 } | 108 } |
| 109 GrTexture* backgroundTex = background.getTexture(); | 109 GrTexture* backgroundTex = background.getTexture(); |
| 110 SkBitmap foreground = src; | 110 SkBitmap foreground = src; |
| 111 SkIPoint foregroundOffset = SkIPoint::Make(0, 0); | 111 SkIPoint foregroundOffset = SkIPoint::Make(0, 0); |
| 112 if (getInput(1) && !getInput(1)->getInputResultGPU(proxy, src, ctm, &foregro
und, | 112 if (getInput(1) && !getInput(1)->getInputResultGPU(proxy, src, ctx, &foregro
und, |
| 113 &foregroundOffset)) { | 113 &foregroundOffset)) { |
| 114 return false; | 114 return false; |
| 115 } | 115 } |
| 116 GrTexture* foregroundTex = foreground.getTexture(); | 116 GrTexture* foregroundTex = foreground.getTexture(); |
| 117 GrContext* context = foregroundTex->getContext(); | 117 GrContext* context = foregroundTex->getContext(); |
| 118 | 118 |
| 119 GrEffectRef* xferEffect = NULL; | 119 GrEffectRef* xferEffect = NULL; |
| 120 | 120 |
| 121 GrTextureDesc desc; | 121 GrTextureDesc desc; |
| 122 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 122 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 foregroundPaint.addColorTextureEffect(foregroundTex, foregroundMatrix); | 157 foregroundPaint.addColorTextureEffect(foregroundTex, foregroundMatrix); |
| 158 context->drawRect(foregroundPaint, srcRect); | 158 context->drawRect(foregroundPaint, srcRect); |
| 159 } | 159 } |
| 160 offset->fX = backgroundOffset.fX; | 160 offset->fX = backgroundOffset.fX; |
| 161 offset->fY = backgroundOffset.fY; | 161 offset->fY = backgroundOffset.fY; |
| 162 WrapTexture(dst, src.width(), src.height(), result); | 162 WrapTexture(dst, src.width(), src.height(), result); |
| 163 return true; | 163 return true; |
| 164 } | 164 } |
| 165 | 165 |
| 166 #endif | 166 #endif |
| OLD | NEW |