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 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 | 54 |
55 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(w, h)); | 55 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(w, h)); |
56 if (NULL == device.get()) { | 56 if (NULL == device.get()) { |
57 return false; | 57 return false; |
58 } | 58 } |
59 SkCanvas canvas(device); | 59 SkCanvas canvas(device); |
60 SkPaint paint; | 60 SkPaint paint; |
61 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 61 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
62 | 62 |
63 SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(subset, | |
64 SkShader::kRepeat_TileMode, SkShader::kRepeat_
TileMode)); | |
65 SkMatrix shaderMatrix; | 63 SkMatrix shaderMatrix; |
66 shaderMatrix.setTranslate(SkIntToScalar(srcOffset.fX), | 64 shaderMatrix.setTranslate(SkIntToScalar(srcOffset.fX), |
67 SkIntToScalar(srcOffset.fY)); | 65 SkIntToScalar(srcOffset.fY)); |
68 shader->setLocalMatrix(shaderMatrix); | 66 SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(subset, |
| 67 SkShader::kRepeat_TileMode, SkShader::kRepeat_
TileMode, |
| 68 &shaderMatrix)); |
69 paint.setShader(shader); | 69 paint.setShader(shader); |
70 canvas.translate(-dstRect.fLeft, -dstRect.fTop); | 70 canvas.translate(-dstRect.fLeft, -dstRect.fTop); |
71 canvas.drawRect(dstRect, paint); | 71 canvas.drawRect(dstRect, paint); |
72 *dst = device->accessBitmap(false); | 72 *dst = device->accessBitmap(false); |
73 offset->fX = dstIRect.fLeft; | 73 offset->fX = dstIRect.fLeft; |
74 offset->fY = dstIRect.fTop; | 74 offset->fY = dstIRect.fTop; |
75 return true; | 75 return true; |
76 } | 76 } |
77 | 77 |
78 SkTileImageFilter::SkTileImageFilter(SkReadBuffer& buffer) | 78 SkTileImageFilter::SkTileImageFilter(SkReadBuffer& buffer) |
79 : INHERITED(1, buffer) { | 79 : INHERITED(1, buffer) { |
80 buffer.readRect(&fSrcRect); | 80 buffer.readRect(&fSrcRect); |
81 buffer.readRect(&fDstRect); | 81 buffer.readRect(&fDstRect); |
82 buffer.validate(buffer.isValid() && SkIsValidRect(fSrcRect) && SkIsValidRect
(fDstRect)); | 82 buffer.validate(buffer.isValid() && SkIsValidRect(fSrcRect) && SkIsValidRect
(fDstRect)); |
83 } | 83 } |
84 | 84 |
85 void SkTileImageFilter::flatten(SkWriteBuffer& buffer) const { | 85 void SkTileImageFilter::flatten(SkWriteBuffer& buffer) const { |
86 this->INHERITED::flatten(buffer); | 86 this->INHERITED::flatten(buffer); |
87 buffer.writeRect(fSrcRect); | 87 buffer.writeRect(fSrcRect); |
88 buffer.writeRect(fDstRect); | 88 buffer.writeRect(fDstRect); |
89 } | 89 } |
OLD | NEW |