Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Unified Diff: src/gpu/SkGpuDevice.cpp

Issue 925343002: Swap render target instead of creating a new gpu device for surface copy-on-write (Closed) Base URL: https://skia.googlesource.com/skia.git@skimage-filters-02-use-sksurface-constructor-skgpudevice
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | src/image/SkSurface_Gpu.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/SkGpuDevice.cpp
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 9760968e54970f8259fda84585b560b4575ac9b2..2aa16e4d8d9c7cbaaa2df625abd59a772f6aad23 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -7,41 +7,40 @@
#include "SkGpuDevice.h"
-#include "effects/GrBicubicEffect.h"
-#include "effects/GrDashingEffect.h"
-#include "effects/GrTextureDomain.h"
-#include "effects/GrSimpleTextureEffect.h"
-
-#include "GrContext.h"
#include "GrBitmapTextContext.h"
+#include "GrContext.h"
#include "GrDistanceFieldTextContext.h"
+#include "GrGpu.h"
+#include "GrGpuResourcePriv.h"
#include "GrLayerHoister.h"
#include "GrRecordReplaceDraw.h"
#include "GrStrokeInfo.h"
#include "GrTracing.h"
-#include "GrGpu.h"
-
-#include "SkGrTexturePixelRef.h"
-
#include "SkCanvasPriv.h"
#include "SkDeviceImageFilterProxy.h"
#include "SkDrawProcs.h"
+#include "SkErrorInternals.h"
#include "SkGlyphCache.h"
+#include "SkGrTexturePixelRef.h"
#include "SkImageFilter.h"
#include "SkLayerInfo.h"
#include "SkMaskFilter.h"
#include "SkPathEffect.h"
#include "SkPicture.h"
#include "SkPictureData.h"
-#include "SkRecord.h"
#include "SkRRect.h"
+#include "SkRecord.h"
#include "SkStroke.h"
#include "SkSurface.h"
+#include "SkSurface_Gpu.h"
#include "SkTLazy.h"
#include "SkUtils.h"
#include "SkVertState.h"
#include "SkXfermode.h"
-#include "SkErrorInternals.h"
+#include "effects/GrBicubicEffect.h"
+#include "effects/GrDashingEffect.h"
+#include "effects/GrSimpleTextureEffect.h"
+#include "effects/GrTextureDomain.h"
#if SK_SUPPORT_GPU
@@ -164,9 +163,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;
@@ -195,13 +193,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 (NULL == rt) {
return NULL;
}
- return SkNEW_ARGS(SkGpuDevice, (texture->asRenderTarget(), props, flags));
+ return SkNEW_ARGS(SkGpuDevice, (rt, props, flags));
}
SkGpuDevice::~SkGpuDevice() {
@@ -302,6 +311,38 @@ void SkGpuDevice::clearAll() {
fNeedClear = false;
}
+void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) {
+ // Caller must have accessed the render target, because it knows the rt must be replaced.
+ SkASSERT(!fNeedClear);
+
+ SkSurface::Budgeted budgeted =
+ fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgeted
+ : SkSurface::kNo_Budgeted;
+
+ SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget(
+ fRenderTarget->getContext(), budgeted, this->imageInfo(), fRenderTarget->numSamples()));
+
+ if (NULL == newRT) {
+ return;
+ }
+
+ if (shouldRetainContent) {
+ if (fRenderTarget->wasDestroyed()) {
+ return;
+ }
+ this->context()->copySurface(newRT, fRenderTarget);
+ }
+
+ SkASSERT(fRenderTarget != newRT);
+
+ fRenderTarget->unref();
+ fRenderTarget = newRT.detach();
+
+ SkASSERT(fRenderTarget->surfacePriv().info() == fLegacyBitmap.info());
+ SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (fRenderTarget->surfacePriv().info(), fRenderTarget));
+ fLegacyBitmap.setPixelRef(pr)->unref();
+}
+
///////////////////////////////////////////////////////////////////////////////
SK_COMPILE_ASSERT(SkShader::kNone_BitmapType == 0, shader_type_mismatch);
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | src/image/SkSurface_Gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698