зеркало из https://github.com/mozilla/moz-skia.git
use SkImageInfo directly, instead of converting to SkBitmap::Config
BUG= R=scroggo@google.com Review URL: https://codereview.chromium.org/128933004 git-svn-id: http://skia.googlecode.com/svn/trunk@12972 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
e48ef2ae51
Коммит
1360c52b10
|
@ -153,6 +153,7 @@ public:
|
|||
|
||||
protected:
|
||||
SkSurface(int width, int height);
|
||||
SkSurface(const SkImageInfo&);
|
||||
|
||||
// called by subclass if their contents have changed
|
||||
void dirtyGenerationID() {
|
||||
|
|
|
@ -16,6 +16,11 @@ SkSurface_Base::SkSurface_Base(int width, int height) : INHERITED(width, height)
|
|||
fCachedImage = NULL;
|
||||
}
|
||||
|
||||
SkSurface_Base::SkSurface_Base(const SkImageInfo& info) : INHERITED(info) {
|
||||
fCachedCanvas = NULL;
|
||||
fCachedImage = NULL;
|
||||
}
|
||||
|
||||
SkSurface_Base::~SkSurface_Base() {
|
||||
// in case the canvas outsurvives us, we null the callback
|
||||
if (fCachedCanvas) {
|
||||
|
@ -73,8 +78,17 @@ static SkSurface_Base* asSB(SkSurface* surface) {
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkSurface::SkSurface(int width, int height) : fWidth(width), fHeight(height) {
|
||||
SkASSERT(width >= 0);
|
||||
SkASSERT(height >= 0);
|
||||
SkASSERT(fWidth >= 0);
|
||||
SkASSERT(fHeight >= 0);
|
||||
fGenerationID = 0;
|
||||
}
|
||||
|
||||
SkSurface::SkSurface(const SkImageInfo& info)
|
||||
: fWidth(info.fWidth)
|
||||
, fHeight(info.fHeight)
|
||||
{
|
||||
SkASSERT(fWidth >= 0);
|
||||
SkASSERT(fHeight >= 0);
|
||||
fGenerationID = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
class SkSurface_Base : public SkSurface {
|
||||
public:
|
||||
SkSurface_Base(int width, int height);
|
||||
explicit SkSurface_Base(const SkImageInfo&);
|
||||
virtual ~SkSurface_Base();
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
static bool Valid(const SkImageInfo&, size_t rb = kIgnoreRowBytesValue);
|
||||
|
||||
SkSurface_Raster(const SkImageInfo&, void*, size_t rb);
|
||||
SkSurface_Raster(const SkImageInfo&, SkPixelRef*, size_t rb);
|
||||
SkSurface_Raster(SkPixelRef*);
|
||||
|
||||
virtual SkCanvas* onNewCanvas() SK_OVERRIDE;
|
||||
virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE;
|
||||
|
@ -39,25 +39,21 @@ private:
|
|||
bool SkSurface_Raster::Valid(const SkImageInfo& info, size_t rowBytes) {
|
||||
static const size_t kMaxTotalSize = SK_MaxS32;
|
||||
|
||||
SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
|
||||
|
||||
int shift = 0;
|
||||
switch (config) {
|
||||
case SkBitmap::kA8_Config:
|
||||
switch (info.fColorType) {
|
||||
case kAlpha_8_SkColorType:
|
||||
shift = 0;
|
||||
break;
|
||||
case SkBitmap::kRGB_565_Config:
|
||||
case kRGB_565_SkColorType:
|
||||
shift = 1;
|
||||
break;
|
||||
case SkBitmap::kARGB_8888_Config:
|
||||
case kPMColor_SkColorType:
|
||||
shift = 2;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: examine colorspace
|
||||
|
||||
if (kIgnoreRowBytesValue == rowBytes) {
|
||||
return true;
|
||||
}
|
||||
|
@ -72,7 +68,7 @@ bool SkSurface_Raster::Valid(const SkImageInfo& info, size_t rowBytes) {
|
|||
return false;
|
||||
}
|
||||
|
||||
uint64_t size = (uint64_t)info.fHeight * rowBytes;
|
||||
uint64_t size = sk_64_mul(info.fHeight, rowBytes);
|
||||
if (size > kMaxTotalSize) {
|
||||
return false;
|
||||
}
|
||||
|
@ -81,21 +77,23 @@ bool SkSurface_Raster::Valid(const SkImageInfo& info, size_t rowBytes) {
|
|||
}
|
||||
|
||||
SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, void* pixels, size_t rb)
|
||||
: INHERITED(info.fWidth, info.fHeight) {
|
||||
SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
|
||||
fBitmap.setConfig(config, info.fWidth, info.fHeight, rb, info.fAlphaType);
|
||||
: INHERITED(info)
|
||||
{
|
||||
fBitmap.setConfig(info, rb);
|
||||
fBitmap.setPixels(pixels);
|
||||
fWeOwnThePixels = false; // We are "Direct"
|
||||
}
|
||||
|
||||
SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, SkPixelRef* pr, size_t rb)
|
||||
: INHERITED(info.fWidth, info.fHeight) {
|
||||
SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
|
||||
fBitmap.setConfig(config, info.fWidth, info.fHeight, rb, info.fAlphaType);
|
||||
SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr)
|
||||
: INHERITED(pr->info().fWidth, pr->info().fHeight)
|
||||
{
|
||||
const SkImageInfo& info = pr->info();
|
||||
|
||||
fBitmap.setConfig(info, info.minRowBytes());
|
||||
fBitmap.setPixelRef(pr);
|
||||
fWeOwnThePixels = true;
|
||||
|
||||
if (!SkAlphaTypeIsOpaque(info.fAlphaType)) {
|
||||
if (!info.isOpaque()) {
|
||||
fBitmap.eraseColor(SK_ColorTRANSPARENT);
|
||||
}
|
||||
}
|
||||
|
@ -159,5 +157,5 @@ SkSurface* SkSurface::NewRaster(const SkImageInfo& info) {
|
|||
if (NULL == pr.get()) {
|
||||
return NULL;
|
||||
}
|
||||
return SkNEW_ARGS(SkSurface_Raster, (info, pr, info.minRowBytes()));
|
||||
return SkNEW_ARGS(SkSurface_Raster, (pr));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче