Revert 8525,8526 pending investigation of bench_pictures crashes.
authorbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 3 Apr 2013 21:06:42 +0000 (21:06 +0000)
committerbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 3 Apr 2013 21:06:42 +0000 (21:06 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@8527 2bbb7eff-a529-9590-31e7-b0007b416f81

gyp/tests.gyp
include/gpu/GrRenderTarget.h
include/gpu/GrSurface.h
include/gpu/GrTexture.h
src/gpu/GrContext.cpp
src/gpu/GrGpu.h
src/gpu/GrTexture.cpp
src/gpu/gl/GrGLTexture.cpp
tests/GrSurfaceTest.cpp [deleted file]

index 8914edd..cd9e1b8 100644 (file)
@@ -57,7 +57,6 @@
         '../tests/GrContextFactoryTest.cpp',
         '../tests/GradientTest.cpp',
         '../tests/GrMemoryPoolTest.cpp',
-        '../tests/GrSurfaceTest.cpp',
         '../tests/HashCacheTest.cpp',
         '../tests/InfRectTest.cpp',
         '../tests/LListTest.cpp',
index 22f42f2..fcb4c3d 100644 (file)
@@ -149,6 +149,15 @@ protected:
     }
 
     friend class GrTexture;
+    // When a texture unrefs an owned render target this func
+    // removes the back pointer. This could be called from
+    // texture's destructor but would have to be done in derived
+    // classes. By the time of texture base destructor it has already
+    // lost its pointer to the rt.
+    void onTextureReleaseRenderTarget() {
+        GrAssert(NULL != fTexture);
+        fTexture = NULL;
+    }
 
     // override of GrResource
     virtual void onAbandon() SK_OVERRIDE;
index 52a5665..02fc0d5 100644 (file)
@@ -64,22 +64,6 @@ public:
     virtual const GrRenderTarget* asRenderTarget() const = 0;
 
     /**
-     * Checks whether this GrSurface refers to the same GPU object as other. This
-     * catches the case where a GrTexture and GrRenderTarget refer to the same
-     * GPU memory.
-     */
-    bool isSameAs(const GrSurface* other) const {
-        const GrRenderTarget* thisRT = this->asRenderTarget();
-        if (NULL != thisRT) {
-            return thisRT == other->asRenderTarget();
-        } else {
-            const GrTexture* thisTex = this->asTexture();
-            GrAssert(NULL != thisTex); // We must be one or the other
-            return thisTex == other->asTexture();
-        }
-    }
-
-    /**
      * Reads a rectangle of pixels from the surface.
      * @param left          left edge of the rectangle to read (inclusive)
      * @param top           top edge of the rectangle to read (inclusive)
index 52253ed..5d8ecaa 100644 (file)
@@ -11,8 +11,8 @@
 
 #include "GrSurface.h"
 #include "SkPoint.h"
-#include "GrRenderTarget.h"
 
+class GrRenderTarget;
 class GrResourceKey;
 class GrTextureParams;
 
@@ -80,10 +80,10 @@ public:
      *            render target
      */
     virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE {
-        return fRenderTarget.get();
+        return fRenderTarget;
     }
     virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE {
-        return fRenderTarget.get();
+        return fRenderTarget;
     }
 
     // GrTexture
@@ -101,6 +101,13 @@ public:
     }
 
     /**
+     * Removes the reference on the associated GrRenderTarget held by this
+     * texture. Afterwards asRenderTarget() will return NULL. The
+     * GrRenderTarget survives the release if another ref is held on it.
+     */
+    void releaseRenderTarget();
+
+    /**
      *  Return the native ID or handle to the texture, depending on the
      *  platform. e.g. on OpenGL, return the texture ID.
      */
@@ -130,9 +137,9 @@ public:
     static bool NeedsFiltering(const GrResourceKey& key);
 
 protected:
-    // A texture refs its rt representation but not vice-versa. It is up to
-    // the subclass constructor to initialize this pointer.
-    SkAutoTUnref<GrRenderTarget> fRenderTarget;
+    GrRenderTarget* fRenderTarget; // texture refs its rt representation
+                                   // base class cons sets to NULL
+                                   // subclass cons can create and set
 
     GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc)
     : INHERITED(gpu, isWrapped, desc)
index 071183b..1b62062 100644 (file)
@@ -373,6 +373,7 @@ GrTexture* GrContext::createResizedTexture(const GrTextureDesc& desc,
             verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(GrPoint));
             fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
         }
+        texture->releaseRenderTarget();
     } else {
         // TODO: Our CPU stretch doesn't filter. But we create separate
         // stretched textures when the texture params is either filtered or
index f55c6ad..d4e4e6b 100644 (file)
@@ -78,7 +78,8 @@ public:
      *
      * If kRenderTarget_TextureFlag is specified the GrRenderTarget is
      * accessible via GrTexture::asRenderTarget(). The texture will hold a ref
-     * on the render target until the texture is destroyed.
+     * on the render target until its releaseRenderTarget() is called or it is
+     * destroyed.
      *
      * @param desc        describes the texture to be created.
      * @param srcData     texel data to load texture. Begins with full-size
index 87df147..44a1442 100644 (file)
@@ -67,15 +67,33 @@ void GrTexture::writePixels(int left, int top, int width, int height,
                                 pixelOpsFlags);
 }
 
