| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 if (!applyCropRect(ctx, background, backgroundOffset, &bounds)) { | 70 if (!applyCropRect(ctx, background, backgroundOffset, &bounds)) { |
| 71 bounds.setEmpty(); | 71 bounds.setEmpty(); |
| 72 background.reset(); | 72 background.reset(); |
| 73 } | 73 } |
| 74 bounds.join(foregroundBounds); | 74 bounds.join(foregroundBounds); |
| 75 if (bounds.isEmpty()) { | 75 if (bounds.isEmpty()) { |
| 76 return false; | 76 return false; |
| 77 } | 77 } |
| 78 | 78 |
| 79 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); | 79 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); |
| 80 if (NULL == device.get()) { | 80 if (nullptr == device.get()) { |
| 81 return false; | 81 return false; |
| 82 } | 82 } |
| 83 SkCanvas canvas(device); | 83 SkCanvas canvas(device); |
| 84 canvas.translate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top())
); | 84 canvas.translate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top())
); |
| 85 SkPaint paint; | 85 SkPaint paint; |
| 86 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 86 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 87 canvas.drawBitmap(background, SkIntToScalar(backgroundOffset.fX), | 87 canvas.drawBitmap(background, SkIntToScalar(backgroundOffset.fX), |
| 88 SkIntToScalar(backgroundOffset.fY), &paint); | 88 SkIntToScalar(backgroundOffset.fY), &paint); |
| 89 paint.setXfermode(fMode); | 89 paint.setXfermode(fMode); |
| 90 canvas.drawBitmap(foreground, SkIntToScalar(foregroundOffset.fX), | 90 canvas.drawBitmap(foreground, SkIntToScalar(foregroundOffset.fX), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 116 this->getInput(1)->toString(str); | 116 this->getInput(1)->toString(str); |
| 117 str->appendf(")"); | 117 str->appendf(")"); |
| 118 } | 118 } |
| 119 str->append(")"); | 119 str->append(")"); |
| 120 } | 120 } |
| 121 #endif | 121 #endif |
| 122 | 122 |
| 123 #if SK_SUPPORT_GPU | 123 #if SK_SUPPORT_GPU |
| 124 | 124 |
| 125 bool SkXfermodeImageFilter::canFilterImageGPU() const { | 125 bool SkXfermodeImageFilter::canFilterImageGPU() const { |
| 126 return fMode && fMode->asFragmentProcessor(NULL, NULL, NULL) && !cropRectIsS
et(); | 126 return fMode && fMode->asFragmentProcessor(nullptr, nullptr, nullptr) && !cr
opRectIsSet(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, | 129 bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, |
| 130 const SkBitmap& src, | 130 const SkBitmap& src, |
| 131 const Context& ctx, | 131 const Context& ctx, |
| 132 SkBitmap* result, | 132 SkBitmap* result, |
| 133 SkIPoint* offset) const { | 133 SkIPoint* offset) const { |
| 134 SkBitmap background = src; | 134 SkBitmap background = src; |
| 135 SkIPoint backgroundOffset = SkIPoint::Make(0, 0); | 135 SkIPoint backgroundOffset = SkIPoint::Make(0, 0); |
| 136 if (this->getInput(0) && | 136 if (this->getInput(0) && |
| 137 !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &background, &bac
kgroundOffset)) { | 137 !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &background, &bac
kgroundOffset)) { |
| 138 return false; | 138 return false; |
| 139 } | 139 } |
| 140 | 140 |
| 141 GrTexture* backgroundTex = background.getTexture(); | 141 GrTexture* backgroundTex = background.getTexture(); |
| 142 if (NULL == backgroundTex) { | 142 if (nullptr == backgroundTex) { |
| 143 SkASSERT(false); | 143 SkASSERT(false); |
| 144 return false; | 144 return false; |
| 145 } | 145 } |
| 146 | 146 |
| 147 SkBitmap foreground = src; | 147 SkBitmap foreground = src; |
| 148 SkIPoint foregroundOffset = SkIPoint::Make(0, 0); | 148 SkIPoint foregroundOffset = SkIPoint::Make(0, 0); |
| 149 if (this->getInput(1) && | 149 if (this->getInput(1) && |
| 150 !this->getInput(1)->getInputResultGPU(proxy, src, ctx, &foreground, &for
egroundOffset)) { | 150 !this->getInput(1)->getInputResultGPU(proxy, src, ctx, &foreground, &for
egroundOffset)) { |
| 151 return false; | 151 return false; |
| 152 } | 152 } |
| 153 GrTexture* foregroundTex = foreground.getTexture(); | 153 GrTexture* foregroundTex = foreground.getTexture(); |
| 154 GrContext* context = foregroundTex->getContext(); | 154 GrContext* context = foregroundTex->getContext(); |
| 155 | 155 |
| 156 GrFragmentProcessor* xferProcessor = NULL; | 156 GrFragmentProcessor* xferProcessor = nullptr; |
| 157 | 157 |
| 158 GrSurfaceDesc desc; | 158 GrSurfaceDesc desc; |
| 159 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 159 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 160 desc.fWidth = src.width(); | 160 desc.fWidth = src.width(); |
| 161 desc.fHeight = src.height(); | 161 desc.fHeight = src.height(); |
| 162 desc.fConfig = kSkia8888_GrPixelConfig; | 162 desc.fConfig = kSkia8888_GrPixelConfig; |
| 163 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(
desc)); | 163 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(
desc)); |
| 164 if (!dst) { | 164 if (!dst) { |
| 165 return false; | 165 return false; |
| 166 } | 166 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 SkMatrix::I(), srcRect); | 201 SkMatrix::I(), srcRect); |
| 202 | 202 |
| 203 offset->fX = backgroundOffset.fX; | 203 offset->fX = backgroundOffset.fX; |
| 204 offset->fY = backgroundOffset.fY; | 204 offset->fY = backgroundOffset.fY; |
| 205 WrapTexture(dst, src.width(), src.height(), result); | 205 WrapTexture(dst, src.width(), src.height(), result); |
| 206 return true; | 206 return true; |
| 207 } | 207 } |
| 208 | 208 |
| 209 #endif | 209 #endif |
| 210 | 210 |
| OLD | NEW |