Index: src/gpu/SkGpuDevice.cpp |
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp |
index 8912851d8f369c88a9b36aeb7d281c8b2490c690..7b881d60a298e31005aefd375d6428b55df6b70f 100644 |
--- a/src/gpu/SkGpuDevice.cpp |
+++ b/src/gpu/SkGpuDevice.cpp |
@@ -38,6 +38,7 @@ |
#include "SkRRect.h" |
#include "SkStroke.h" |
#include "SkSurface.h" |
+#include "SkSurface_Gpu.h" |
#include "SkTLazy.h" |
#include "SkUtils.h" |
#include "SkVertState.h" |
@@ -165,9 +166,8 @@ SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, const SkSurfaceProps* props, unsign |
fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProperties(), useDFT); |
} |
-SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgeted, |
- const SkImageInfo& origInfo, int sampleCount, |
- const SkSurfaceProps* props, unsigned flags) { |
+GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::Budgeted budgeted, |
+ const SkImageInfo& origInfo, int sampleCount) { |
if (kUnknown_SkColorType == origInfo.colorType() || |
origInfo.width() < 0 || origInfo.height() < 0) { |
return NULL; |
@@ -196,13 +196,24 @@ SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete |
desc.fHeight = info.height(); |
desc.fConfig = SkImageInfo2GrPixelConfig(info); |
desc.fSampleCnt = sampleCount; |
+ GrTexture* texture = context->createTexture(desc, SkToBool(budgeted), NULL, 0); |
+ if (NULL == texture) { |
+ return NULL; |
+ } |
+ SkASSERT(NULL != texture->asRenderTarget()); |
+ return texture->asRenderTarget(); |
+} |
- SkAutoTUnref<GrTexture> texture(context->createTexture(desc, SkToBool(budgeted), NULL, 0)); |
- if (!texture) { |
+SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgeted, |
+ const SkImageInfo& info, int sampleCount, |
+ const SkSurfaceProps* props, unsigned flags) { |
+ |
+ SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget(context, budgeted, info, sampleCount)); |
+ if (!rt) { |
return NULL; |
} |
- return SkNEW_ARGS(SkGpuDevice, (texture->asRenderTarget(), props, flags)); |
+ return SkNEW_ARGS(SkGpuDevice, (rt, props, flags)); |
} |
SkGpuDevice::~SkGpuDevice() { |
@@ -311,6 +322,18 @@ void SkGpuDevice::clearAll() { |
fNeedClear = false; |
} |
+void SkGpuDevice::swapRenderTarget(GrRenderTarget* newRenderTarget) { |
+ SkASSERT(!fNeedClear); |
+ if (fContext->getRenderTarget() == fRenderTarget) { |
+ fContext->setRenderTarget(NULL); |
+ } |
+ SkRefCnt_SafeAssign(fRenderTarget, newRenderTarget); |
+ SkASSERT(newRenderTarget->surfacePriv().info() == fLegacyBitmap.info()); |
+ SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (newRenderTarget->surfacePriv().info(), |
+ newRenderTarget)); |
+ fLegacyBitmap.setPixelRef(pr)->unref(); |
+} |
+ |
/////////////////////////////////////////////////////////////////////////////// |
SK_COMPILE_ASSERT(SkShader::kNone_BitmapType == 0, shader_type_mismatch); |