///////////////////////////////////////////////////////////////////////////////
static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorType dstCT,
- const SkIRect* subset) {
+ const SkIRect* subset) {
if (NULL == texture || kUnknown_SkColorType == dstCT) {
return NULL;
}
if (NULL == context) {
return NULL;
}
- GrTextureDesc desc;
+ GrSurfaceDesc desc;
- SkIPoint pointStorage;
- SkIPoint* topLeft;
- if (subset != NULL) {
+ SkIRect srcRect;
+
+ if (!subset) {
+ desc.fWidth = texture->width();
+ desc.fHeight = texture->height();
+ srcRect = SkIRect::MakeWH(texture->width(), texture->height());
+ } else {
SkASSERT(SkIRect::MakeWH(texture->width(), texture->height()).contains(*subset));
// Create a new texture that is the size of subset.
desc.fWidth = subset->width();
desc.fHeight = subset->height();
- pointStorage.set(subset->x(), subset->y());
- topLeft = &pointStorage;
- } else {
- desc.fWidth = texture->width();
- desc.fHeight = texture->height();
- topLeft = NULL;
+ srcRect = *subset;
}
- desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
+ desc.fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag;
desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType);
GrTexture* dst = context->createUncachedTexture(desc, NULL, 0);
return NULL;
}
- context->copyTexture(texture, dst->asRenderTarget(), topLeft);
-
// Blink is relying on the above copy being sent to GL immediately in the case when the source
- // is a WebGL canvas backing store. We could have a TODO to remove this flush, but we have a
- // larger TODO to remove SkGrPixelRef entirely.
- context->flush();
-
+ // is a WebGL canvas backing store. We could have a TODO to remove this flush flag, but we have
+ // a larger TODO to remove SkGrPixelRef entirely.
+ context->copySurface(dst->asRenderTarget(), texture, srcRect, SkIPoint::Make(0,0),
+ GrContext::kFlushWrites_PixelOp);
+
SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPremul_SkAlphaType);
SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst));
SkSafeUnref(dst);
///////////////////////////////////////////////////////////////////////////////
-SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface,
- bool transferCacheLock) : INHERITED(info) {
+SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface) : INHERITED(info) {
// For surfaces that are both textures and render targets, the texture owns the
// render target but not vice versa. So we ref the texture to keep both alive for
// the lifetime of this pixel ref.
if (NULL == fSurface) {
fSurface = SkSafeRef(surface);
}
- fUnlock = transferCacheLock;
if (fSurface) {
SkASSERT(info.width() <= fSurface->width());
}
SkGrPixelRef::~SkGrPixelRef() {
- if (fUnlock) {
- GrContext* context = fSurface->getContext();
- GrTexture* texture = fSurface->asTexture();
- if (context && texture) {
- context->unlockScratchTexture(texture);
- }
- }
SkSafeUnref(fSurface);
}