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

Side by Side Diff: src/codec/SkIcoCodec.cpp

Issue 2044573002: Revert of Make SkPngCodec decode progressively. (Closed) Base URL: https://skia.googlesource.com/skia.git@foil
Patch Set: Rebase Created 4 years, 6 months 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/codec/SkIcoCodec.h ('k') | src/codec/SkPngCodec.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 "SkBmpCodec.h" 8 #include "SkBmpCodec.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 179
180 /* 180 /*
181 * Creates an instance of the decoder 181 * Creates an instance of the decoder
182 * Called only by NewFromStream 182 * Called only by NewFromStream
183 */ 183 */
184 SkIcoCodec::SkIcoCodec(int width, int height, const SkEncodedInfo& info, 184 SkIcoCodec::SkIcoCodec(int width, int height, const SkEncodedInfo& info,
185 SkTArray<SkAutoTDelete<SkCodec>, true>* codecs) 185 SkTArray<SkAutoTDelete<SkCodec>, true>* codecs)
186 : INHERITED(width, height, info, nullptr) 186 : INHERITED(width, height, info, nullptr)
187 , fEmbeddedCodecs(codecs) 187 , fEmbeddedCodecs(codecs)
188 , fCurrScanlineCodec(nullptr) 188 , fCurrScanlineCodec(nullptr)
189 , fCurrIncrementalCodec(nullptr)
190 {} 189 {}
191 190
192 /* 191 /*
193 * Chooses the best dimensions given the desired scale 192 * Chooses the best dimensions given the desired scale
194 */ 193 */
195 SkISize SkIcoCodec::onGetScaledDimensions(float desiredScale) const { 194 SkISize SkIcoCodec::onGetScaledDimensions(float desiredScale) const {
196 // We set the dimensions to the largest candidate image by default. 195 // We set the dimensions to the largest candidate image by default.
197 // Regardless of the scale request, this is the largest image that we 196 // Regardless of the scale request, this is the largest image that we
198 // will decode. 197 // will decode.
199 int origWidth = this->getInfo().width(); 198 int origWidth = this->getInfo().width();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 while (true) { 282 while (true) {
284 index = this->chooseCodec(dstInfo.dimensions(), index); 283 index = this->chooseCodec(dstInfo.dimensions(), index);
285 if (index < 0) { 284 if (index < 0) {
286 break; 285 break;
287 } 286 }
288 287
289 SkCodec* embeddedCodec = fEmbeddedCodecs->operator[](index); 288 SkCodec* embeddedCodec = fEmbeddedCodecs->operator[](index);
290 result = embeddedCodec->startScanlineDecode(dstInfo, &options, colorTabl e, colorCount); 289 result = embeddedCodec->startScanlineDecode(dstInfo, &options, colorTabl e, colorCount);
291 if (kSuccess == result) { 290 if (kSuccess == result) {
292 fCurrScanlineCodec = embeddedCodec; 291 fCurrScanlineCodec = embeddedCodec;
293 fCurrIncrementalCodec = nullptr;
294 return result; 292 return result;
295 } 293 }
296 294
297 index++; 295 index++;
298 } 296 }
299 297
300 SkCodecPrintf("Error: No matching candidate image in ico.\n"); 298 SkCodecPrintf("Error: No matching candidate image in ico.\n");
301 return result; 299 return result;
302 } 300 }
303 301
304 int SkIcoCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { 302 int SkIcoCodec::onGetScanlines(void* dst, int count, size_t rowBytes) {
305 SkASSERT(fCurrScanlineCodec); 303 SkASSERT(fCurrScanlineCodec);
306 return fCurrScanlineCodec->getScanlines(dst, count, rowBytes); 304 return fCurrScanlineCodec->getScanlines(dst, count, rowBytes);
307 } 305 }
308 306
309 bool SkIcoCodec::onSkipScanlines(int count) { 307 bool SkIcoCodec::onSkipScanlines(int count) {
310 SkASSERT(fCurrScanlineCodec); 308 SkASSERT(fCurrScanlineCodec);
311 return fCurrScanlineCodec->skipScanlines(count); 309 return fCurrScanlineCodec->skipScanlines(count);
312 } 310 }
313 311
314 SkCodec::Result SkIcoCodec::onStartIncrementalDecode(const SkImageInfo& dstInfo,
315 void* pixels, size_t rowBytes, const SkCodec::Options& options,
316 SkPMColor* colorTable, int* colorCount) {
317 int index = 0;
318 while (true) {
319 index = this->chooseCodec(dstInfo.dimensions(), index);
320 if (index < 0) {
321 break;
322 }
323
324 SkCodec* embeddedCodec = fEmbeddedCodecs->operator[](index);
325 switch (embeddedCodec->startIncrementalDecode(dstInfo,
326 pixels, rowBytes, &options, colorTable, colorCount)) {
327 case kSuccess:
328 fCurrIncrementalCodec = embeddedCodec;
329 fCurrScanlineCodec = nullptr;
330 return kSuccess;
331 case kUnimplemented:
332 // FIXME: embeddedCodec is a BMP. If scanline decoding would wor k,
333 // return kUnimplemented so that SkSampledCodec will fall throug h
334 // to use the scanline decoder.
335 // Note that calling startScanlineDecode will require an extra
336 // rewind. The embedded codec has an SkMemoryStream, which is
337 // cheap to rewind, though it will do extra work re-reading the
338 // header.
339 // Also note that we pass nullptr for Options. This is because
340 // Options that are valid for incremental decoding may not be
341 // valid for scanline decoding.
342 // Once BMP supports incremental decoding this workaround can go
343 // away.
344 if (embeddedCodec->startScanlineDecode(dstInfo, nullptr,
345 colorTable, colorCount) == kSuccess) {
346 return kUnimplemented;
347 }
348 // Move on to the next embedded codec.
349 break;
350 default:
351 break;
352 }
353
354 index++;
355 }
356
357 SkCodecPrintf("Error: No matching candidate image in ico.\n");
358 return kInvalidScale;
359 }
360
361 SkCodec::Result SkIcoCodec::onIncrementalDecode(int* rowsDecoded) {
362 SkASSERT(fCurrIncrementalCodec);
363 return fCurrIncrementalCodec->incrementalDecode(rowsDecoded);
364 }
365
366 SkCodec::SkScanlineOrder SkIcoCodec::onGetScanlineOrder() const { 312 SkCodec::SkScanlineOrder SkIcoCodec::onGetScanlineOrder() const {
367 // FIXME: This function will possibly return the wrong value if it is called 313 // FIXME: This function will possibly return the wrong value if it is called
368 // before startScanlineDecode()/startIncrementalDecode(). 314 // before startScanlineDecode().
369 if (fCurrScanlineCodec) { 315 return fCurrScanlineCodec ? fCurrScanlineCodec->getScanlineOrder() :
370 SkASSERT(!fCurrIncrementalCodec); 316 INHERITED::onGetScanlineOrder();
371 return fCurrScanlineCodec->getScanlineOrder();
372 }
373
374 if (fCurrIncrementalCodec) {
375 return fCurrIncrementalCodec->getScanlineOrder();
376 }
377
378 return INHERITED::onGetScanlineOrder();
379 } 317 }
380 318
381 SkSampler* SkIcoCodec::getSampler(bool createIfNecessary) { 319 SkSampler* SkIcoCodec::getSampler(bool createIfNecessary) {
382 if (fCurrScanlineCodec) { 320 return fCurrScanlineCodec ? fCurrScanlineCodec->getSampler(createIfNecessary ) : nullptr;
383 SkASSERT(!fCurrIncrementalCodec);
384 return fCurrScanlineCodec->getSampler(createIfNecessary);
385 }
386
387 if (fCurrIncrementalCodec) {
388 return fCurrIncrementalCodec->getSampler(createIfNecessary);
389 }
390
391 return nullptr;
392 } 321 }
OLDNEW
« no previous file with comments | « src/codec/SkIcoCodec.h ('k') | src/codec/SkPngCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698