| Index: src/image/SkSurface_Gpu.cpp
|
| diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
|
| index 01c3bb74474112c94f10932c06a3a02e28543a90..b43a9a13d90aa90e8edea57a6e8b81892105110a 100644
|
| --- a/src/image/SkSurface_Gpu.cpp
|
| +++ b/src/image/SkSurface_Gpu.cpp
|
| @@ -20,11 +20,23 @@
|
|
|
| SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device)
|
| : INHERITED(device->width(), device->height(), &device->surfaceProps())
|
| - , fDevice(SkRef(device)) {
|
| + , fDevice(SkRef(device))
|
| + , fOwnsDevice(true) {
|
| + fDevice->setSurface(this);
|
| +}
|
| +
|
| +
|
| +SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device, ReverseOwnershipDeprecated)
|
| + : INHERITED(device->width(), device->height(), &device->surfaceProps())
|
| + , fDevice(device)
|
| + , fOwnsDevice(false) {
|
| + fDevice->setSurface(this);
|
| }
|
|
|
| SkSurface_Gpu::~SkSurface_Gpu() {
|
| - fDevice->unref();
|
| + if (fOwnsDevice) {
|
| + fDevice->unref();
|
| + }
|
| }
|
|
|
| SkCanvas* SkSurface_Gpu::onNewCanvas() {
|
| @@ -133,6 +145,47 @@ GrRenderTarget* SkSurface_Gpu::CreateRenderTarget(GrContext* context, SkSurface:
|
| return texture->asRenderTarget();
|
| }
|
|
|
| +SkGpuDevice* SkSurface_Gpu::createCompatibleDeviceDeprecated(
|
| + const SkBaseDevice::CreateInfo& cinfo) {
|
| + GrRenderTarget* rt = fDevice->accessRenderTarget();
|
| + GrSurfaceDesc desc;
|
| + desc.fConfig = rt->config();
|
| + desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
| + desc.fWidth = cinfo.fInfo.width();
|
| + desc.fHeight = cinfo.fInfo.height();
|
| + desc.fSampleCnt = rt->numSamples();
|
| +
|
| + SkAutoTUnref<GrTexture> texture;
|
| + // Skia's convention is to only clear a device if it is non-opaque.
|
| + unsigned flags = cinfo.fInfo.isOpaque() ? 0 : SkGpuDevice::kNeedClear_Flag;
|
| +
|
| + // layers are never draw in repeat modes, so we can request an approx
|
| + // match and ignore any padding.
|
| + const GrContext::ScratchTexMatch match = (SkBaseDevice::kSaveLayer_Usage == cinfo.fUsage) ?
|
| + GrContext::kApprox_ScratchTexMatch :
|
| + GrContext::kExact_ScratchTexMatch;
|
| + texture.reset(rt->getContext()->refScratchTexture(desc, match));
|
| +
|
| + if (!texture) {
|
| + SkDebugf("---- failed to create compatible device texture [%d %d]\n",
|
| + cinfo.fInfo.width(), cinfo.fInfo.height());
|
| + return NULL;
|
| + }
|
| +
|
| + // This is a factory function for SkGpuDevice (not SkSurface_Gpu, at the moment).
|
| + // Caller requested new instance of device, so caller owns the ref.
|
| + SkGpuDevice* device = SkGpuDevice::CreateWithReverseOwnershipDeprecated(
|
| + texture->asRenderTarget(), &this->props(), flags);
|
| + if (NULL == device) {
|
| + return NULL;
|
| + }
|
| +
|
| + SkNEW_ARGS(SkSurface_Gpu, (device, kReverseOwnershipDeprecated));
|
| +
|
| + // Device owns the surface.
|
| +
|
| + return device;
|
| +}
|
|
|
| ///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|