switch to colortype for deepcopy
BUG=skia: R=robertphillips@google.com, bsalomon@google.com, reed@google.com Author: reed@chromium.org Review URL: https://codereview.chromium.org/323283002
This commit is contained in:
parent
bae584ab35
commit
e4538f5b46
@ -223,14 +223,14 @@ public:
|
||||
|
||||
/**
|
||||
* Makes a deep copy of this PixelRef, respecting the requested config.
|
||||
* @param config Desired config.
|
||||
* @param colorType Desired colortype.
|
||||
* @param subset Subset of this PixelRef to copy. Must be fully contained within the bounds of
|
||||
* of this PixelRef.
|
||||
* @return A new SkPixelRef, or NULL if either there is an error (e.g. the destination could
|
||||
* not be created with the given config), or this PixelRef does not support deep
|
||||
* copies.
|
||||
*/
|
||||
virtual SkPixelRef* deepCopy(SkBitmap::Config config, const SkIRect* subset = NULL) {
|
||||
virtual SkPixelRef* deepCopy(SkColorType colortype, const SkIRect* subset) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ public:
|
||||
protected:
|
||||
// overrides from SkPixelRef
|
||||
virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset) SK_OVERRIDE;
|
||||
virtual SkPixelRef* deepCopy(SkBitmap::Config dstConfig, const SkIRect* subset) SK_OVERRIDE;
|
||||
virtual SkPixelRef* deepCopy(SkColorType, const SkIRect* subset) SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
GrSurface* fSurface;
|
||||
|
@ -830,7 +830,7 @@ bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const {
|
||||
|
||||
if (fPixelRef->getTexture() != NULL) {
|
||||
// Do a deep copy
|
||||
SkPixelRef* pixelRef = fPixelRef->deepCopy(this->config(), &subset);
|
||||
SkPixelRef* pixelRef = fPixelRef->deepCopy(this->colorType(), &subset);
|
||||
if (pixelRef != NULL) {
|
||||
SkBitmap dst;
|
||||
dst.setInfo(SkImageInfo::Make(subset.width(), subset.height(),
|
||||
@ -1031,8 +1031,7 @@ bool SkBitmap::copyTo(SkBitmap* dst, SkColorType dstColorType,
|
||||
}
|
||||
|
||||
bool SkBitmap::deepCopyTo(SkBitmap* dst) const {
|
||||
const SkBitmap::Config dstConfig = this->config();
|
||||
const SkColorType dstCT = SkBitmapConfigToColorType(dstConfig);
|
||||
const SkColorType dstCT = this->colorType();
|
||||
|
||||
if (!this->canCopyTo(dstCT)) {
|
||||
return false;
|
||||
@ -1041,7 +1040,7 @@ bool SkBitmap::deepCopyTo(SkBitmap* dst) const {
|
||||
// If we have a PixelRef, and it supports deep copy, use it.
|
||||
// Currently supported only by texture-backed bitmaps.
|
||||
if (fPixelRef) {
|
||||
SkPixelRef* pixelRef = fPixelRef->deepCopy(dstConfig);
|
||||
SkPixelRef* pixelRef = fPixelRef->deepCopy(dstCT, NULL);
|
||||
if (pixelRef) {
|
||||
uint32_t rowBytes;
|
||||
if (this->colorType() == dstCT) {
|
||||
|
@ -51,9 +51,9 @@ bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, SkBitmap::Config dstConfig,
|
||||
static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, SkColorType dstCT,
|
||||
const SkIRect* subset) {
|
||||
if (NULL == texture) {
|
||||
if (NULL == texture || kUnknown_SkColorType == dstCT) {
|
||||
return NULL;
|
||||
}
|
||||
GrContext* context = texture->getContext();
|
||||
@ -77,15 +77,7 @@ static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, SkBitmap::Config
|
||||
topLeft = NULL;
|
||||
}
|
||||
desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
|
||||
desc.fConfig = SkBitmapConfig2GrPixelConfig(dstConfig);
|
||||
|
||||
SkImageInfo info;
|
||||
if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) {
|
||||
return NULL;
|
||||
}
|
||||
info.fWidth = desc.fWidth;
|
||||
info.fHeight = desc.fHeight;
|
||||
info.fAlphaType = kPremul_SkAlphaType;
|
||||
desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType);
|
||||
|
||||
GrTexture* dst = context->createUncachedTexture(desc, NULL, 0);
|
||||
if (NULL == dst) {
|
||||
@ -104,6 +96,7 @@ static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, SkBitmap::Config
|
||||
dst->releaseRenderTarget();
|
||||
#endif
|
||||
|
||||
SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPremul_SkAlphaType);
|
||||
SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst));
|
||||
SkSafeUnref(dst);
|
||||
return pixelRef;
|
||||
@ -152,18 +145,18 @@ GrTexture* SkGrPixelRef::getTexture() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkPixelRef* SkGrPixelRef::deepCopy(SkBitmap::Config dstConfig, const SkIRect* subset) {
|
||||
SkPixelRef* SkGrPixelRef::deepCopy(SkColorType dstCT, const SkIRect* subset) {
|
||||
if (NULL == fSurface) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// Note that when copying a render-target-backed pixel ref, we
|
||||
// return a texture-backed pixel ref instead. This is because
|
||||
// render-target pixel refs are usually created in conjunction with
|
||||
// a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live
|
||||
// independently of that texture. Texture-backed pixel refs, on the other
|
||||
// hand, own their GrTextures, and are thus self-contained.
|
||||
return copyToTexturePixelRef(fSurface->asTexture(), dstConfig, subset);
|
||||
return copyToTexturePixelRef(fSurface->asTexture(), dstCT, subset);
|
||||
}
|
||||
|
||||
bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) {
|
||||
|
Loading…
Reference in New Issue
Block a user