aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-03-21 13:26:13 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-21 13:26:22 +0000
commiteaa78c45002b4a6e43f4fe2028652b050132dad2 (patch)
tree00c45b889ac05a1a7e34a33f0e301bb2f73b4e5c /src/image
parent107524c2a26e81ebeb2edaa62a96df3bcde0d0c7 (diff)
Revert "Make SkImage_Gpu be deferred"
This reverts commit 0db235bc0278887c344eb25b4681e9cca4cf892a. Reason for revert: cc_unittests failing Original change's description: > Make SkImage_Gpu be deferred > > This CL removes the GrTexture-based ctor forcing everyone to create deferred SkImage_Gpus. > > split out into: > https://skia-review.googlesource.com/c/9106/ (Remove atlas creation from GrResourceProvider) > > Change-Id: I266bbe089c242fe54d5b7adcc7895aa5a39440a0 > Reviewed-on: https://skia-review.googlesource.com/6680 > Commit-Queue: Robert Phillips <robertphillips@google.com> > Reviewed-by: Brian Salomon <bsalomon@google.com> > TBR=bsalomon@google.com,robertphillips@google.com,reviews@skia.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Change-Id: Ia15590a1fae04b52723713760fdbf0492ad36286 Reviewed-on: https://skia-review.googlesource.com/9962 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/image')
-rw-r--r--src/image/SkImage.cpp17
-rw-r--r--src/image/SkImage_Base.h7
-rw-r--r--src/image/SkImage_Gpu.cpp69
-rw-r--r--src/image/SkImage_Gpu.h8
-rw-r--r--src/image/SkSurface_Gpu.cpp37
5 files changed, 51 insertions, 87 deletions
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index fe6369ed35..6217f4ecda 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -169,14 +169,25 @@ sk_sp<SkImage> SkImage::makeSubset(const SkIRect& subset) const {
#if SK_SUPPORT_GPU
GrTexture* SkImage::getTexture() const {
- return as_IB(this)->onGetTexture();
+ return as_IB(this)->peekTexture();
}
-bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->peekProxy()); }
+bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->peekTexture()); }
GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextIO,
GrSurfaceOrigin* origin) const {
- return as_IB(this)->onGetTextureHandle(flushPendingGrContextIO, origin);
+ GrTexture* texture = as_IB(this)->peekTexture();
+ if (texture) {
+ GrContext* context = texture->getContext();
+ if (context && flushPendingGrContextIO) {
+ context->prepareSurfaceForExternalIO(texture);
+ }
+ if (origin) {
+ *origin = texture->origin();
+ }
+ return texture->getTextureHandle();
+ }
+ return 0;
}
#else
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h
index e0319ddc25..284af0d1a6 100644
--- a/src/image/SkImage_Base.h
+++ b/src/image/SkImage_Base.h
@@ -47,20 +47,13 @@ public:
virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
int srcX, int srcY, CachingHint) const = 0;
- // MDB TODO: this entry point needs to go away
virtual GrTexture* peekTexture() const { return nullptr; }
#if SK_SUPPORT_GPU
- virtual GrTextureProxy* peekProxy() const { return nullptr; }
virtual sk_sp<GrTextureProxy> asTextureProxyRef() const { return nullptr; }
virtual sk_sp<GrTextureProxy> asTextureProxyRef(GrContext*, const GrSamplerParams&,
SkColorSpace*, sk_sp<SkColorSpace>*,
SkScalar scaleAdjust[2]) const = 0;
virtual sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const { return nullptr; }
- virtual GrBackendObject onGetTextureHandle(bool flushPendingGrContextIO,
- GrSurfaceOrigin* origin) const {
- return 0;
- }
- virtual GrTexture* onGetTexture() const { return nullptr; }
#endif
virtual SkImageCacherator* peekCacherator() const { return nullptr; }
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index c9bc2ee9a4..bcd7275279 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -36,6 +36,17 @@
#include "SkPixelRef.h"
#include "SkReadPixelsRec.h"
+SkImage_Gpu::SkImage_Gpu(uint32_t uniqueID, SkAlphaType at, sk_sp<GrTexture> tex,
+ sk_sp<SkColorSpace> colorSpace, SkBudgeted budgeted)
+ : INHERITED(tex->width(), tex->height(), uniqueID)
+ , fContext(tex->getContext())
+ , fProxy(GrSurfaceProxy::MakeWrapped(std::move(tex)))
+ , fAlphaType(at)
+ , fBudgeted(budgeted)
+ , fColorSpace(std::move(colorSpace))
+ , fAddedRasterVersionToCache(false) {
+}
+
SkImage_Gpu::SkImage_Gpu(GrContext* context, uint32_t uniqueID, SkAlphaType at,
sk_sp<GrTextureProxy> proxy,
sk_sp<SkColorSpace> colorSpace, SkBudgeted budgeted)
@@ -154,33 +165,6 @@ static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes)
}
}
-GrBackendObject SkImage_Gpu::onGetTextureHandle(bool flushPendingGrContextIO,
- GrSurfaceOrigin* origin) const {
- GrTextureProxy* proxy = this->peekProxy();
- SkASSERT(proxy);
-
- GrSurface* surface = proxy->instantiate(fContext->resourceProvider());
- if (surface && surface->asTexture()) {
- if (flushPendingGrContextIO) {
- fContext->prepareSurfaceForExternalIO(surface);
- }
- if (origin) {
- *origin = surface->origin();
- }
- return surface->asTexture()->getTextureHandle();
- }
- return 0;
-}
-
-GrTexture* SkImage_Gpu::onGetTexture() const {
- GrTextureProxy* proxy = this->peekProxy();
- if (!proxy) {
- return nullptr;
- }
-
- return proxy->instantiate(fContext->resourceProvider());
-}
-
bool SkImage_Gpu::onReadYUV8Planes(const SkISize sizes[3], void* const planes[3],
const size_t rowBytes[3], SkYUVColorSpace colorSpace) const {
if (GrTextureToYUVPlanes(fContext, fProxy, sizes, planes, rowBytes, colorSpace)) {
@@ -267,7 +251,6 @@ static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackend
if (desc.fWidth <= 0 || desc.fHeight <= 0) {
return nullptr;
}
-
sk_sp<GrTexture> tex = ctx->resourceProvider()->wrapBackendTexture(desc, ownership);
if (!tex) {
return nullptr;
@@ -278,9 +261,8 @@ static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackend
const SkBudgeted budgeted = (kAdoptAndCache_GrWrapOwnership == ownership)
? SkBudgeted::kYes : SkBudgeted::kNo;
- sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(tex)));
- return sk_make_sp<SkImage_Gpu>(ctx, kNeedNewImageUniqueID,
- at, std::move(proxy), std::move(colorSpace), budgeted);
+ return sk_make_sp<SkImage_Gpu>(kNeedNewImageUniqueID,
+ at, std::move(tex), std::move(colorSpace), budgeted);
}
sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
@@ -406,8 +388,7 @@ sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace
std::move(imageColorSpace));
}
-static sk_sp<SkImage> create_image_from_maker(GrContext* context,
- GrTextureMaker* maker, SkAlphaType at, uint32_t id,
+static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id,
SkColorSpace* dstColorSpace) {
sk_sp<SkColorSpace> texColorSpace;
sk_sp<GrTexture> texture(maker->refTextureForParams(GrSamplerParams::ClampNoFilter(),
@@ -415,8 +396,7 @@ static sk_sp<SkImage> create_image_from_maker(GrContext* context,
if (!texture) {
return nullptr;
}
- sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(std::move(texture));
- return sk_make_sp<SkImage_Gpu>(context, id, at, std::move(proxy),
+ return sk_make_sp<SkImage_Gpu>(id, at, std::move(texture),
std::move(texColorSpace), SkBudgeted::kNo);
}
@@ -430,14 +410,12 @@ sk_sp<SkImage> SkImage::makeTextureImage(GrContext* context, SkColorSpace* dstCo
if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) {
GrImageTextureMaker maker(context, cacher, this, kDisallow_CachingHint);
- return create_image_from_maker(context, &maker, this->alphaType(),
- this->uniqueID(), dstColorSpace);
+ return create_image_from_maker(&maker, this->alphaType(), this->uniqueID(), dstColorSpace);
}
if (const SkBitmap* bmp = as_IB(this)->onPeekBitmap()) {
GrBitmapTextureMaker maker(context, *bmp);
- return create_image_from_maker(context, &maker, this->alphaType(),
- this->uniqueID(), dstColorSpace);
+ return create_image_from_maker(&maker, this->alphaType(), this->uniqueID(), dstColorSpace);
}
return nullptr;
}
@@ -846,16 +824,13 @@ sk_sp<SkImage> SkImage::MakeTextureFromMipMap(GrContext* ctx, const SkImageInfo&
if (!ctx) {
return nullptr;
}
- sk_sp<GrTextureProxy> proxy(GrUploadMipMapToTextureProxy(ctx, info, texels, mipLevelCount,
- colorMode));
- if (!proxy) {
+ sk_sp<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, mipLevelCount, colorMode));
+ if (!texture) {
return nullptr;
}
-
- SkASSERT(proxy->priv().isExact());
- return sk_make_sp<SkImage_Gpu>(ctx, kNeedNewImageUniqueID,
- info.alphaType(), std::move(proxy),
- info.refColorSpace(), budgeted);
+ return sk_make_sp<SkImage_Gpu>(kNeedNewImageUniqueID,
+ info.alphaType(), std::move(texture),
+ sk_ref_sp(info.colorSpace()), budgeted);
}
sk_sp<SkImage> SkImage_Gpu::onMakeColorSpace(sk_sp<SkColorSpace> colorSpace) const {
diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h
index 858419156c..53c38dc278 100644
--- a/src/image/SkImage_Gpu.h
+++ b/src/image/SkImage_Gpu.h
@@ -21,6 +21,7 @@
class SkImage_Gpu : public SkImage_Base {
public:
+ SkImage_Gpu(uint32_t uniqueID, SkAlphaType, sk_sp<GrTexture>, sk_sp<SkColorSpace>, SkBudgeted);
SkImage_Gpu(GrContext*, uint32_t uniqueID, SkAlphaType, sk_sp<GrTextureProxy>,
sk_sp<SkColorSpace>, SkBudgeted);
~SkImage_Gpu() override;
@@ -33,9 +34,6 @@ public:
sk_sp<SkColorSpace>*, SkScalar scaleAdjust[2]) const override;
sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
- GrTextureProxy* peekProxy() const override {
- return fProxy.get();
- }
GrTexture* peekTexture() const override {
return fProxy->instantiate(fContext->resourceProvider());
}
@@ -45,14 +43,10 @@ public:
sk_sp<GrTextureProxy> asTextureProxyRef(GrContext*, const GrSamplerParams&, SkColorSpace*,
sk_sp<SkColorSpace>*,
SkScalar scaleAdjust[2]) const override;
-
sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const override {
*uniqueID = this->uniqueID();
return sk_ref_sp(this->peekTexture());
}
- GrBackendObject onGetTextureHandle(bool flushPendingGrContextIO,
- GrSurfaceOrigin* origin) const override;
- GrTexture* onGetTexture() const override;
bool onReadYUV8Planes(const SkISize sizes[3], void* const planes[3],
const size_t rowBytes[3], SkYUVColorSpace colorSpace) const override;
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index fdbbf82779..b610c9c9a1 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -8,15 +8,14 @@
#include "SkSurface_Gpu.h"
#include "GrContextPriv.h"
-#include "GrRenderTargetContextPriv.h"
#include "GrResourceProvider.h"
-
#include "SkCanvas.h"
#include "SkColorSpace_Base.h"
#include "SkGpuDevice.h"
#include "SkImage_Base.h"
#include "SkImage_Gpu.h"
#include "SkImagePriv.h"
+#include "GrRenderTargetContextPriv.h"
#include "SkSurface_Base.h"
#if SK_SUPPORT_GPU
@@ -24,7 +23,6 @@
SkSurface_Gpu::SkSurface_Gpu(sk_sp<SkGpuDevice> device)
: INHERITED(device->width(), device->height(), &device->surfaceProps())
, fDevice(std::move(device)) {
- SkASSERT(fDevice->accessRenderTargetContext()->asSurfaceProxy()->priv().isExact());
}
SkSurface_Gpu::~SkSurface_Gpu() {
@@ -93,45 +91,38 @@ sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot() {
GrContext* ctx = fDevice->context();
- if (!rtc->asSurfaceProxy()) {
- return nullptr;
- }
-
- SkBudgeted budgeted = rtc->asSurfaceProxy()->isBudgeted();
-
- sk_sp<GrTextureProxy> srcProxy = rtc->asTextureProxyRef();
+ GrSurfaceProxy* srcProxy = rtc->asSurfaceProxy();
+ sk_sp<GrSurfaceContext> copyCtx;
// If the original render target is a buffer originally created by the client, then we don't
// want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid
// copy-on-write.
if (!srcProxy || rtc->priv().refsWrappedObjects()) {
- // MDB TODO: replace this with GrSurfaceProxy::Copy?
GrSurfaceDesc desc = rtc->desc();
desc.fFlags = desc.fFlags & ~kRenderTarget_GrSurfaceFlag;
- sk_sp<GrSurfaceContext> copyCtx = ctx->contextPriv().makeDeferredSurfaceContext(
- desc,
+ copyCtx = ctx->contextPriv().makeDeferredSurfaceContext(desc,
SkBackingFit::kExact,
- budgeted);
+ srcProxy->isBudgeted());
if (!copyCtx) {
return nullptr;
}
- if (!copyCtx->copy(rtc->asSurfaceProxy())) {
+ if (!copyCtx->copy(srcProxy)) {
return nullptr;
}
- srcProxy = copyCtx->asTextureProxyRef();
+ srcProxy = copyCtx->asSurfaceProxy();
}
+ // TODO: add proxy-backed SkImage_Gpu
+ GrTexture* tex = srcProxy->instantiate(ctx->resourceProvider())->asTexture();
+
const SkImageInfo info = fDevice->imageInfo();
sk_sp<SkImage> image;
- if (srcProxy) {
- // The renderTargetContext coming out of SkGpuDevice should always be exact and the
- // above copy creates a kExact surfaceContext.
- SkASSERT(srcProxy->priv().isExact());
- image = sk_make_sp<SkImage_Gpu>(ctx, kNeedNewImageUniqueID,
- info.alphaType(), std::move(srcProxy),
- info.refColorSpace(), budgeted);
+ if (tex) {
+ image = sk_make_sp<SkImage_Gpu>(kNeedNewImageUniqueID,
+ info.alphaType(), sk_ref_sp(tex),
+ sk_ref_sp(info.colorSpace()), srcProxy->isBudgeted());
}
return image;
}