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

Side by Side Diff: src/effects/SkBitmapSource.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 SkTileImageFilter to respect CTM, and not to request an invalid subset 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
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The Android Open Source Project 2 * Copyright 2012 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 "SkBitmapSource.h" 8 #include "SkBitmapSource.h"
9 #include "SkDevice.h"
10 #include "SkCanvas.h"
11 #include "SkFlattenableBuffers.h"
12 #include "SkValidationUtils.h"
9 13
10 SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap) 14 SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap)
11 : INHERITED(0, 0), 15 : INHERITED(0, 0),
12 fBitmap(bitmap) { 16 fBitmap(bitmap),
17 fSrcRect(SkRect::MakeWH(SkIntToScalar(bitmap.width()),
18 SkIntToScalar(bitmap.height()))),
19 fDstRect(fSrcRect) {
20 }
21
22 SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap, const SkRect& srcRect, co nst SkRect& dstRect)
23 : INHERITED(0, 0),
24 fBitmap(bitmap),
25 fSrcRect(srcRect),
26 fDstRect(dstRect) {
13 } 27 }
14 28
15 SkBitmapSource::SkBitmapSource(SkFlattenableReadBuffer& buffer) 29 SkBitmapSource::SkBitmapSource(SkFlattenableReadBuffer& buffer)
16 : INHERITED(0, buffer) { 30 : INHERITED(0, buffer) {
17 fBitmap.unflatten(buffer); 31 fBitmap.unflatten(buffer);
32 buffer.readRect(&fSrcRect);
33 buffer.readRect(&fDstRect);
34 buffer.validate(SkIsValidRect(fSrcRect) && SkIsValidRect(fDstRect));
18 } 35 }
19 36
20 void SkBitmapSource::flatten(SkFlattenableWriteBuffer& buffer) const { 37 void SkBitmapSource::flatten(SkFlattenableWriteBuffer& buffer) const {
21 this->INHERITED::flatten(buffer); 38 this->INHERITED::flatten(buffer);
22 fBitmap.flatten(buffer); 39 fBitmap.flatten(buffer);
40 buffer.writeRect(fSrcRect);
41 buffer.writeRect(fDstRect);
23 } 42 }
24 43
25 bool SkBitmapSource::onFilterImage(Proxy*, const SkBitmap&, const SkMatrix&, 44 bool SkBitmapSource::onFilterImage(Proxy* proxy, const SkBitmap&, const SkMatrix & matrix,
26 SkBitmap* result, SkIPoint* offset) { 45 SkBitmap* result, SkIPoint* offset) {
27 *result = fBitmap; 46 SkRect bounds, dstRect;
47 fBitmap.getBounds(&bounds);
48 matrix.mapRect(&dstRect, fDstRect);
49 if (fSrcRect == bounds && dstRect == bounds) {
robertphillips 2013/12/09 16:23:01 // no portion cropped out
Stephen White 2013/12/09 17:04:25 Done.
50 *result = fBitmap;
51 return true;
52 }
53 SkIRect dstIRect;
54 dstRect.roundOut(&dstIRect);
55
56 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstIRect.width(), dstI Rect.height()));
57 if (NULL == device.get()) {
58 return false;
59 }
60
61 SkCanvas canvas(device.get());
62 SkPaint paint;
63
64 // Subtract off the integer component of the translation (will be applied in loc, below).
65 dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop) );
66 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
67 // FIXME: this probably shouldn't be necessary, but drawBitmapRectToRect ass erts
68 // None filtering when it's translate-only
robertphillips 2013/12/09 16:23:01 \n somewhere?
Stephen White 2013/12/09 17:04:25 Done.
69 paint.setFilterLevel(fSrcRect.width() == dstRect.width() && fSrcRect.height( ) == dstRect.height() ? SkPaint::kNone_FilterLevel : SkPaint::kMedium_FilterLeve l);
70 canvas.drawBitmapRectToRect(fBitmap, &fSrcRect, dstRect, &paint);
71
72 *result = device.get()->accessBitmap(false);
73 offset->fX += dstIRect.fLeft;
74 offset->fY += dstIRect.fTop;
28 return true; 75 return true;
29 } 76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698