+void GrTexture::releaseRenderTarget() {
+    if (NULL != fRenderTarget) {
+        GrAssert(fRenderTarget->asTexture() == this);
+        GrAssert(fDesc.fFlags & kRenderTarget_GrTextureFlagBit);
+
+        fRenderTarget->onTextureReleaseRenderTarget();
+        fRenderTarget->unref();
+        fRenderTarget = NULL;
+
+        fDesc.fFlags = fDesc.fFlags &
+            ~(kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit);
+        fDesc.fSampleCnt = 0;
+    }
+}
+
 void GrTexture::onRelease() {
     GrAssert(!this->isSetFlag((GrTextureFlags) kReturnToCache_FlagBit));
+    this->releaseRenderTarget();
+
     INHERITED::onRelease();
 }
 
 void GrTexture::onAbandon() {
-    if (NULL != fRenderTarget.get()) {
+    if (NULL != fRenderTarget) {
         fRenderTarget->abandon();
     }
+
     INHERITED::onAbandon();
 }
 
index 6314b0c..66d6371 100644 (file)
@@ -34,7 +34,8 @@ void GrGLTexture::init(GrGpuGL* gpu,
         vp.fBottom = 0;
         vp.fHeight = textureDesc.fHeight;
 
-        fRenderTarget.reset(SkNEW_ARGS(GrGLRenderTarget, (gpu, *rtDesc, vp, fTexIDObj, this)));
+        fRenderTarget = SkNEW_ARGS(GrGLRenderTarget,
+                                   (gpu, *rtDesc, vp, fTexIDObj, this));
     }
 }
 
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
deleted file mode 100644 (file)
index 3fe071c..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-
-/*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-// This is a GPU-backend specific test.
-
-#include "SkTypes.h"
-
-#if SK_SUPPORT_GPU
-
-#include "Test.h"
-#include "GrContext.h"
-#include "GrContextFactory.h"
-#include "GrRenderTarget.h"
-#include "GrTexture.h"
-
-static void GrSurfaceIsSameTest(skiatest::Reporter* reporter, GrContextFactory* factory) {
-    GrContext* context = factory->get(GrContextFactory::kNull_GLContextType);
-    if (NULL != context) {
-        GrTextureDesc desc;
-        desc.fConfig = kSkia8888_GrPixelConfig;
-        desc.fFlags = kRenderTarget_GrTextureFlagBit;
-        desc.fWidth = 256;
-        desc.fHeight = 256;
-        desc.fSampleCnt = 0;
-        GrSurface* texRT1 = context->createUncachedTexture(desc, NULL, 0);
-        GrSurface* texRT2 = context->createUncachedTexture(desc, NULL, 0);
-        desc.fFlags = kNone_GrTextureFlags;
-        GrSurface* tex1 = context->createUncachedTexture(desc, NULL, 0);
-
-        REPORTER_ASSERT(reporter, texRT1->isSameAs(texRT1));
-        REPORTER_ASSERT(reporter, texRT1->isSameAs(texRT1->asRenderTarget()));
-        REPORTER_ASSERT(reporter, texRT1->asRenderTarget()->isSameAs(texRT1));
-        REPORTER_ASSERT(reporter, !texRT2->isSameAs(texRT1));
-        REPORTER_ASSERT(reporter, !texRT2->asRenderTarget()->isSameAs(texRT1));
-        REPORTER_ASSERT(reporter, !texRT2->isSameAs(texRT1->asRenderTarget()));
-        REPORTER_ASSERT(reporter, !texRT2->isSameAs(tex1));
-        REPORTER_ASSERT(reporter, !texRT2->asRenderTarget()->isSameAs(tex1));
-
-        GrBackendTextureDesc backendDesc;
-        backendDesc.fConfig = kSkia8888_GrPixelConfig;
-        backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
-        backendDesc.fWidth = 256;
-        backendDesc.fHeight = 256;
-        backendDesc.fSampleCnt = 0;
-        backendDesc.fTextureHandle = 5;
-        GrSurface* externalTexRT = context->wrapBackendTexture(backendDesc);
-        REPORTER_ASSERT(reporter, externalTexRT->isSameAs(externalTexRT));
-        REPORTER_ASSERT(reporter, externalTexRT->isSameAs(externalTexRT->asRenderTarget()));
-        REPORTER_ASSERT(reporter, externalTexRT->asRenderTarget()->isSameAs(externalTexRT));
-        REPORTER_ASSERT(reporter, !externalTexRT->isSameAs(texRT1));
-        REPORTER_ASSERT(reporter, !externalTexRT->asRenderTarget()->isSameAs(texRT1));
-
-        texRT1->unref();
-        texRT2->unref();
-        tex1->unref();
-        externalTexRT->unref();
-    }
-}
-
-#include "TestClassDef.h"
-DEFINE_GPUTESTCLASS("GrSurfaceIsSame", GrSurfaceIsSameTestClass, GrSurfaceIsSameTest)
-
-#endif