Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "SkDropShadowImageFilter.h" | |
| 9 | |
| 10 #include "SkBitmap.h" | |
| 11 #include "SkBlurImageFilter.h" | |
| 12 #include "SkCanvas.h" | |
| 13 #include "SkColorMatrixFilter.h" | |
| 14 #include "SkDevice.h" | |
| 15 #include "SkFlattenableBuffers.h" | |
| 16 | |
| 17 SkDropShadowImageFilter::SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkSca lar sigma, SkColor color, SkImageFilter* input) | |
| 18 : SkImageFilter(input) | |
| 19 , fDx(dx) | |
| 20 , fDy(dy) | |
| 21 , fSigma(sigma) | |
| 22 , fColor(color) | |
| 23 { | |
| 24 } | |
| 25 | |
| 26 SkDropShadowImageFilter::SkDropShadowImageFilter(SkFlattenableReadBuffer& buffer ) : SkImageFilter(buffer) | |
| 27 { | |
| 28 fDx = buffer.readScalar(); | |
| 29 fDy = buffer.readScalar(); | |
| 30 fSigma = buffer.readScalar(); | |
| 31 fColor = buffer.readColor(); | |
| 32 } | |
| 33 | |
| 34 void SkDropShadowImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const | |
| 35 { | |
| 36 this->INHERITED::flatten(buffer); | |
|
Justin Novosad
2013/08/06 19:27:24
FYI: This line was missing in the Blink version of
| |
| 37 buffer.writeScalar(fDx); | |
| 38 buffer.writeScalar(fDy); | |
| 39 buffer.writeScalar(fSigma); | |
| 40 buffer.writeColor(fColor); | |
| 41 } | |
| 42 | |
| 43 bool SkDropShadowImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source , const SkMatrix& matrix, SkBitmap* result, SkIPoint* loc) | |
| 44 { | |
| 45 SkBitmap src = source; | |
| 46 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, lo c)) | |
| 47 return false; | |
| 48 | |
| 49 SkAutoTUnref<SkDevice> device(proxy->createDevice(src.width(), src.height()) ); | |
| 50 SkCanvas canvas(device.get()); | |
| 51 | |
| 52 SkAutoTUnref<SkImageFilter> blurFilter(new SkBlurImageFilter(fSigma, fSigma) ); | |
| 53 SkAutoTUnref<SkColorFilter> colorFilter(SkColorFilter::CreateModeFilter(fCol or, SkXfermode::kSrcIn_Mode)); | |
| 54 SkPaint paint; | |
| 55 paint.setImageFilter(blurFilter.get()); | |
| 56 paint.setColorFilter(colorFilter.get()); | |
| 57 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | |
| 58 canvas.saveLayer(0, &paint); | |
| 59 canvas.drawBitmap(src, fDx, fDy); | |
|
Stephen White
2013/08/06 19:33:37
You can use drawBitmap(src, fDx, fDy, &paint) dire
| |
| 60 canvas.restore(); | |
| 61 canvas.drawBitmap(src, 0, 0); | |
| 62 *result = device.get()->accessBitmap(false); | |
|
Stephen White
2013/08/06 19:33:37
Nit: I think you can just use device->accessBitmap
| |
| 63 return true; | |
| 64 } | |
| 65 | |
| OLD | NEW |