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

Unified Diff: src/gpu/SkGpuDevice.cpp

Issue 926843003: Move canvas->surface association to the device subclasses (Closed) Base URL: https://skia.googlesource.com/skia.git@skimage-filters-03-sksurface-set-root-device-simple
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.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 7b881d60a298e31005aefd375d6428b55df6b70f..fda57984677eced76ba3cfeda87a30da99438aaf 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -16,6 +16,7 @@
#include "GrContext.h"
#include "GrBitmapTextContext.h"
#include "GrDistanceFieldTextContext.h"
+#include "GrGpuResourcePriv.h"
#include "GrLayerHoister.h"
#include "GrRecordReplaceDraw.h"
#include "GrStrokeInfo.h"
@@ -45,6 +46,7 @@
#include "SkXfermode.h"
#include "SkErrorInternals.h"
+
#if SK_SUPPORT_GPU
enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 };
@@ -149,6 +151,7 @@ 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)
{
fDrawProcs = NULL;
@@ -233,12 +236,17 @@ SkGpuDevice::~SkGpuDevice() {
fContext->setClip(NULL);
}
- fRenderTarget->unref();
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();
@@ -297,6 +305,9 @@ void SkGpuDevice::onDetachFromCanvas() {
// and not the state from some other canvas/device
void SkGpuDevice::prepareDraw(const SkDraw& draw) {
SkASSERT(fClipData.fClipStack);
+ if (fSurface) {
+ fSurface->aboutToDraw(SkSurface::kRetain_ContentChangeMode);
+ }
fContext->setRenderTarget(fRenderTarget);
@@ -322,16 +333,33 @@ void SkGpuDevice::clearAll() {
fNeedClear = false;
}
-void SkGpuDevice::swapRenderTarget(GrRenderTarget* newRenderTarget) {
+void SkGpuDevice::detachBackendRenderTarget(bool retainContent) {
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();
+
+ GrRenderTarget* oldRT = fRenderTarget;
+ SkSurface::Budgeted budgeted = oldRT->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgeted :
+ SkSurface::kNo_Budgeted;
+
+ GrRenderTarget* newRT = CreateRenderTarget(oldRT->getContext(), budgeted, this->imageInfo(),
+ oldRT->numSamples());
+ if (newRT) {
+ if (retainContent && !oldRT->wasDestroyed()) {
+ oldRT->getContext()->copySurface(newRT, oldRT);
+ }
+
+ if (fRenderTarget != newRT) {
+ fRenderTarget->unref();
+ fRenderTarget = newRT;
+ }
+
+ SkASSERT(newRT->surfacePriv().info() == fLegacyBitmap.info());
+ SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (newRT->surfacePriv().info(),
+ newRT));
+ fLegacyBitmap.setPixelRef(pr)->unref();
+ }
}
///////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | src/image/SkSurface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698