Moved SkGrTexturePixelRef to SkGrPixelRef
authorrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 28 Jun 2012 20:59:13 +0000 (20:59 +0000)
committerrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 28 Jun 2012 20:59:13 +0000 (20:59 +0000)
http://codereview.appspot.com/6344054/

git-svn-id: http://skia.googlecode.com/svn/trunk@4397 2bbb7eff-a529-9590-31e7-b0007b416f81

gyp/gpu.gyp
include/gpu/SkGrPixelRef.h [new file with mode: 0644]
include/gpu/SkGrTexturePixelRef.h [deleted file]
src/gpu/SkGpuDevice.cpp
src/gpu/SkGrPixelRef.cpp [new file with mode: 0644]
src/gpu/SkGrTexturePixelRef.cpp [deleted file]

index 381d6bcc5e4c8a371ce2a1d5f929399d4f5ca175..40d5c28b60d091eda666bd31c00c9d6bd6dba155 100644 (file)
         '../include/gpu/SkGpuCanvas.h',
         '../include/gpu/SkGpuDevice.h',
         '../include/gpu/SkGr.h',
-        '../include/gpu/SkGrTexturePixelRef.h',
+        '../include/gpu/SkGrPixelRef.h',
 
         '../include/gpu/gl/SkGLContext.h',
         '../include/gpu/gl/SkMesaGLContext.h',
         '../src/gpu/SkGpuDevice.cpp',
         '../src/gpu/SkGr.cpp',
         '../src/gpu/SkGrFontScaler.cpp',
-        '../src/gpu/SkGrTexturePixelRef.cpp',
+        '../src/gpu/SkGrPixelRef.cpp',
 
         '../src/gpu/gl/SkGLContext.cpp',
         '../src/gpu/gl/SkNullGLContext.cpp',
diff --git a/include/gpu/SkGrPixelRef.h b/include/gpu/SkGrPixelRef.h
new file mode 100644 (file)
index 0000000..b7eaf0d
--- /dev/null
@@ -0,0 +1,64 @@
+
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+
+#ifndef SkGrPixelRef_DEFINED
+#define SkGrPixelRef_DEFINED
+
+#include "SkBitmap.h"
+#include "SkPixelRef.h"
+#include "GrTexture.h"
+#include "GrRenderTarget.h"
+
+
+/**
+ *  Common baseclass that implements onLockPixels() by calling onReadPixels().
+ *  Since it has a copy, it always returns false for onLockPixelsAreWritable().
+ */
+class SK_API SkROLockPixelsPixelRef : public SkPixelRef {
+public:
+    SkROLockPixelsPixelRef();
+    virtual ~SkROLockPixelsPixelRef();
+
+protected:
+    // override from SkPixelRef
+    virtual void* onLockPixels(SkColorTable** ptr);
+    virtual void onUnlockPixels();
+    virtual bool onLockPixelsAreWritable() const;   // return false;
+
+private:
+    SkBitmap    fBitmap;
+    typedef SkPixelRef INHERITED;
+};
+
+/**
+ *  PixelRef that wraps a GrSurface
+ */
+class SK_API SkGrPixelRef : public SkROLockPixelsPixelRef {
+public:
+    SkGrPixelRef(GrSurface* surface);
+    virtual ~SkGrPixelRef();
+
+    // override from SkPixelRef
+    virtual SkGpuTexture* getTexture() SK_OVERRIDE;
+
+    SK_DECLARE_UNFLATTENABLE_OBJECT()
+
+protected:
+    // overrides from SkPixelRef
+    virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset) SK_OVERRIDE;
+    virtual SkPixelRef* deepCopy(SkBitmap::Config dstConfig) SK_OVERRIDE;
+
+private:
+    GrSurface*  fSurface;
+    typedef SkROLockPixelsPixelRef INHERITED;
+};
+
+#endif
+
diff --git a/include/gpu/SkGrTexturePixelRef.h b/include/gpu/SkGrTexturePixelRef.h
deleted file mode 100644 (file)
index b7eaf0d..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-
-/*
- * Copyright 2010 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-
-#ifndef SkGrPixelRef_DEFINED
-#define SkGrPixelRef_DEFINED
-
-#include "SkBitmap.h"
-#include "SkPixelRef.h"
-#include "GrTexture.h"
-#include "GrRenderTarget.h"
-
-
-/**
- *  Common baseclass that implements onLockPixels() by calling onReadPixels().
- *  Since it has a copy, it always returns false for onLockPixelsAreWritable().
- */
-class SK_API SkROLockPixelsPixelRef : public SkPixelRef {
-public:
-    SkROLockPixelsPixelRef();
-    virtual ~SkROLockPixelsPixelRef();
-
-protected:
-    // override from SkPixelRef
-    virtual void* onLockPixels(SkColorTable** ptr);
-    virtual void onUnlockPixels();
-    virtual bool onLockPixelsAreWritable() const;   // return false;
-
-private:
-    SkBitmap    fBitmap;
-    typedef SkPixelRef INHERITED;
-};
-
-/**
- *  PixelRef that wraps a GrSurface
- */
-class SK_API SkGrPixelRef : public SkROLockPixelsPixelRef {
-public:
-    SkGrPixelRef(GrSurface* surface);
-    virtual ~SkGrPixelRef();
-
-    // override from SkPixelRef
-    virtual SkGpuTexture* getTexture() SK_OVERRIDE;
-
-    SK_DECLARE_UNFLATTENABLE_OBJECT()
-
-protected:
-    // overrides from SkPixelRef
-    virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset) SK_OVERRIDE;
-    virtual SkPixelRef* deepCopy(SkBitmap::Config dstConfig) SK_OVERRIDE;
-
-private:
-    GrSurface*  fSurface;
-    typedef SkROLockPixelsPixelRef INHERITED;
-};
-
-#endif
-
index c0feff22af6753213fc17df79bb783034d4aac99..ee0d3c1032dbb38276924465ec439ccb40e8ab85 100644 (file)
@@ -14,7 +14,7 @@
 #include "GrDefaultTextContext.h"
 #include "GrTextContext.h"
 
