Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: src/effects/SkTileImageFilter.cpp

Issue 106933002: Implement srcRect and dstRect functionality in SkBitmapSource. This is required for the "preserveAs… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix nits Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/effects/SkBitmapSource.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "SkDevice.h" 11 #include "SkDevice.h"
12 #include "SkFlattenableBuffers.h" 12 #include "SkFlattenableBuffers.h"
13 #include "SkMatrix.h" 13 #include "SkMatrix.h"
14 #include "SkPaint.h" 14 #include "SkPaint.h"
15 #include "SkShader.h" 15 #include "SkShader.h"
16 #include "SkValidationUtils.h" 16 #include "SkValidationUtils.h"
17 17
18 bool SkTileImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, const S kMatrix& ctm, 18 bool SkTileImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, const S kMatrix& ctm,
19 SkBitmap* dst, SkIPoint* offset) { 19 SkBitmap* dst, SkIPoint* offset) {
20 SkBitmap source = src; 20 SkBitmap source = src;
21 SkImageFilter* input = getInput(0); 21 SkImageFilter* input = getInput(0);
22 SkIPoint localOffset = SkIPoint::Make(0, 0); 22 SkIPoint localOffset = SkIPoint::Make(0, 0);
23 if (input && !input->filterImage(proxy, src, ctm, &source, &localOffset)) { 23 if (input && !input->filterImage(proxy, src, ctm, &source, &localOffset)) {
24 return false; 24 return false;
25 } 25 }
26 26
27 int w = SkScalarTruncToInt(fDstRect.width()); 27 SkRect dstRect;
28 int h = SkScalarTruncToInt(fDstRect.height()); 28 ctm.mapRect(&dstRect, fDstRect);
29 int w = SkScalarCeilToInt(dstRect.width());
30 int h = SkScalarCeilToInt(dstRect.height());
29 if (!fSrcRect.width() || !fSrcRect.height() || !w || !h) { 31 if (!fSrcRect.width() || !fSrcRect.height() || !w || !h) {
30 return false; 32 return false;
31 } 33 }
32 34
33 SkIRect srcRect; 35 SkRect srcRect;
34 fSrcRect.roundOut(&srcRect); 36 ctm.mapRect(&srcRect, fSrcRect);
37 SkIRect srcIRect;
38 srcRect.roundOut(&srcIRect);
35 SkBitmap subset; 39 SkBitmap subset;
36 if (!source.extractSubset(&subset, srcRect)) { 40 SkIRect bounds;
41 source.getBounds(&bounds);
42 if (!srcIRect.intersect(bounds)) {
43 return true;
44 } else if (!source.extractSubset(&subset, srcIRect)) {
37 return false; 45 return false;
38 } 46 }
39 47
40 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(w, h)); 48 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(w, h));
41 if (NULL == device.get()) { 49 if (NULL == device.get()) {
42 return false; 50 return false;
43 } 51 }
44 SkIRect bounds;
45 source.getBounds(&bounds);
46 SkCanvas canvas(device); 52 SkCanvas canvas(device);
47 SkPaint paint; 53 SkPaint paint;
48 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 54 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
49 55
50 SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(subset, 56 SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(subset,
51 SkShader::kRepeat_TileMode, SkShader::kRepeat_ TileMode)); 57 SkShader::kRepeat_TileMode, SkShader::kRepeat_ TileMode));
52 paint.setShader(shader); 58 paint.setShader(shader);
53 SkRect dstRect = fDstRect;
54 dstRect.offset(SkIntToScalar(localOffset.fX), SkIntToScalar(localOffset.fY)) ; 59 dstRect.offset(SkIntToScalar(localOffset.fX), SkIntToScalar(localOffset.fY)) ;
55 canvas.drawRect(dstRect, paint); 60 canvas.drawRect(dstRect, paint);
56 *dst = device->accessBitmap(false); 61 *dst = device->accessBitmap(false);
57 return true; 62 return true;
58 } 63 }
59 64
60 SkTileImageFilter::SkTileImageFilter(SkFlattenableReadBuffer& buffer) 65 SkTileImageFilter::SkTileImageFilter(SkFlattenableReadBuffer& buffer)
61 : INHERITED(1, buffer) { 66 : INHERITED(1, buffer) {
62 buffer.readRect(&fSrcRect); 67 buffer.readRect(&fSrcRect);
63 buffer.readRect(&fDstRect); 68 buffer.readRect(&fDstRect);
64 buffer.validate(buffer.isValid() && SkIsValidRect(fSrcRect) && SkIsValidRect (fDstRect)); 69 buffer.validate(buffer.isValid() && SkIsValidRect(fSrcRect) && SkIsValidRect (fDstRect));
65 } 70 }
66 71
67 void SkTileImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { 72 void SkTileImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
68 this->INHERITED::flatten(buffer); 73 this->INHERITED::flatten(buffer);
69 buffer.writeRect(fSrcRect); 74 buffer.writeRect(fSrcRect);
70 buffer.writeRect(fDstRect); 75 buffer.writeRect(fDstRect);
71 } 76 }
OLDNEW
« no previous file with comments | « src/effects/SkBitmapSource.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698