skia2/tools/SkBitmapRegionDecoderInterface.cpp
msarett a5783aeff0 Provides various implementations of Android's SkBitmapRegionDecoder.
Implements testing in DM for these implementations.

nanobench testing will follow after this.

TBR=scroggo
BUG=skia:

Committed: https://skia.googlesource.com/skia/+/76f755e6d54a32f9887ad254ce59a3a62f28bde4

Review URL: https://codereview.chromium.org/1288963002
2015-09-08 15:35:32 -07:00

52 lines
1.8 KiB
C++

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBitmapRegionCanvas.h"
#include "SkBitmapRegionDecoderInterface.h"
#include "SkBitmapRegionSampler.h"
#include "SkScanlineDecoder.h"
#include "SkImageDecoder.h"
SkBitmapRegionDecoderInterface* SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(
SkStreamRewindable* stream, Strategy strategy) {
switch (strategy) {
case kOriginal_Strategy: {
SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
int width, height;
if (nullptr == decoder) {
SkDebugf("Error: Could not create image decoder.\n");
return nullptr;
}
if (!decoder->buildTileIndex(stream, &width, &height)) {
SkDebugf("Error: Could not build tile index.\n");
delete decoder;
return nullptr;
}
return new SkBitmapRegionSampler(decoder, width, height);
}
case kCanvas_Strategy: {
SkScanlineDecoder* decoder = SkScanlineDecoder::NewFromStream(stream);
if (nullptr == decoder) {
SkDebugf("Error: Failed to create decoder.\n");
return nullptr;
}
switch (decoder->getScanlineOrder()) {
case SkScanlineDecoder::kTopDown_SkScanlineOrder:
case SkScanlineDecoder::kNone_SkScanlineOrder:
break;
default:
SkDebugf("Error: Scanline ordering not supported.\n");
return nullptr;
}
return new SkBitmapRegionCanvas(decoder);
}
default:
SkASSERT(false);
return nullptr;
}
}