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

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

Issue 742663002: add roundOut that returns its result (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « src/core/SkScan_Hairline.cpp ('k') | src/effects/SkBlurMaskFilter.cpp » ('j') | 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 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" 9 #include "SkDevice.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 SkBitmap* result, SkIPoint* offset) const { 60 SkBitmap* result, SkIPoint* offset) const {
61 SkRect bounds, dstRect; 61 SkRect bounds, dstRect;
62 fBitmap.getBounds(&bounds); 62 fBitmap.getBounds(&bounds);
63 ctx.ctm().mapRect(&dstRect, fDstRect); 63 ctx.ctm().mapRect(&dstRect, fDstRect);
64 if (fSrcRect == bounds && dstRect == bounds) { 64 if (fSrcRect == bounds && dstRect == bounds) {
65 // No regions cropped out or resized; return entire bitmap. 65 // No regions cropped out or resized; return entire bitmap.
66 *result = fBitmap; 66 *result = fBitmap;
67 offset->fX = offset->fY = 0; 67 offset->fX = offset->fY = 0;
68 return true; 68 return true;
69 } 69 }
70 SkIRect dstIRect;
71 dstRect.roundOut(&dstIRect);
72 70
71 const SkIRect dstIRect = dstRect.roundOut();
73 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstIRect.width(), dstI Rect.height())); 72 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstIRect.width(), dstI Rect.height()));
74 if (NULL == device.get()) { 73 if (NULL == device.get()) {
75 return false; 74 return false;
76 } 75 }
77 76
78 SkCanvas canvas(device.get()); 77 SkCanvas canvas(device.get());
79 SkPaint paint; 78 SkPaint paint;
80 79
81 // Subtract off the integer component of the translation (will be applied in loc, below). 80 // Subtract off the integer component of the translation (will be applied in loc, below).
82 dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop) ); 81 dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop) );
83 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 82 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
84 // FIXME: this probably shouldn't be necessary, but drawBitmapRectToRect ass erts 83 // FIXME: this probably shouldn't be necessary, but drawBitmapRectToRect ass erts
85 // None filtering when it's translate-only 84 // None filtering when it's translate-only
86 paint.setFilterLevel( 85 paint.setFilterLevel(
87 fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.heig ht() ? 86 fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.heig ht() ?
88 SkPaint::kNone_FilterLevel : SkPaint::kHigh_FilterLevel); 87 SkPaint::kNone_FilterLevel : SkPaint::kHigh_FilterLevel);
89 canvas.drawBitmapRectToRect(fBitmap, &fSrcRect, dstRect, &paint); 88 canvas.drawBitmapRectToRect(fBitmap, &fSrcRect, dstRect, &paint);
90 89
91 *result = device.get()->accessBitmap(false); 90 *result = device.get()->accessBitmap(false);
92 offset->fX = dstIRect.fLeft; 91 offset->fX = dstIRect.fLeft;
93 offset->fY = dstIRect.fTop; 92 offset->fY = dstIRect.fTop;
94 return true; 93 return true;
95 } 94 }
96 95
97 void SkBitmapSource::computeFastBounds(const SkRect&, SkRect* dst) const { 96 void SkBitmapSource::computeFastBounds(const SkRect&, SkRect* dst) const {
98 *dst = fDstRect; 97 *dst = fDstRect;
99 } 98 }
OLDNEW
« no previous file with comments | « src/core/SkScan_Hairline.cpp ('k') | src/effects/SkBlurMaskFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698