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

Side by Side Diff: tools/android/SkBitmapRegionCanvas.cpp

Issue 1420053010: Make BRD take advantage of zero initialized memory (Closed) Base URL: https://skia.googlesource.com/skia.git@zero-init
Patch Set: Reduce scope of local variable Created 5 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 | « tools/android/SkBitmapRegionCanvas.h ('k') | tools/android/SkBitmapRegionCodec.h » ('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 2015 Google Inc. 2 * Copyright 2015 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 "SkBitmapRegionCanvas.h" 8 #include "SkBitmapRegionCanvas.h"
9 #include "SkBitmapRegionDecoderPriv.h" 9 #include "SkBitmapRegionDecoderPriv.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkCodecPriv.h" 11 #include "SkCodecPriv.h"
12 12
13 SkBitmapRegionCanvas::SkBitmapRegionCanvas(SkCodec* decoder) 13 SkBitmapRegionCanvas::SkBitmapRegionCanvas(SkCodec* decoder)
14 : INHERITED(decoder->getInfo().width(), decoder->getInfo().height()) 14 : INHERITED(decoder->getInfo().width(), decoder->getInfo().height())
15 , fDecoder(decoder) 15 , fDecoder(decoder)
16 {} 16 {}
17 17
18 bool SkBitmapRegionCanvas::decodeRegion(SkBitmap* bitmap, SkBitmap::Allocator* a llocator, 18 bool SkBitmapRegionCanvas::decodeRegion(SkBitmap* bitmap, SkBRDAllocator* alloca tor,
19 const SkIRect& desiredSubset, int sampleSize, SkColorType dstColorType, 19 const SkIRect& desiredSubset, int sampleSize, SkColorType dstColorType,
20 bool requireUnpremul) { 20 bool requireUnpremul) {
21 // Reject color types not supported by this method 21 // Reject color types not supported by this method
22 if (kIndex_8_SkColorType == dstColorType || kGray_8_SkColorType == dstColorT ype) { 22 if (kIndex_8_SkColorType == dstColorType || kGray_8_SkColorType == dstColorT ype) {
23 SkCodecPrintf("Error: Color type not supported.\n"); 23 SkCodecPrintf("Error: Color type not supported.\n");
24 return false; 24 return false;
25 } 25 }
26 26
27 // Reject requests for unpremultiplied alpha 27 // Reject requests for unpremultiplied alpha
28 if (requireUnpremul) { 28 if (requireUnpremul) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 bitmap->setInfo(dstInfo, dstInfo.minRowBytes()); 95 bitmap->setInfo(dstInfo, dstInfo.minRowBytes());
96 if (!bitmap->tryAllocPixels(allocator, nullptr)) { 96 if (!bitmap->tryAllocPixels(allocator, nullptr)) {
97 SkCodecPrintf("Error: Could not allocate pixels.\n"); 97 SkCodecPrintf("Error: Could not allocate pixels.\n");
98 return false; 98 return false;
99 } 99 }
100 100
101 // Zero the bitmap if the region is not completely within the image. 101 // Zero the bitmap if the region is not completely within the image.
102 // TODO (msarett): Can we make this faster by implementing it to only 102 // TODO (msarett): Can we make this faster by implementing it to only
103 // zero parts of the image that we won't overwrite with 103 // zero parts of the image that we won't overwrite with
104 // pixels? 104 // pixels?
105 // TODO (msarett): This could be skipped if memory is zero initialized.
106 // This would matter if this code is moved to Android and
107 // uses Android bitmaps.
108 if (SubsetType::kPartiallyInside_SubsetType == type) { 105 if (SubsetType::kPartiallyInside_SubsetType == type) {
109 bitmap->eraseColor(0); 106 SkCodec::ZeroInitialized zeroInit = allocator ? allocator->zeroInit() :
107 SkCodec::kNo_ZeroInitialized;
108 if (SkCodec::kNo_ZeroInitialized == zeroInit) {
109 bitmap->eraseColor(0);
110 }
110 } 111 }
111 112
112 // Use a canvas to crop and scale to the destination bitmap 113 // Use a canvas to crop and scale to the destination bitmap
113 SkCanvas canvas(*bitmap); 114 SkCanvas canvas(*bitmap);
114 // TODO (msarett): Maybe we can take advantage of the fact that SkRect uses floats? 115 // TODO (msarett): Maybe we can take advantage of the fact that SkRect uses floats?
115 SkRect src = SkRect::MakeXYWH((SkScalar) subset.x(), (SkScalar) 0, 116 SkRect src = SkRect::MakeXYWH((SkScalar) subset.x(), (SkScalar) 0,
116 (SkScalar) subset.width(), (SkScalar) subset.height()); 117 (SkScalar) subset.width(), (SkScalar) subset.height());
117 SkRect dst = SkRect::MakeXYWH((SkScalar) (outX / sampleSize), (SkScalar) (ou tY / sampleSize), 118 SkRect dst = SkRect::MakeXYWH((SkScalar) (outX / sampleSize), (SkScalar) (ou tY / sampleSize),
118 (SkScalar) get_scaled_dimension(subset.width(), sampleSize), 119 (SkScalar) get_scaled_dimension(subset.width(), sampleSize),
119 (SkScalar) get_scaled_dimension(subset.height(), sampleSize)); 120 (SkScalar) get_scaled_dimension(subset.height(), sampleSize));
(...skipping 10 matching lines...) Expand all
130 // SkCanvas does not draw to these color types. 131 // SkCanvas does not draw to these color types.
131 if (kIndex_8_SkColorType == colorType || kGray_8_SkColorType == colorType) { 132 if (kIndex_8_SkColorType == colorType || kGray_8_SkColorType == colorType) {
132 return false; 133 return false;
133 } 134 }
134 135
135 // FIXME: Call virtual function when it lands. 136 // FIXME: Call virtual function when it lands.
136 SkImageInfo info = SkImageInfo::Make(0, 0, colorType, fDecoder->getInfo().al phaType(), 137 SkImageInfo info = SkImageInfo::Make(0, 0, colorType, fDecoder->getInfo().al phaType(),
137 fDecoder->getInfo().profileType()); 138 fDecoder->getInfo().profileType());
138 return conversion_possible(info, fDecoder->getInfo()); 139 return conversion_possible(info, fDecoder->getInfo());
139 } 140 }
OLDNEW
« no previous file with comments | « tools/android/SkBitmapRegionCanvas.h ('k') | tools/android/SkBitmapRegionCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698