return pr;
}
- /**
- * Implements readPixels API. The caller will ensure that:
- * 1. bitmap has pixel config kARGB_8888_Config.
- * 2. bitmap has pixels.
- * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is
- * contained in the device bounds.
- */
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
- virtual bool onReadPixels(const SkBitmap&, int x, int y, SkCanvas::Config8888) SK_OVERRIDE;
-#endif
virtual bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y) SK_OVERRIDE;
virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) SK_OVERRIDE;
virtual void* onAccessPixels(SkImageInfo* info, size_t* rowBytes) SK_OVERRIDE;
#include "SkRegion.h"
#include "SkXfermode.h"
-//#define SK_SUPPORT_LEGACY_READPIXELSCONFIG
-
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
- #ifndef SK_SUPPORT_LEGACY_CONFIG8888
- #define SK_SUPPORT_LEGACY_CONFIG8888
- #endif
-#endif
-
// if not defined, we always assume ClipToLayer for saveLayer()
//#define SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
*/
const void* peekPixels(SkImageInfo* info, size_t* rowBytes);
-#ifdef SK_SUPPORT_LEGACY_CONFIG8888
- /**
- * This enum can be used with read/writePixels to perform a pixel ops to or
- * from an 8888 config other than Skia's native config (SkPMColor). There
- * are three byte orders supported: native, BGRA, and RGBA. Each has a
- * premultiplied and unpremultiplied variant.
- *
- * Components of a 8888 pixel can be packed/unpacked from a 32bit word using
- * either byte offsets or shift values. Byte offsets are endian-invariant
- * while shifts are not. BGRA and RGBA configs are defined by byte
- * orderings. The native config is defined by shift values (SK_A32_SHIFT,
- * ..., SK_B32_SHIFT).
- */
- enum Config8888 {
- /**
- * Skia's native order specified by:
- * SK_A32_SHIFT, SK_R32_SHIFT, SK_G32_SHIFT, and SK_B32_SHIFT
- *
- * kNative_Premul_Config8888 is equivalent to SkPMColor
- * kNative_Unpremul_Config8888 has the same component order as SkPMColor
- * but is not premultiplied.
- */
- kNative_Premul_Config8888,
- kNative_Unpremul_Config8888,
- /**
- * low byte to high byte: B, G, R, A.
- */
- kBGRA_Premul_Config8888,
- kBGRA_Unpremul_Config8888,
- /**
- * low byte to high byte: R, G, B, A.
- */
- kRGBA_Premul_Config8888,
- kRGBA_Unpremul_Config8888
- };
-#endif
-
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
- /**
- * On success (returns true), copy the canvas pixels into the bitmap.
- * On failure, the bitmap parameter is left unchanged and false is
- * returned.
- *
- * The canvas' pixels are converted to the bitmap's config. The only
- * supported config is kARGB_8888_Config, though this is likely to be
- * relaxed in the future. The meaning of config kARGB_8888_Config is
- * modified by the enum param config8888. The default value interprets
- * kARGB_8888_Config as SkPMColor
- *
- * If the bitmap has pixels already allocated, the canvas pixels will be
- * written there. If not, bitmap->allocPixels() will be called
- * automatically. If the bitmap is backed by a texture readPixels will
- * fail.
- *
- * The actual pixels written is the intersection of the canvas' bounds, and
- * the rectangle formed by the bitmap's width,height and the specified x,y.
- * If bitmap pixels extend outside of that intersection, they will not be
- * modified.
- *
- * Other failure conditions:
- * * If the canvas is backed by a non-raster device (e.g. PDF) then
- * readPixels will fail.
- * * If bitmap is texture-backed then readPixels will fail. (This may be
- * relaxed in the future.)
- *
- * Example that reads the entire canvas into a bitmap using the native
- * SkPMColor:
- * SkISize size = canvas->getDeviceSize();
- * bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
- * size.fHeight);
- * if (canvas->readPixels(bitmap, 0, 0)) {
- * // use the pixels
- * }
- */
- bool readPixels(SkBitmap* bitmap, int x, int y, Config8888 config8888);
-#endif
-
/**
* Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes),
* converting them into the requested format (SkImageInfo). The base-layer pixels are read
width/height will be the edge color replicated.
If a shader is present on the paint it will be ignored, except in the
- case where the bitmap is kA8_Config. In that case, the color is
+ case where the bitmap is kAlpha_8_SkColorType. In that case, the color is
generated by the shader.
@param bitmap The bitmap to be drawn
virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
const SkPaint&) = 0;
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
- /**
- * On success (returns true), copy the device pixels into the bitmap.
- * On failure, the bitmap parameter is left unchanged and false is
- * returned.
- *
- * The device's pixels are converted to the bitmap's config. The only
- * supported config is kARGB_8888_Config, though this is likely to be
- * relaxed in the future. The meaning of config kARGB_8888_Config is
- * modified by the enum param config8888. The default value interprets
- * kARGB_8888_Config as SkPMColor
- *
- * If the bitmap has pixels already allocated, the device pixels will be
- * written there. If not, bitmap->allocPixels() will be called
- * automatically. If the bitmap is backed by a texture readPixels will
- * fail.
- *
- * The actual pixels written is the intersection of the device's bounds,
- * and the rectangle formed by the bitmap's width,height and the specified
- * x,y. If bitmap pixels extend outside of that intersection, they will not
- * be modified.
- *
- * Other failure conditions:
- * * If the device is not a raster device (e.g. PDF) then readPixels will
- * fail.
- * * If bitmap is texture-backed then readPixels will fail. (This may be
- * relaxed in the future.)
- */
- bool readPixels(SkBitmap* bitmap,
- int x, int y,
- SkCanvas::Config8888 config8888);
-#endif
bool readPixels(const SkImageInfo&, void* dst, size_t rowBytes, int x, int y);
///////////////////////////////////////////////////////////////////////////
const SkImageFilter::Context& ctx,
SkBitmap* result, SkIPoint* offset) = 0;
-#ifdef SK_SUPPORT_LEGACY_CONFIG8888
- // This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if
- // either is identical to kNative_Premul_Config8888. Otherwise, -1.
- static const SkCanvas::Config8888 kPMColorAlias;
-#endif
-
protected:
// default impl returns NULL
virtual SkSurface* newSurface(const SkImageInfo&);
virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes);
/**
- * Implements readPixels API. The caller will ensure that:
- * 1. bitmap has pixel config kARGB_8888_Config.
- * 2. bitmap has pixels.
- * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is
- * contained in the device bounds.
- */
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
- virtual bool onReadPixels(const SkBitmap& bitmap, int x, int y, SkCanvas::Config8888);
-#endif
-
- /**
* The caller is responsible for "pre-clipping" the dst. The impl can assume that the dst
* image at the specified x,y offset will fit within the device's bounds.
*
int x, int y,
const SkPaint& paint) SK_OVERRIDE;
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
- virtual bool onReadPixels(const SkBitmap& bitmap,
- int x,
- int y,
- SkCanvas::Config8888) SK_OVERRIDE;
-#endif
-
virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE;
private:
protected:
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
- virtual bool onReadPixels(const SkBitmap&, int x, int y, SkCanvas::Config8888) SK_OVERRIDE;
-#endif
virtual bool onReadPixels(const SkImageInfo&, void*, size_t, int, int) SK_OVERRIDE;
virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) SK_OVERRIDE;
}
protected:
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
- virtual bool onReadPixels(const SkBitmap& bitmap, int x, int y,
- SkCanvas::Config8888) SK_OVERRIDE;
-#endif
virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE;
private:
return true;
}
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
-bool SkBitmapDevice::onReadPixels(const SkBitmap& bitmap,
- int x, int y,
- SkCanvas::Config8888 config8888) {
- SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config());
- SkASSERT(!bitmap.isNull());
- SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::MakeXYWH(x, y,
- bitmap.width(),
- bitmap.height())));
-
- SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.height());
- const SkBitmap& src = this->accessBitmap(false);
-
- SkBitmap subset;
- if (!src.extractSubset(&subset, srcRect)) {
- return false;
- }
- if (kPMColor_SkColorType != subset.colorType()) {
- // It'd be preferable to do this directly to bitmap.
- subset.copyTo(&subset, kPMColor_SkColorType);
- }
- SkAutoLockPixels alp(bitmap);
- uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels());
- SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset);
- return true;
-}
-#endif
-
void* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) {
if (fBitmap.getPixels()) {
*info = fBitmap.info();
return device;
}
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
-bool SkCanvas::readPixels(SkBitmap* bitmap,
- int x, int y,
- Config8888 config8888) {
- SkBaseDevice* device = this->getDevice();
- if (!device) {
- return false;
- }
- return device->readPixels(bitmap, x, y, config8888);
-}
-#endif
-
bool SkCanvas::readPixels(SkBitmap* bitmap, int x, int y) {
if (kUnknown_SkColorType == bitmap->colorType() || bitmap->getTexture()) {
return false;
return bitmap;
}
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
-bool SkBaseDevice::readPixels(SkBitmap* bitmap, int x, int y,
- SkCanvas::Config8888 config8888) {
- if (SkBitmap::kARGB_8888_Config != bitmap->config() ||
- NULL != bitmap->getTexture()) {
- return false;
- }
-
- const SkBitmap& src = this->accessBitmap(false);
-
- SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap->width(),
- bitmap->height());
- SkIRect devbounds = SkIRect::MakeWH(src.width(), src.height());
- if (!srcRect.intersect(devbounds)) {
- return false;
- }
-
- SkBitmap tmp;
- SkBitmap* bmp;
- if (bitmap->isNull()) {
- if (!tmp.allocPixels(SkImageInfo::MakeN32Premul(bitmap->width(),
- bitmap->height()))) {
- return false;
- }
- bmp = &tmp;
- } else {
- bmp = bitmap;
- }
-
- SkIRect subrect = srcRect;
- subrect.offset(-x, -y);
- SkBitmap bmpSubset;
- bmp->extractSubset(&bmpSubset, subrect);
-
- bool result = this->onReadPixels(bmpSubset,
- srcRect.fLeft,
- srcRect.fTop,
- config8888);
- if (result && bmp == &tmp) {
- tmp.swap(*bitmap);
- }
- return result;
-}
-bool SkBaseDevice::onReadPixels(const SkBitmap&, int x, int y, SkCanvas::Config8888) {
- return false;
-}
-#endif
-
SkSurface* SkBaseDevice::newSurface(const SkImageInfo&) { return NULL; }
const void* SkBaseDevice::peekPixels(SkImageInfo*, size_t*) { return NULL; }
"Could not add layer to current visuals.");
}
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
-bool SkXPSDevice::onReadPixels(const SkBitmap& bitmap, int x, int y,
- SkCanvas::Config8888) {
- return false;
-}
-#endif
-
SkBaseDevice* SkXPSDevice::onCreateDevice(const SkImageInfo&, Usage) {
//Conditional for bug compatibility with PDF device.
#if 0
///////////////////////////////////////////////////////////////////////////////
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
-namespace {
-GrPixelConfig config8888_to_grconfig_and_flags(SkCanvas::Config8888 config8888, uint32_t* flags) {
- switch (config8888) {
- case SkCanvas::kNative_Premul_Config8888:
- *flags = 0;
- return kSkia8888_GrPixelConfig;
- case SkCanvas::kNative_Unpremul_Config8888:
- *flags = GrContext::kUnpremul_PixelOpsFlag;
- return kSkia8888_GrPixelConfig;
- case SkCanvas::kBGRA_Premul_Config8888:
- *flags = 0;
- return kBGRA_8888_GrPixelConfig;
- case SkCanvas::kBGRA_Unpremul_Config8888:
- *flags = GrContext::kUnpremul_PixelOpsFlag;
- return kBGRA_8888_GrPixelConfig;
- case SkCanvas::kRGBA_Premul_Config8888:
- *flags = 0;
- return kRGBA_8888_GrPixelConfig;
- case SkCanvas::kRGBA_Unpremul_Config8888:
- *flags = GrContext::kUnpremul_PixelOpsFlag;
- return kRGBA_8888_GrPixelConfig;
- default:
- GrCrash("Unexpected Config8888.");
- *flags = 0; // suppress warning
- return kSkia8888_GrPixelConfig;
- }
-}
-}
-
-bool SkGpuDevice::onReadPixels(const SkBitmap& bitmap,
- int x, int y,
- SkCanvas::Config8888 config8888) {
- DO_DEFERRED_CLEAR();
- SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config());
- SkASSERT(!bitmap.isNull());
- SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.height())));
-
- SkAutoLockPixels alp(bitmap);
- GrPixelConfig config;
- uint32_t flags;
- config = config8888_to_grconfig_and_flags(config8888, &flags);
- return fContext->readRenderTargetPixels(fRenderTarget,
- x, y,
- bitmap.width(),
- bitmap.height(),
- config,
- bitmap.getPixels(),
- bitmap.rowBytes(),
- flags);
-}
-#endif
-
bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
int x, int y) {
DO_DEFERRED_CLEAR();
&content.entry()->fContent);
}
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
-bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y,
- SkCanvas::Config8888) {
- return false;
-}
-#endif
-
bool SkPDFDevice::allowImageFilter(const SkImageFilter*) {
return false;
}
protected:
virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE;
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
- virtual bool onReadPixels(const SkBitmap& bitmap,
- int x, int y,
- SkCanvas::Config8888 config8888) SK_OVERRIDE;
-#endif
virtual bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y) SK_OVERRIDE;
virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int x, int y) SK_OVERRIDE;
return this->immediateDevice()->newSurface(info);
}
-#ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
-bool SkDeferredDevice::onReadPixels(
- const SkBitmap& bitmap, int x, int y, SkCanvas::Config8888 config8888) {
- this->flushPendingCommands(kNormal_PlaybackMode);
- return fImmediateCanvas->readPixels(const_cast<SkBitmap*>(&bitmap),
- x, y, config8888);
-}
-#endif
-
bool SkDeferredDevice::onReadPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
int x, int y) {
this->flushPendingCommands(kNormal_PlaybackMode);