-#include "SkGrTexturePixelRef.h"
+#include "SkGrPixelRef.h"
 
 #include "SkColorFilter.h"
 #include "SkDrawProcs.h"
diff --git a/src/gpu/SkGrPixelRef.cpp b/src/gpu/SkGrPixelRef.cpp
new file mode 100644 (file)
index 0000000..4359da2
--- /dev/null
@@ -0,0 +1,150 @@
+
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+
+#include "SkGrPixelRef.h"
+#include "GrContext.h"
+#include "GrTexture.h"
+#include "SkGr.h"
+#include "SkRect.h"
+
+// since we call lockPixels recursively on fBitmap, we need a distinct mutex,
+// to avoid deadlock with the default one provided by SkPixelRef.
+SK_DECLARE_STATIC_MUTEX(gROLockPixelsPixelRefMutex);
+
+SkROLockPixelsPixelRef::SkROLockPixelsPixelRef() : INHERITED(&gROLockPixelsPixelRefMutex) {
+}
+
+SkROLockPixelsPixelRef::~SkROLockPixelsPixelRef() {
+}
+
+void* SkROLockPixelsPixelRef::onLockPixels(SkColorTable** ctable) {
+    if (ctable) {
+        *ctable = NULL;
+    }
+    fBitmap.reset();
+//    SkDebugf("---------- calling readpixels in support of lockpixels\n");
+    if (!this->onReadPixels(&fBitmap, NULL)) {
+        SkDebugf("SkROLockPixelsPixelRef::onLockPixels failed!\n");
+        return NULL;
+    }
+    fBitmap.lockPixels();
+    return fBitmap.getPixels();
+}
+
+void SkROLockPixelsPixelRef::onUnlockPixels() {
+    fBitmap.unlockPixels();
+}
+
+bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const {
+    return false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture,
+                                           SkBitmap::Config dstConfig) {
+    if (NULL == texture) {
+        return NULL;
+    }
+    GrContext* context = texture->getContext();
+    if (NULL == context) {
+        return NULL;
+    }
+    GrTextureDesc desc;
+
+    desc.fWidth  = texture->width();
+    desc.fHeight = texture->height();
+    desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
+    desc.fConfig = SkGr::BitmapConfig2PixelConfig(dstConfig);
+
+    GrTexture* dst = context->createUncachedTexture(desc, NULL, 0);
+    if (NULL == dst) {
+        return NULL;
+    }
+
+    context->copyTexture(texture, dst->asRenderTarget());
+
+    // The render texture we have created (to perform the copy) isn't fully
+    // functional (since it doesn't have a stencil buffer). Release it here
+    // so the caller doesn't try to render to it.
+    // TODO: we can undo this release when dynamic stencil buffer attach/
+    // detach has been implemented
+    dst->releaseRenderTarget();
+
+    SkGrPixelRef* pixelRef = new SkGrPixelRef(dst);
+    GrSafeUnref(dst);
+    return pixelRef;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+SkGrPixelRef::SkGrPixelRef(GrSurface* surface) {
+    // The GrTexture has a ref to the GrRenderTarget but not vice versa.
+    // If the GrTexture exists take a ref to that (rather than the render
+    // target)
+    fSurface = surface->asTexture();
+    if (NULL == fSurface) {
+        fSurface = surface;
+    }
+
+    GrSafeRef(surface);
+}
+
+SkGrPixelRef::~SkGrPixelRef() {
+    GrSafeUnref(fSurface);
+}
+
+SkGpuTexture* SkGrPixelRef::getTexture() {
+    if (NULL != fSurface) {
+        return (SkGpuTexture*) fSurface->asTexture();
+    }
+    return NULL;
+}
+
+SkPixelRef* SkGrPixelRef::deepCopy(SkBitmap::Config dstConfig) {
+    if (NULL == fSurface) {
+        return NULL;
+    }
+
+    // Note that when copying a render-target-backed pixel ref, we
+    // return a texture-backed pixel ref instead.  This is because
+    // render-target pixel refs are usually created in conjunction with
+    // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live
+    // independently of that texture.  Texture-backed pixel refs, on the other
+    // hand, own their GrTextures, and are thus self-contained.
+    return copyToTexturePixelRef(fSurface->asTexture(), dstConfig);
+}
+
+bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) {
+    if (NULL == fSurface || !fSurface->isValid()) {
+        return false;
+    }
+
+    int left, top, width, height;
+    if (NULL != subset) {
+        left = subset->fLeft;
+        width = subset->width();
+        top = subset->fTop;
+        height = subset->height();
+    } else {
+        left = 0;
+        width = fSurface->width();
+        top = 0;
+        height = fSurface->height();
+    }
+    dst->setConfig(SkBitmap::kARGB_8888_Config, width, height);
+    dst->allocPixels();
+    SkAutoLockPixels al(*dst);
+    void* buffer = dst->getPixels();
+    return fSurface->readPixels(left, top, width, height,
+                                kSkia8888_PM_GrPixelConfig,
+                                buffer, dst->rowBytes());
+}
+
diff --git a/src/gpu/SkGrTexturePixelRef.cpp b/src/gpu/SkGrTexturePixelRef.cpp
deleted file mode 100644 (file)
index 33577f6..0000000
+++ /dev/null
@@ -1,150 +0,0 @@
-
-/*
- * Copyright 2010 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-
-#include "SkGrTexturePixelRef.h"
-#include "GrContext.h"
-#include "GrTexture.h"
-#include "SkGr.h"
-#include "SkRect.h"
-
-// since we call lockPixels recursively on fBitmap, we need a distinct mutex,
-// to avoid deadlock with the default one provided by SkPixelRef.
-SK_DECLARE_STATIC_MUTEX(gROLockPixelsPixelRefMutex);
-
-SkROLockPixelsPixelRef::SkROLockPixelsPixelRef() : INHERITED(&gROLockPixelsPixelRefMutex) {
-}
-
-SkROLockPixelsPixelRef::~SkROLockPixelsPixelRef() {
-}
-
-void* SkROLockPixelsPixelRef::onLockPixels(SkColorTable** ctable) {
-    if (ctable) {
-        *ctable = NULL;
-    }
-    fBitmap.reset();
-//    SkDebugf("---------- calling readpixels in support of lockpixels\n");
-    if (!this->onReadPixels(&fBitmap, NULL)) {
-        SkDebugf("SkROLockPixelsPixelRef::onLockPixels failed!\n");
-        return NULL;
-    }
-    fBitmap.lockPixels();
-    return fBitmap.getPixels();
-}
-
-void SkROLockPixelsPixelRef::onUnlockPixels() {
-    fBitmap.unlockPixels();
-}
-
-bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const {
-    return false;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture,
-                                           SkBitmap::Config dstConfig) {
-    if (NULL == texture) {
-        return NULL;
-    }
-    GrContext* context = texture->getContext();
-    if (NULL == context) {
-        return NULL;
-    }
-    GrTextureDesc desc;
-
-    desc.fWidth  = texture->width();
-    desc.fHeight = texture->height();
-    desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
-    desc.fConfig = SkGr::BitmapConfig2PixelConfig(dstConfig);
-
-    GrTexture* dst = context->createUncachedTexture(desc, NULL, 0);
-    if (NULL == dst) {
-        return NULL;
-    }
-
-    context->copyTexture(texture, dst->asRenderTarget());
-
-    // The render texture we have created (to perform the copy) isn't fully
-    // functional (since it doesn't have a stencil buffer). Release it here
-    // so the caller doesn't try to render to it.
-    // TODO: we can undo this release when dynamic stencil buffer attach/
-    // detach has been implemented
-    dst->releaseRenderTarget();
-
-    SkGrPixelRef* pixelRef = new SkGrPixelRef(dst);
-    GrSafeUnref(dst);
-    return pixelRef;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-SkGrPixelRef::SkGrPixelRef(GrSurface* surface) {
-    // The GrTexture has a ref to the GrRenderTarget but not vice versa.
-    // If the GrTexture exists take a ref to that (rather than the render
-    // target)
-    fSurface = surface->asTexture();
-    if (NULL == fSurface) {
-        fSurface = surface;
-    }
-
-    GrSafeRef(surface);
-}
-
-SkGrPixelRef::~SkGrPixelRef() {
-    GrSafeUnref(fSurface);
-}
-
-SkGpuTexture* SkGrPixelRef::getTexture() {
-    if (NULL != fSurface) {
-        return (SkGpuTexture*) fSurface->asTexture();
-    }
-    return NULL;
-}
-
-SkPixelRef* SkGrPixelRef::deepCopy(SkBitmap::Config dstConfig) {
-    if (NULL == fSurface) {
-        return NULL;
-    }
-
-    // Note that when copying a render-target-backed pixel ref, we
-    // return a texture-backed pixel ref instead.  This is because
-    // render-target pixel refs are usually created in conjunction with
-    // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live
-    // independently of that texture.  Texture-backed pixel refs, on the other
-    // hand, own their GrTextures, and are thus self-contained.
-    return copyToTexturePixelRef(fSurface->asTexture(), dstConfig);
-}
-
-bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) {
-    if (NULL == fSurface || !fSurface->isValid()) {
-        return false;
-    }
-
-    int left, top, width, height;
-    if (NULL != subset) {
-        left = subset->fLeft;
-        width = subset->width();
-        top = subset->fTop;
-        height = subset->height();
-    } else {
-        left = 0;
-        width = fSurface->width();
-        top = 0;
-        height = fSurface->height();
-    }
-    dst->setConfig(SkBitmap::kARGB_8888_Config, width, height);
-    dst->allocPixels();
-    SkAutoLockPixels al(*dst);
-    void* buffer = dst->getPixels();
-    return fSurface->readPixels(left, top, width, height,
-                                kSkia8888_PM_GrPixelConfig,
-                                buffer, dst->rowBytes());
-}
-