remove SkBitmap::allocConfigPixels and update dox
I see no callers in android
R=scroggo@google.com
Author: reed@google.com
Review URL: https://codereview.chromium.org/310283004
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index b739714..6d3f619 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -151,7 +151,7 @@
};
struct ConfigData {
- SkBitmap::Config fConfig;
+ SkColorType fColorType;
Backend fBackend;
GLContextType fGLContextType; // GPU backend only
int fSampleCnt; // GPU backend only
@@ -477,7 +477,8 @@
*/
static void setup_bitmap(const ConfigData& gRec, SkISize& size,
SkBitmap* bitmap) {
- bitmap->allocConfigPixels(gRec.fConfig, size.width(), size.height());
+ bitmap->allocPixels(SkImageInfo::Make(size.width(), size.height(),
+ gRec.fColorType, kPremul_SkAlphaType));
bitmap->eraseColor(SK_ColorTRANSPARENT);
}
@@ -1287,39 +1288,36 @@
#endif
static const ConfigData gRec[] = {
- { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888", true },
-#if 0 // stop testing this (for now at least) since we want to remove support for it (soon please!!!)
- { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444", true },
-#endif
- { SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565", true },
+ { kN32_SkColorType, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888", true },
+ { kRGB_565_SkColorType, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565", true },
#if SK_SUPPORT_GPU
- { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu", true },
- { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16", false},
- { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 4, kRW_ConfigFlag, "msaa4", false},
- { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNVPR_GLContextType, 4, kRW_ConfigFlag, "nvprmsaa4", true },
- { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNVPR_GLContextType, 16, kRW_ConfigFlag, "nvprmsaa16", false},
+ { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu", true },
+ { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16", false},
+ { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNative_GLContextType, 4, kRW_ConfigFlag, "msaa4", false},
+ { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNVPR_GLContextType, 4, kRW_ConfigFlag, "nvprmsaa4", true },
+ { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNVPR_GLContextType, 16, kRW_ConfigFlag, "nvprmsaa16", false},
/* The gpudebug context does not generate meaningful images, so don't record
* the images it generates! We only run it to look for asserts. */
- { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "gpudebug", kDebugOnly},
+ { kN32_SkColorType, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "gpudebug", kDebugOnly},
/* The gpunull context does the least amount of work possible and doesn't
generate meaninful images, so don't record them!. It can be run to
isolate the CPU-side processing expense from the GPU-side.
*/
- { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNull_GLContextType, 0, kNone_ConfigFlag, "gpunull", kDebugOnly},
+ { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNull_GLContextType, 0, kNone_ConfigFlag, "gpunull", kDebugOnly},
#if SK_ANGLE
- { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle", true },
- { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16", true },
+ { kN32_SkColorType, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle", true },
+ { kN32_SkColorType, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16", true },
#endif // SK_ANGLE
#ifdef SK_MESA
- { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa", true },
+ { kN32_SkColorType, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa", true },
#endif // SK_MESA
#endif // SK_SUPPORT_GPU
#ifdef SK_SUPPORT_XPS
/* At present we have no way of comparing XPS files (either natively or by converting to PNG). */
- { SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps", true },
+ { kN32_SkColorType, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps", true },
#endif // SK_SUPPORT_XPS
#ifdef SK_SUPPORT_PDF
- { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "pdf", true },
+ { kN32_SkColorType, kPDF_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "pdf", true },
#endif // SK_SUPPORT_PDF
};
@@ -1740,7 +1738,7 @@
}
if ((gmFlags & GM::kSkip565_Flag) &&
(kRaster_Backend == config.fBackend) &&
- (SkBitmap::kRGB_565_Config == config.fConfig)) {
+ (kRGB_565_SkColorType == config.fColorType)) {
gmmain.RecordSkippedTest(shortNamePlusConfig,
renderModeDescriptor,
config.fBackend);
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index 35f0151..6de95be 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -27,7 +27,7 @@
/** \class SkBitmap
The SkBitmap class specifies a raster bitmap. A bitmap has an integer width
- and height, and a format (config), and a pointer to the actual pixels.
+ and height, and a format (colortype), and a pointer to the actual pixels.
Bitmaps can be drawn into a SkCanvas, but they are also used to specify the
target of a SkCanvas' drawing operations.
A const SkBitmap exposes getAddr(), which lets a caller write its pixels;
@@ -53,9 +53,15 @@
kConfigCount = kARGB_8888_Config + 1
};
+ /** Return the config for the bitmap. */
+ Config config() const;
+
+ SK_ATTR_DEPRECATED("use config()")
+ Config getConfig() const { return this->config(); }
+
/**
* Default construct creates a bitmap with zero width and height, and no pixels.
- * Its config is set to kNo_Config.
+ * Its colortype is set to kUnknown_SkColorType.
*/
SkBitmap();
@@ -101,24 +107,23 @@
}
#endif
- /** Return the number of bytes per pixel based on the config. If the config
- does not have at least 1 byte per (e.g. kA1_Config) then 0 is returned.
+ /**
+ * Return the number of bytes per pixel based on the colortype. If the colortype is
+ * kUnknown_SkColorType, then 0 is returned.
*/
int bytesPerPixel() const { return fInfo.bytesPerPixel(); }
- /** Return the rowbytes expressed as a number of pixels (like width and
- height). Note, for 1-byte per pixel configs like kA8_Config, this will
- return the same as rowBytes(). Is undefined for configs that are less
- than 1-byte per pixel (e.g. kA1_Config)
+ /**
+ * Return the rowbytes expressed as a number of pixels (like width and height).
+ * If the colortype is kUnknown_SkColorType, then 0 is returned.
*/
int rowBytesAsPixels() const {
return fRowBytes >> this->shiftPerPixel();
}
- /** Return the shift amount per pixel (i.e. 0 for 1-byte per pixel, 1 for
- 2-bytes per pixel configs, 2 for 4-bytes per pixel configs). Return 0
- for configs that are not at least 1-byte per pixel (e.g. kA1_Config
- or kNo_Config)
+ /**
+ * Return the shift amount per pixel (i.e. 0 for 1-byte per pixel, 1 for 2-bytes per pixel
+ * colortypes, 2 for 4-bytes per pixel colortypes). Return 0 for kUnknown_SkColorType.
*/
int shiftPerPixel() const { return this->bytesPerPixel() >> 1; }
@@ -139,19 +144,13 @@
*/
bool drawsNothing() const { return this->empty() || this->isNull(); }
- /** Return the config for the bitmap. */
- Config config() const;
-
- SK_ATTR_DEPRECATED("use config()")
- Config getConfig() const { return this->config(); }
-
/** Return the number of bytes between subsequent rows of the bitmap. */
size_t rowBytes() const { return fRowBytes; }
/**
* Set the bitmap's alphaType, returning true on success. If false is
* returned, then the specified new alphaType is incompatible with the
- * Config, and the current alphaType is unchanged.
+ * colortype, and the current alphaType is unchanged.
*
* Note: this changes the alphatype for the underlying pixels, which means
* that all bitmaps that might be sharing (subsets of) the pixels will
@@ -228,6 +227,7 @@
*/
void reset();
+#ifdef SK_SUPPORT_LEGACY_COMPUTE_CONFIG_SIZE
/** Given a config and a width, this computes the optimal rowBytes value. This is called automatically
if you pass 0 for rowBytes to setConfig().
*/
@@ -247,6 +247,7 @@
static int64_t ComputeSize64(Config, int width, int height);
static size_t ComputeSize(Config, int width, int height);
+#endif
/**
* This will brute-force return true if all of the pixels in the bitmap
@@ -302,12 +303,6 @@
return this->allocPixels(info, NULL, NULL);
}
- /**
- * Legacy helper function, which creates an SkImageInfo from the specified
- * config and then calls allocPixels(info).
- */
- bool allocConfigPixels(Config, int width, int height, bool isOpaque = false);
-
bool allocN32Pixels(int width, int height, bool isOpaque = false) {
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
if (isOpaque) {
@@ -384,7 +379,7 @@
bool preserveDstPad = false) const;
/** Use the standard HeapAllocator to create the pixelref that manages the
- pixel memory. It will be sized based on the current width/height/config.
+ pixel memory. It will be sized based on the current ImageInfo.
If this is called multiple times, a new pixelref object will be created
each time.
@@ -392,7 +387,7 @@
not null) it will take care of incrementing the reference count.
@param ctable ColorTable (or null) to use with the pixels that will
- be allocated. Only used if config == Index8_Config
+ be allocated. Only used if colortype == kIndex_8_SkColorType
@return true if the allocation succeeds. If not the pixelref field of
the bitmap will be unchanged.
*/
@@ -401,7 +396,7 @@
}
/** Use the specified Allocator to create the pixelref that manages the
- pixel memory. It will be sized based on the current width/height/config.
+ pixel memory. It will be sized based on the current ImageInfo.
If this is called multiple times, a new pixelref object will be created
each time.
@@ -409,12 +404,11 @@
not null) it will take care of incrementing the reference count.
@param allocator The Allocator to use to create a pixelref that can
- manage the pixel memory for the current
- width/height/config. If allocator is NULL, the standard
- HeapAllocator will be used.
+ manage the pixel memory for the current ImageInfo.
+ If allocator is NULL, the standard HeapAllocator will be used.
@param ctable ColorTable (or null) to use with the pixels that will
- be allocated. Only used if config == Index8_Config.
- If it is non-null and the config is not Index8, it will
+ be allocated. Only used if colortype == kIndex_8_SkColorType.
+ If it is non-null and the colortype is not indexed, it will
be ignored.
@return true if the allocation succeeds. If not the pixelref field of
the bitmap will be unchanged.
@@ -478,7 +472,7 @@
bool lockPixelsAreWritable() const;
/** Call this to be sure that the bitmap is valid enough to be drawn (i.e.
- it has non-null pixels, and if required by its config, it has a
+ it has non-null pixels, and if required by its colortype, it has a
non-null colortable. Returns true if all of the above are met.
*/
bool readyToDraw() const {
@@ -512,8 +506,8 @@
/**
* Fill the entire bitmap with the specified color.
- * If the bitmap's config does not support alpha (e.g. 565) then the alpha
- * of the color is ignored (treated as opaque). If the config only supports
+ * If the bitmap's colortype does not support alpha (e.g. 565) then the alpha
+ * of the color is ignored (treated as opaque). If the colortype only supports
* alpha (e.g. A1 or A8) then the color's r,g,b components are ignored.
*/
void eraseColor(SkColor c) const {
@@ -523,8 +517,8 @@
/**
* Fill the entire bitmap with the specified color.
- * If the bitmap's config does not support alpha (e.g. 565) then the alpha
- * of the color is ignored (treated as opaque). If the config only supports
+ * If the bitmap's colortype does not support alpha (e.g. 565) then the alpha
+ * of the color is ignored (treated as opaque). If the colortype only supports
* alpha (e.g. A1 or A8) then the color's r,g,b components are ignored.
*/
void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const;
@@ -536,8 +530,8 @@
/**
* Fill the specified area of this bitmap with the specified color.
- * If the bitmap's config does not support alpha (e.g. 565) then the alpha
- * of the color is ignored (treated as opaque). If the config only supports
+ * If the bitmap's colortype does not support alpha (e.g. 565) then the alpha
+ * of the color is ignored (treated as opaque). If the colortype only supports
* alpha (e.g. A1 or A8) then the color's r,g,b components are ignored.
*/
void eraseArea(const SkIRect& area, SkColor c) const;
@@ -556,9 +550,8 @@
was scrolled away. E.g. if dx = dy = 0, then inval would
be set to empty. If dx >= width or dy >= height, then
inval would be set to the entire bounds of the bitmap.
- @return true if the scroll was doable. Will return false if the bitmap
- uses an unsupported config for scrolling (only kA8,
- kIndex8, kRGB_565, kARGB_4444, kARGB_8888 are supported).
+ @return true if the scroll was doable. Will return false if the colortype is kUnkown or
+ if the bitmap is immutable.
If no pixels are present (i.e. getPixels() returns false)
inval will still be updated, and true will be returned.
*/
@@ -567,9 +560,9 @@
/**
* Return the SkColor of the specified pixel. In most cases this will
- * require un-premultiplying the color. Alpha only configs (A1 and A8)
+ * require un-premultiplying the color. Alpha only colortypes (e.g. kAlpha_8_SkColorType)
* return black with the appropriate alpha set. The value is undefined
- * for kNone_Config or if x or y are out of bounds, or if the bitmap
+ * for kUnknown_SkColorType or if x or y are out of bounds, or if the bitmap
* does not have any pixels (or has not be locked with lockPixels()).
*/
SkColor getColor(int x, int y) const;
@@ -587,21 +580,21 @@
/** Returns the address of the pixel specified by x,y for 32bit pixels.
* In debug build, this asserts that the pixels are allocated and locked,
- * and that the config is 32-bit, however none of these checks are performed
+ * and that the colortype is 32-bit, however none of these checks are performed
* in the release build.
*/
inline uint32_t* getAddr32(int x, int y) const;
/** Returns the address of the pixel specified by x,y for 16bit pixels.
* In debug build, this asserts that the pixels are allocated and locked,
- * and that the config is 16-bit, however none of these checks are performed
+ * and that the colortype is 16-bit, however none of these checks are performed
* in the release build.
*/
inline uint16_t* getAddr16(int x, int y) const;
/** Returns the address of the pixel specified by x,y for 8bit pixels.
* In debug build, this asserts that the pixels are allocated and locked,
- * and that the config is 8-bit, however none of these checks are performed
+ * and that the colortype is 8-bit, however none of these checks are performed
* in the release build.
*/
inline uint8_t* getAddr8(int x, int y) const;
@@ -609,16 +602,16 @@
/** Returns the color corresponding to the pixel specified by x,y for
* colortable based bitmaps.
* In debug build, this asserts that the pixels are allocated and locked,
- * that the config is kIndex8, and that the colortable is allocated,
+ * that the colortype is indexed, and that the colortable is allocated,
* however none of these checks are performed in the release build.
*/
inline SkPMColor getIndex8Color(int x, int y) const;
/** Set dst to be a setset of this bitmap. If possible, it will share the
- pixel memory, and just point into a subset of it. However, if the config
+ pixel memory, and just point into a subset of it. However, if the colortype
does not support this, a local copy will be made and associated with
the dst bitmap. If the subset rectangle, intersected with the bitmap's
- dimensions is empty, or if there is an unsupported config, false will be
+ dimensions is empty, or if there is an unsupported colortype, false will be
returned and dst will be untouched.
@param dst The bitmap that will be set to a subset of this bitmap
@param subset The rectangle of pixels in this bitmap that dst will
@@ -631,7 +624,7 @@
* and allocating the dst pixels on the cpu.
* Returns false if either there is an error (i.e. the src does not have
* pixels) or the request cannot be satisfied (e.g. the src has per-pixel
- * alpha, and the requested config does not support alpha).
+ * alpha, and the requested colortype does not support alpha).
* @param dst The bitmap to be sized and allocated
* @param ct The desired colorType for dst
* @param allocator Allocator used to allocate the pixelref for the dst
@@ -705,9 +698,9 @@
SK_DECLARE_INST_COUNT(Allocator)
/** Allocate the pixel memory for the bitmap, given its dimensions and
- config. Return true on success, where success means either setPixels
+ colortype. Return true on success, where success means either setPixels
or setPixelRef was called. The pixels need not be locked when this
- returns. If the config requires a colortable, it also must be
+ returns. If the colortype requires a colortable, it also must be
installed via setColorTable. If false is returned, the bitmap and
colortable should be left unchanged.
*/
@@ -778,17 +771,6 @@
void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const;
- /* Internal computations for safe size.
- */
- static int64_t ComputeSafeSize64(Config config,
- uint32_t width,
- uint32_t height,
- size_t rowBytes);
- static size_t ComputeSafeSize(Config config,
- uint32_t width,
- uint32_t height,
- size_t rowBytes);
-
/* Unreference any pixelrefs or colortables
*/
void freePixels();
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 07f6f17..799104b 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -95,6 +95,7 @@
return SkColorTypeToBitmapConfig(fInfo.colorType());
}
+#ifdef SK_SUPPORT_LEGACY_COMPUTE_CONFIG_SIZE
int SkBitmap::ComputeBytesPerPixel(SkBitmap::Config config) {
int bpp;
switch (config) {
@@ -134,29 +135,7 @@
int64_t size = SkBitmap::ComputeSize64(c, width, height);
return sk_64_isS32(size) ? sk_64_asS32(size) : 0;
}
-
-int64_t SkBitmap::ComputeSafeSize64(Config config,
- uint32_t width,
- uint32_t height,
- size_t rowBytes) {
- SkImageInfo info = SkImageInfo::Make(width, height,
- SkBitmapConfigToColorType(config),
- kPremul_SkAlphaType);
- return info.getSafeSize64(rowBytes);
-}
-
-size_t SkBitmap::ComputeSafeSize(Config config,
- uint32_t width,
- uint32_t height,
- size_t rowBytes) {
- int64_t safeSize = ComputeSafeSize64(config, width, height, rowBytes);
- int32_t safeSize32 = (int32_t)safeSize;
-
- if (safeSize32 != safeSize) {
- safeSize32 = 0;
- }
- return safeSize32;
-}
+#endif
void SkBitmap::getBounds(SkRect* bounds) const {
SkASSERT(bounds);
@@ -278,34 +257,6 @@
}
}
-static bool config_to_colorType(SkBitmap::Config config, SkColorType* ctOut) {
- SkColorType ct;
- switch (config) {
- case SkBitmap::kA8_Config:
- ct = kAlpha_8_SkColorType;
- break;
- case SkBitmap::kIndex8_Config:
- ct = kIndex_8_SkColorType;
- break;
- case SkBitmap::kRGB_565_Config:
- ct = kRGB_565_SkColorType;
- break;
- case SkBitmap::kARGB_4444_Config:
- ct = kARGB_4444_SkColorType;
- break;
- case SkBitmap::kARGB_8888_Config:
- ct = kN32_SkColorType;
- break;
- case SkBitmap::kNo_Config:
- default:
- return false;
- }
- if (ctOut) {
- *ctOut = ct;
- }
- return true;
-}
-
SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, int dx, int dy) {
#ifdef SK_DEBUG
if (pr) {
@@ -472,17 +423,6 @@
mask.fImage, mask.fRowBytes);
}
-bool SkBitmap::allocConfigPixels(Config config, int width, int height,
- bool isOpaque) {
- SkColorType ct;
- if (!config_to_colorType(config, &ct)) {
- return false;
- }
-
- SkAlphaType at = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
- return this->allocPixels(SkImageInfo::Make(width, height, ct, at));
-}
-
///////////////////////////////////////////////////////////////////////////////
void SkBitmap::freePixels() {