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

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: 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, const SkRect* srcRect, co nst SkRect* dstRect)
11 : INHERITED(0, 0), 15 : INHERITED(0, 0),
12 fBitmap(bitmap) { 16 fBitmap(bitmap),
17 fSrcRect(srcRect ? *srcRect : SkRect::MakeWH(bitmap.width(), bitmap.height() )),
18 fDstRect(dstRect ? *dstRect : fSrcRect) {
13 } 19 }
14 20
15 SkBitmapSource::SkBitmapSource(SkFlattenableReadBuffer& buffer) 21 SkBitmapSource::SkBitmapSource(SkFlattenableReadBuffer& buffer)
16 : INHERITED(0, buffer) { 22 : INHERITED(0, buffer) {
17 fBitmap.unflatten(buffer); 23 fBitmap.unflatten(buffer);
24 buffer.readRect(&fSrcRect);
25 buffer.readRect(&fDstRect);
26 buffer.validate(SkIsValidRect(fSrcRect) && SkIsValidRect(fDstRect));
18 } 27 }
19 28
20 void SkBitmapSource::flatten(SkFlattenableWriteBuffer& buffer) const { 29 void SkBitmapSource::flatten(SkFlattenableWriteBuffer& buffer) const {
21 this->INHERITED::flatten(buffer); 30 this->INHERITED::flatten(buffer);
22 fBitmap.flatten(buffer); 31 fBitmap.flatten(buffer);
32 buffer.writeRect(fSrcRect);
33 buffer.writeRect(fDstRect);
23 } 34 }
24 35
25 bool SkBitmapSource::onFilterImage(Proxy*, const SkBitmap&, const SkMatrix&, 36 bool SkBitmapSource::onFilterImage(Proxy* proxy, const SkBitmap&, const SkMatrix & matrix,
26 SkBitmap* result, SkIPoint* offset) { 37 SkBitmap* result, SkIPoint* offset) {
27 *result = fBitmap; 38 SkRect bounds, dstRect;
39 fBitmap.getBounds(&bounds);
40 matrix.mapRect(&dstRect, fDstRect);
41 if (fSrcRect == bounds && dstRect == bounds) {
42 *result = fBitmap;
43 return true;
44 }
45 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(SkScalarCeilToInt(dstR ect.width()), SkScalarCeilToInt(dstRect.height())));
46 if (NULL == device.get()) {
47 return false;
48 }
49
50 SkCanvas canvas(device.get());
51 SkPaint paint;
52
53 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
54 // FIXME: this probably shouldn't be necessary, but drawBitmapRectToRect ass erts None filtering when it's translate-only
55 paint.setFilterLevel(fSrcRect.width() == dstRect.width() && fSrcRect.height( ) == dstRect.height() ? SkPaint::kNone_FilterLevel : SkPaint::kMedium_FilterLeve l);
56 canvas.drawBitmapRectToRect(fBitmap, &fSrcRect, SkRect::MakeWH(dstRect.width (), dstRect.height()), &paint);
57
58 *result = device.get()->accessBitmap(false);
59 offset->fX += dstRect.fLeft;
60 offset->fY += dstRect.fTop;
28 return true; 61 return true;
29 } 62 }
OLDNEW
« include/effects/SkBitmapSource.h ('K') | « include/effects/SkBitmapSource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698