};
struct ConfigData {
- SkBitmap::Config fConfig;
+ SkColorType fColorType;
Backend fBackend;
GLContextType fGLContextType; // GPU backend only
int fSampleCnt; // GPU backend only
*/
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);
}
#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
};
}
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);
/** \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;
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();
}
#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; }
*/
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
*/
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().
*/
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
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) {
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.
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.
*/
}
/** 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.
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.
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 {
/**
* 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 {
/**
* 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;
/**
* 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;
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.
*/
/**
* 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;
/** 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;
/** 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
* 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
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.
*/
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();