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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1418093006: Refactor SkBitmapRegionDecoderInterface for Android (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Pass in the allocator, decodeRegion() in a single call 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
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 "DMSrcSink.h" 8 #include "DMSrcSink.h"
9 #include "SamplePipeControllers.h" 9 #include "SamplePipeControllers.h"
10 #include "SkAndroidCodec.h" 10 #include "SkAndroidCodec.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 118 }
119 119
120 const uint32_t width = brd->width(); 120 const uint32_t width = brd->width();
121 const uint32_t height = brd->height(); 121 const uint32_t height = brd->height();
122 // Visually inspecting very small output images is not necessary. 122 // Visually inspecting very small output images is not necessary.
123 if ((width / fSampleSize <= 10 || height / fSampleSize <= 10) && 1 != fSampl eSize) { 123 if ((width / fSampleSize <= 10 || height / fSampleSize <= 10) && 1 != fSampl eSize) {
124 return Error::Nonfatal("Scaling very small images is uninteresting."); 124 return Error::Nonfatal("Scaling very small images is uninteresting.");
125 } 125 }
126 switch (fMode) { 126 switch (fMode) {
127 case kFullImage_Mode: { 127 case kFullImage_Mode: {
128 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(0, 0, width, height , fSampleSize, 128 SkBitmap bitmap;
129 colorType)); 129 if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(0, 0, wid th, height),
130 if (nullptr == bitmap.get() || colorType != bitmap->colorType()) { 130 fSampleSize, colorType, false)) {
131 // FIXME: Make this a fatal error.
scroggo 2015/10/27 18:53:55 Why is this not fatal, and what do you need to do
msarett 2015/10/27 19:06:16 I *think* the only thing that needs to be done is
scroggo 2015/10/27 19:23:37 I'm fine if that is left to a separate change, but
132 return Error::Nonfatal("Cannot decode region.\n");
133 }
134 if (colorType != bitmap.colorType()) {
131 return Error::Nonfatal("Cannot convert to color type.\n"); 135 return Error::Nonfatal("Cannot convert to color type.\n");
132 } 136 }
133 canvas->drawBitmap(*bitmap, 0, 0); 137 canvas->drawBitmap(bitmap, 0, 0);
134 return ""; 138 return "";
135 } 139 }
136 case kDivisor_Mode: { 140 case kDivisor_Mode: {
137 const uint32_t divisor = 2; 141 const uint32_t divisor = 2;
138 if (width < divisor || height < divisor) { 142 if (width < divisor || height < divisor) {
139 return Error::Nonfatal("Divisor is larger than image dimension.\ n"); 143 return Error::Nonfatal("Divisor is larger than image dimension.\ n");
140 } 144 }
141 145
142 // Use a border to test subsets that extend outside the image. 146 // Use a border to test subsets that extend outside the image.
143 // We will not allow the border to be larger than the image dimensio ns. Allowing 147 // We will not allow the border to be larger than the image dimensio ns. Allowing
(...skipping 27 matching lines...) Expand all
171 // Increase the size of the last subset in each row or colum n, when the 175 // Increase the size of the last subset in each row or colum n, when the
172 // divisor does not divide evenly into the image dimensions 176 // divisor does not divide evenly into the image dimensions
173 subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; 177 subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0;
174 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; 178 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0;
175 179
176 // Increase the size of the subset in order to have a border on each side 180 // Increase the size of the subset in order to have a border on each side
177 const int decodeLeft = left - unscaledBorder; 181 const int decodeLeft = left - unscaledBorder;
178 const int decodeTop = top - unscaledBorder; 182 const int decodeTop = top - unscaledBorder;
179 const uint32_t decodeWidth = subsetWidth + unscaledBorder * 2; 183 const uint32_t decodeWidth = subsetWidth + unscaledBorder * 2;
180 const uint32_t decodeHeight = subsetHeight + unscaledBorder * 2; 184 const uint32_t decodeHeight = subsetHeight + unscaledBorder * 2;
181 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(decodeLeft, 185 SkBitmap bitmap;
182 decodeTop, decodeWidth, decodeHeight, fSampleSize, c olorType)); 186 if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(d ecodeLeft,
183 if (nullptr == bitmap.get() || colorType != bitmap->colorTyp e()) { 187 decodeTop, decodeWidth, decodeHeight), fSampleSize, colorType, false)) {
188 // FIXME: Make this a fatal error.
189 return Error::Nonfatal("Cannot not decode region.\n");
190 }
191 if (colorType != bitmap.colorType()) {
184 return Error::Nonfatal("Cannot convert to color type.\n" ); 192 return Error::Nonfatal("Cannot convert to color type.\n" );
185 } 193 }
186 194
187 canvas->drawBitmapRect(*bitmap, 195 canvas->drawBitmapRect(bitmap,
188 SkRect::MakeXYWH((SkScalar) scaledBorder, (SkScalar) scaledBorder, 196 SkRect::MakeXYWH((SkScalar) scaledBorder, (SkScalar) scaledBorder,
189 (SkScalar) (subsetWidth / fSampleSize), 197 (SkScalar) (subsetWidth / fSampleSize),
190 (SkScalar) (subsetHeight / fSampleSize)), 198 (SkScalar) (subsetHeight / fSampleSize)),
191 SkRect::MakeXYWH((SkScalar) (left / fSampleSize), 199 SkRect::MakeXYWH((SkScalar) (left / fSampleSize),
192 (SkScalar) (top / fSampleSize), 200 (SkScalar) (top / fSampleSize),
193 (SkScalar) (subsetWidth / fSampleSize), 201 (SkScalar) (subsetWidth / fSampleSize),
194 (SkScalar) (subsetHeight / fSampleSize)), 202 (SkScalar) (subsetHeight / fSampleSize)),
195 nullptr); 203 nullptr);
196 } 204 }
197 } 205 }
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 skr.visit<void>(i, drawsAsSingletonPictures); 1376 skr.visit<void>(i, drawsAsSingletonPictures);
1369 } 1377 }
1370 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); 1378 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
1371 1379
1372 canvas->drawPicture(macroPic); 1380 canvas->drawPicture(macroPic);
1373 return ""; 1381 return "";
1374 }); 1382 });
1375 } 1383 }
1376 1384
1377 } // namespace DM 1385 } // namespace DM
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698