Index: src/gpu/SkGpuDevice.cpp |
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp |
index 7fc0b352b781919673e30db2fb64d301e2195a8a..d7a5f4678035debd981d6583c0d315ba37ed8346 100644 |
--- a/src/gpu/SkGpuDevice.cpp |
+++ b/src/gpu/SkGpuDevice.cpp |
@@ -130,6 +130,17 @@ SkGpuDevice* SkGpuDevice::Create(GrRenderTarget* rt, const SkSurfaceProps* props |
return SkNEW_ARGS(SkGpuDevice, (rt, props, flags)); |
} |
+SkGpuDevice* SkGpuDevice::CreateWithReverseOwnershipDeprecated(GrRenderTarget* rt, |
+ const SkSurfaceProps* props, |
+ unsigned flags) { |
+ SkGpuDevice* device = SkGpuDevice::Create(rt, props, flags); |
+ if (NULL == device) { |
+ return device; |
+ } |
+ device->fDeviceOwnsSurface = true; |
+ return device; |
+} |
+ |
static SkDeviceProperties surfaceprops_to_deviceprops(const SkSurfaceProps* props) { |
if (props) { |
return SkDeviceProperties(props->pixelGeometry()); |
@@ -149,6 +160,8 @@ static SkSurfaceProps copy_or_default_props(const SkSurfaceProps* props) { |
SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, const SkSurfaceProps* props, unsigned flags) |
: INHERITED(surfaceprops_to_deviceprops(props)) |
, fSurfaceProps(copy_or_default_props(props)) |
+ , fSurface(NULL) |
+ , fDeviceOwnsSurface(false) |
{ |
fDrawProcs = NULL; |
@@ -166,6 +179,14 @@ SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, const SkSurfaceProps* props, unsign |
fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProperties(), useDFT); |
} |
+void SkGpuDevice::setSurface(SkSurface_Gpu* surface) { |
+ if (fDeviceOwnsSurface) { |
+ SkRefCnt_SafeAssign(fSurface, surface); |
+ } else { |
+ fSurface = surface; |
+ } |
+} |
+ |
SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgeted, |
const SkImageInfo& info, int sampleCount, |
const SkSurfaceProps* props, unsigned flags) { |
@@ -196,12 +217,18 @@ SkGpuDevice::~SkGpuDevice() { |
fContext->setClip(NULL); |
} |
- fRenderTarget->unref(); |
+ this->setSurface(NULL); |
fContext->unref(); |
} |
/////////////////////////////////////////////////////////////////////////////// |
+void SkGpuDevice::discard() { |
+ if (fSurface) { |
+ fSurface->aboutToDraw(SkSurface::kDiscard_ContentChangeMode); |
+ } |
+} |
+ |
bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
int x, int y) { |
DO_DEFERRED_CLEAR(); |
@@ -261,6 +288,10 @@ void SkGpuDevice::onDetachFromCanvas() { |
void SkGpuDevice::prepareDraw(const SkDraw& draw) { |
SkASSERT(fClipData.fClipStack); |
+ if (fSurface) { |
+ fSurface->aboutToDraw(SkSurface::kRetain_ContentChangeMode); |
+ } |
+ |
fContext->setRenderTarget(fRenderTarget); |
SkASSERT(draw.fClipStack && draw.fClipStack == fClipData.fClipStack); |
@@ -1796,32 +1827,7 @@ void SkGpuDevice::flush() { |
/////////////////////////////////////////////////////////////////////////////// |
SkBaseDevice* SkGpuDevice::onCreateCompatibleDevice(const CreateInfo& cinfo) { |
- GrSurfaceDesc desc; |
- desc.fConfig = fRenderTarget->config(); |
- desc.fFlags = kRenderTarget_GrSurfaceFlag; |
- desc.fWidth = cinfo.fInfo.width(); |
- desc.fHeight = cinfo.fInfo.height(); |
- desc.fSampleCnt = fRenderTarget->numSamples(); |
- |
- SkAutoTUnref<GrTexture> texture; |
- // Skia's convention is to only clear a device if it is non-opaque. |
- unsigned flags = cinfo.fInfo.isOpaque() ? 0 : kNeedClear_Flag; |
- |
- // layers are never draw in repeat modes, so we can request an approx |
- // match and ignore any padding. |
- const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == cinfo.fUsage) ? |
- GrContext::kApprox_ScratchTexMatch : |
- GrContext::kExact_ScratchTexMatch; |
- texture.reset(fContext->refScratchTexture(desc, match)); |
- |
- if (texture) { |
- SkSurfaceProps props(fSurfaceProps.flags(), cinfo.fPixelGeometry); |
- return SkGpuDevice::Create(texture->asRenderTarget(), &props, flags); |
- } else { |
- SkDebugf("---- failed to create compatible device texture [%d %d]\n", |
- cinfo.fInfo.width(), cinfo.fInfo.height()); |
- return NULL; |
- } |
+ return fSurface->createCompatibleDeviceDeprecated(cinfo); |
} |
SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps& props) { |