Rm readPixels from GrSurface & move read/writeSurfacePixels to GrContextPriv (take 2)
authorRobert Phillips <robertphillips@google.com>
Wed, 5 Apr 2017 16:18:58 +0000 (12:18 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 5 Apr 2017 17:00:10 +0000 (17:00 +0000)
This is in service of: https://skia-review.googlesource.com/c/11125/ (Add parallel proxyID to StencilOps & RenderTargetOpList) where I want a better choke point for texture creation to improve discard handling.

This is a reland of: https://skia-review.googlesource.com/c/11200/ (Rm readPixels from GrSurface & move read/writeSurfacePixels to GrContextPriv)

Change-Id: Icd0a90d2beb483dc24ed87c3bace9c817019e148
Reviewed-on: https://skia-review.googlesource.com/11326
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>

30 files changed:
include/gpu/GrContext.h
include/gpu/GrProcessorUnitTest.h
include/gpu/GrSurface.h
src/gpu/GrContext.cpp
src/gpu/GrContextPriv.h
src/gpu/GrRenderTargetContext.cpp
src/gpu/GrResourceProvider.cpp
src/gpu/GrResourceProvider.h
src/gpu/GrSurface.cpp
src/gpu/GrSurfaceProxy.cpp
src/gpu/GrTextureContext.cpp
src/gpu/SkGr.cpp
src/gpu/effects/GrTextureStripAtlas.cpp
src/image/SkImage_Gpu.cpp
tests/BlendTest.cpp
tests/FloatingPointTextureTest.cpp
tests/GLProgramsTest.cpp
tests/GrSurfaceTest.cpp
tests/ImageFilterCacheTest.cpp
tests/ImageStorageTest.cpp
tests/IntTextureTest.cpp
tests/PackedConfigsTextureTest.cpp
tests/ProcessorTest.cpp
tests/ProxyTest.cpp
tests/ReadPixelsTest.cpp
tests/ReadWriteAlphaTest.cpp
tests/ResourceCacheTest.cpp
tests/SRGBReadWritePixelsTest.cpp
tests/TestUtils.cpp
tests/VkUploadPixelsTests.cpp

index ccd27286c7341b410992fabbfa9300ca2de21937..0987d96b2e35be8b7b0e1784d0413fd694bc4920 100644 (file)
@@ -246,68 +246,6 @@ public:
      */
     void flush();
 
-   /**
-    * These flags can be used with the read/write pixels functions below.
-    */
-    enum PixelOpsFlags {
-        /** The GrContext will not be flushed before the surface read or write. This means that
-            the read or write may occur before previous draws have executed. */
-        kDontFlush_PixelOpsFlag = 0x1,
-        /** Any surface writes should be flushed to the backend 3D API after the surface operation
-            is complete */
-        kFlushWrites_PixelOp = 0x2,
-        /** The src for write or dst read is unpremultiplied. This is only respected if both the
-            config src and dst configs are an RGBA/BGRA 8888 format. */
-        kUnpremul_PixelOpsFlag  = 0x4,
-    };
-
-    /**
-     * Reads a rectangle of pixels from a surface.
-     * @param surface       the surface to read from.
-     * @param srcColorSpace color space of the surface
-     * @param left          left edge of the rectangle to read (inclusive)
-     * @param top           top edge of the rectangle to read (inclusive)
-     * @param width         width of rectangle to read in pixels.
-     * @param height        height of rectangle to read in pixels.
-     * @param config        the pixel config of the destination buffer
-     * @param dstColorSpace color space of the destination buffer
-     * @param buffer        memory to read the rectangle into.
-     * @param rowBytes      number of bytes bewtween consecutive rows. Zero means rows are tightly
-     *                      packed.
-     * @param pixelOpsFlags see PixelOpsFlags enum above.
-     *
-     * @return true if the read succeeded, false if not. The read can fail because of an unsupported
-     *         pixel configs
-     */
-    bool readSurfacePixels(GrSurface* surface, SkColorSpace* srcColorSpace,
-                           int left, int top, int width, int height,
-                           GrPixelConfig config, SkColorSpace* dstColorSpace, void* buffer,
-                           size_t rowBytes = 0,
-                           uint32_t pixelOpsFlags = 0);
-
-    /**
-     * Writes a rectangle of pixels to a surface.
-     * @param surface       the surface to write to.
-     * @param dstColorSpace color space of the surface
-     * @param left          left edge of the rectangle to write (inclusive)
-     * @param top           top edge of the rectangle to write (inclusive)
-     * @param width         width of rectangle to write in pixels.
-     * @param height        height of rectangle to write in pixels.
-     * @param config        the pixel config of the source buffer
-     * @param srcColorSpace color space of the source buffer
-     * @param buffer        memory to read pixels from
-     * @param rowBytes      number of bytes between consecutive rows. Zero
-     *                      means rows are tightly packed.
-     * @param pixelOpsFlags see PixelOpsFlags enum above.
-     * @return true if the write succeeded, false if not. The write can fail because of an
-     *         unsupported combination of surface and src configs.
-     */
-    bool writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpace,
-                            int left, int top, int width, int height,
-                            GrPixelConfig config, SkColorSpace* srcColorSpace, const void* buffer,
-                            size_t rowBytes,
-                            uint32_t pixelOpsFlags = 0);
-
     /**
      * An ID associated with this context, guaranteed to be unique.
      */
index 912e393ca06065b881fc83fd3783c924d6b2237c..d6269c85bd599d8e96855a6250610f0da09dc46d 100644 (file)
@@ -49,12 +49,12 @@ struct GrProcessorTestData {
     GrProcessorTestData(SkRandom* random,
                         GrContext* context,
                         const GrRenderTargetContext* renderTargetContext,
-                        GrTexture* const textures[2])
+                        sk_sp<GrTextureProxy> proxies[2])
             : fRandom(random)
             , fRenderTargetContext(renderTargetContext)
             , fContext(context) {
-        fProxies[0] = GrSurfaceProxy::MakeWrapped(sk_ref_sp(textures[0]));
-        fProxies[1] = GrSurfaceProxy::MakeWrapped(sk_ref_sp(textures[1]));
+        fProxies[0] = proxies[0];
+        fProxies[1] = proxies[1];
     }
     SkRandom* fRandom;
     const GrRenderTargetContext* fRenderTargetContext;
index 328731c38f3be8153e2e180c9ddb5d3b4dfea698..81bc215c018081a5cbbc83da743f40c4c0f29f9a 100644 (file)
@@ -66,106 +66,6 @@ public:
     virtual GrRenderTarget* asRenderTarget() { return NULL; }
     virtual const GrRenderTarget* asRenderTarget() const { return NULL; }
 
-    /**
-     * Reads a rectangle of pixels from the surface, possibly performing color space conversion.
-     * @param srcColorSpace color space of the source data (this surface)
-     * @param left          left edge of the rectangle to read (inclusive)
-     * @param top           top edge of the rectangle to read (inclusive)
-     * @param width         width of rectangle to read in pixels.
-     * @param height        height of rectangle to read in pixels.
-     * @param config        the pixel config of the destination buffer
-     * @param dstColorSpace color space of the destination buffer
-     * @param buffer        memory to read the rectangle into.
-     * @param rowBytes      number of bytes between consecutive rows. Zero means rows are tightly
-     *                      packed.
-     * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum.
-     *
-     * @return true if the read succeeded, false if not. The read can fail because of an unsupported
-     *              pixel config.
-     */
-    bool readPixels(SkColorSpace* srcColorSpace,
-                    int left, int top, int width, int height,
-                    GrPixelConfig config,
-                    SkColorSpace* dstColorSpace,
-                    void* buffer,
-                    size_t rowBytes = 0,
-                    uint32_t pixelOpsFlags = 0);
-
-    /**
-     * Reads a rectangle of pixels from the surface. Does not perform any color space conversion.
-     * @param left          left edge of the rectangle to read (inclusive)
-     * @param top           top edge of the rectangle to read (inclusive)
-     * @param width         width of rectangle to read in pixels.
-     * @param height        height of rectangle to read in pixels.
-     * @param config        the pixel config of the destination buffer
-     * @param buffer        memory to read the rectangle into.
-     * @param rowBytes      number of bytes between consecutive rows. Zero means rows are tightly
-     *                      packed.
-     * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum.
-     *
-     * @return true if the read succeeded, false if not. The read can fail because of an unsupported
-     *              pixel config.
-     */
-    bool readPixels(int left, int top, int width, int height,
-                    GrPixelConfig config,
-                    void* buffer,
-                    size_t rowBytes = 0,
-                    uint32_t pixelOpsFlags = 0) {
-        return this->readPixels(nullptr, left, top, width, height, config, nullptr, buffer,
-                                rowBytes, pixelOpsFlags);
-    }
-
-    /**
-     * Copy the src pixels [buffer, rowbytes, pixelconfig] into the surface at the specified
-     * rectangle, possibly performing color space conversion.
-     * @param dstColorSpace color space of the destination (this surface)
-     * @param left          left edge of the rectangle to write (inclusive)
-     * @param top           top edge of the rectangle to write (inclusive)
-     * @param width         width of rectangle to write in pixels.
-     * @param height        height of rectangle to write in pixels.
-     * @param config        the pixel config of the source buffer
-     * @param srcColorSpace color space of the source buffer
-     * @param buffer        memory to read the rectangle from.
-     * @param rowBytes      number of bytes between consecutive rows. Zero means rows are tightly
-     *                      packed.
-     * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum.
-     *
-     * @return true if the write succeeded, false if not. The write can fail because of an
-     *              unsupported pixel config.
-     */
-    bool writePixels(SkColorSpace* dstColorSpace,
-                     int left, int top, int width, int height,
-                     GrPixelConfig config,
-                     SkColorSpace* srcColorSpace,
-                     const void* buffer,
-                     size_t rowBytes = 0,
-                     uint32_t pixelOpsFlags = 0);
-
-    /**
-     * Copy the src pixels [buffer, rowbytes, pixelconfig] into the surface at the specified
-     * rectangle. Does not perform any color space conversion.
-     * @param left          left edge of the rectangle to write (inclusive)
-     * @param top           top edge of the rectangle to write (inclusive)
-     * @param width         width of rectangle to write in pixels.
-     * @param height        height of rectangle to write in pixels.
-     * @param config        the pixel config of the source buffer
-     * @param buffer        memory to read the rectangle from.
-     * @param rowBytes      number of bytes between consecutive rows. Zero means rows are tightly
-     *                      packed.
-     * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum.
-     *
-     * @return true if the write succeeded, false if not. The write can fail because of an
-     *              unsupported pixel config.
-     */
-    bool writePixels(int left, int top, int width, int height,
-                     GrPixelConfig config,
-                     const void* buffer,
-                     size_t rowBytes = 0,
-                     uint32_t pixelOpsFlags = 0) {
-        return this->writePixels(nullptr, left, top, width, height, config, nullptr, buffer,
-                                 rowBytes, pixelOpsFlags);
-    }
-
     /** Access methods that are only to be used within Skia code. */
     inline GrSurfacePriv surfacePriv();
     inline const GrSurfacePriv surfacePriv() const;
index 98f709a96273c384c0aea4e95ce151637203ebc4..c1961f95574fa2cd203a5ce3730a4cc6961699c6 100644 (file)
@@ -26,6 +26,8 @@
 #include "effects/GrConfigConversionEffect.h"
 #include "text/GrTextBlobCache.h"
 
+#define ASSERT_OWNED_PROXY(P) \
+SkASSERT(!(P) || !((P)->priv().peekTexture()) || (P)->priv().peekTexture()->getContext() == this)
 #define ASSERT_OWNED_PROXY_PRIV(P) \
 SkASSERT(!(P) || !((P)->priv().peekTexture()) || (P)->priv().peekTexture()->getContext() == fContext)
 
@@ -37,6 +39,7 @@ SkASSERT(!(P) || !((P)->priv().peekTexture()) || (P)->priv().peekTexture()->getC
 #define RETURN_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return; }
 #define RETURN_IF_ABANDONED_PRIV if (fContext->fDrawingManager->wasAbandoned()) { return; }
 #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return false; }
+#define RETURN_FALSE_IF_ABANDONED_PRIV if (fContext->fDrawingManager->wasAbandoned()) { return false; }
 #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return nullptr; }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -264,19 +267,25 @@ static bool valid_unpremul_config(GrPixelConfig config) {
     return GrPixelConfigIs8888Unorm(config) || kRGBA_half_GrPixelConfig == config;
 }
 
-bool GrContext::writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpace,
-                                   int left, int top, int width, int height,
-                                   GrPixelConfig srcConfig, SkColorSpace* srcColorSpace,
-                                   const void* buffer, size_t rowBytes, uint32_t pixelOpsFlags) {
+bool GrContextPriv::writeSurfacePixels(GrSurfaceProxy* srcProxy, SkColorSpace* dstColorSpace,
+                                       int left, int top, int width, int height,
+                                       GrPixelConfig srcConfig, SkColorSpace* srcColorSpace,
+                                       const void* buffer, size_t rowBytes,
+                                       uint32_t pixelOpsFlags) {
     // TODO: Color space conversion
 
-    ASSERT_SINGLE_OWNER
-    RETURN_FALSE_IF_ABANDONED
-    ASSERT_OWNED_RESOURCE(surface);
-    SkASSERT(surface);
-    GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::writeSurfacePixels");
+    ASSERT_SINGLE_OWNER_PRIV
+    RETURN_FALSE_IF_ABANDONED_PRIV
+    ASSERT_OWNED_PROXY_PRIV(srcProxy);
+    SkASSERT(srcProxy);
+    GR_AUDIT_TRAIL_AUTO_FRAME(&fContext->fAuditTrail, "GrContextPriv::writeSurfacePixels");
 
-    this->testPMConversionsIfNecessary(pixelOpsFlags);
+    GrSurface* surface = srcProxy->instantiate(fContext->resourceProvider());
+    if (!surface) {
+        return false;
+    }
+
+    fContext->testPMConversionsIfNecessary(pixelOpsFlags);
 
     // Trim the params here so that if we wind up making a temporary surface it can be as small as
     // necessary and because GrGpu::getWritePixelsInfo requires it.
@@ -298,23 +307,23 @@ bool GrContext::writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpa
     GrGpu::DrawPreference drawPreference = GrGpu::kNoDraw_DrawPreference;
     // Don't prefer to draw for the conversion (and thereby access a texture from the cache) when
     // we've already determined that there isn't a roundtrip preserving conversion processor pair.
-    if (applyPremulToSrc && this->validPMUPMConversionExists(srcConfig)) {
+    if (applyPremulToSrc && fContext->validPMUPMConversionExists(srcConfig)) {
         drawPreference = GrGpu::kCallerPrefersDraw_DrawPreference;
     }
 
     GrGpu::WritePixelTempDrawInfo tempDrawInfo;
-    if (!fGpu->getWritePixelsInfo(surface, width, height, srcConfig, &drawPreference,
-                                  &tempDrawInfo)) {
+    if (!fContext->fGpu->getWritePixelsInfo(surface, width, height, srcConfig,
+                                            &drawPreference, &tempDrawInfo)) {
         return false;
     }
 
     if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && surface->surfacePriv().hasPendingIO()) {
-        this->contextPriv().flush(nullptr); // MDB TODO: tighten this
+        this->flush(nullptr); // MDB TODO: tighten this
     }
 
     sk_sp<GrTextureProxy> tempProxy;
     if (GrGpu::kNoDraw_DrawPreference != drawPreference) {
-        tempProxy = GrSurfaceProxy::MakeDeferred(this->resourceProvider(),
+        tempProxy = GrSurfaceProxy::MakeDeferred(fContext->resourceProvider(),
                                                  tempDrawInfo.fTempSurfaceDesc,
                                                  SkBackingFit::kApprox,
                                                  SkBudgeted::kYes);
@@ -328,7 +337,7 @@ bool GrContext::writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpa
     if (tempProxy) {
         sk_sp<GrFragmentProcessor> fp;
         if (applyPremulToSrc) {
-            fp = this->createUPMToPMEffect(tempProxy, SkMatrix::I());
+            fp = fContext->createUPMToPMEffect(tempProxy, SkMatrix::I());
             fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), tempDrawInfo.fSwizzle);
             // If premultiplying was the only reason for the draw, fall back to a straight write.
             if (!fp) {
@@ -341,7 +350,7 @@ bool GrContext::writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpa
         }
         if (tempProxy) {
             if (!fp) {
-                fp = GrSimpleTextureEffect::Make(this->resourceProvider(), tempProxy, nullptr,
+                fp = GrSimpleTextureEffect::Make(fContext->resourceProvider(), tempProxy, nullptr,
                                                  SkMatrix::I());
                 fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), tempDrawInfo.fSwizzle);
 
@@ -350,9 +359,9 @@ bool GrContext::writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpa
                 }
             }
             if (tempProxy->priv().hasPendingIO()) {
-                this->contextPriv().flush(tempProxy.get());
+                this->flush(tempProxy.get());
             }
-            GrTexture* texture = tempProxy->instantiate(this->resourceProvider());
+            GrTexture* texture = tempProxy->instantiate(fContext->resourceProvider());
             if (!texture) {
                 return false;
             }
@@ -367,9 +376,9 @@ bool GrContext::writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpa
                 buffer = tmpPixels.get();
                 applyPremulToSrc = false;
             }
-            if (!fGpu->writePixels(texture, 0, 0, width, height,
-                                   tempDrawInfo.fWriteConfig, buffer,
-                                   rowBytes)) {
+            if (!fContext->fGpu->writePixels(texture, 0, 0, width, height,
+                                             tempDrawInfo.fWriteConfig, buffer,
+                                             rowBytes)) {
                 return false;
             }
             SkMatrix matrix;
@@ -380,8 +389,7 @@ bool GrContext::writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpa
             GrRenderTarget* renderTarget = surface->asRenderTarget();
             SkASSERT(renderTarget);
             sk_sp<GrRenderTargetContext> renderTargetContext(
-                this->contextPriv().makeWrappedRenderTargetContext(sk_ref_sp(renderTarget),
-                                                                   nullptr));
+                this->makeWrappedRenderTargetContext(sk_ref_sp(renderTarget), nullptr));
             if (!renderTargetContext) {
                 return false;
             }
@@ -394,7 +402,7 @@ bool GrContext::writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpa
                                           nullptr);
 
             if (kFlushWrites_PixelOp & pixelOpsFlags) {
-                this->contextPriv().flushSurfaceWrites(renderTargetContext->asRenderTargetProxy());
+                this->flushSurfaceWrites(renderTargetContext->asRenderTargetProxy());
             }
         }
     }
@@ -410,24 +418,31 @@ bool GrContext::writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpa
             buffer = tmpPixels.get();
             applyPremulToSrc = false;
         }
-        return fGpu->writePixels(surface, left, top, width, height, srcConfig, buffer, rowBytes);
+        return fContext->fGpu->writePixels(surface, left, top, width, height, srcConfig,
+                                           buffer, rowBytes);
     }
     return true;
 }
 
-bool GrContext::readSurfacePixels(GrSurface* src, SkColorSpace* srcColorSpace,
-                                  int left, int top, int width, int height,
-                                  GrPixelConfig dstConfig, SkColorSpace* dstColorSpace,
-                                  void* buffer, size_t rowBytes, uint32_t flags) {
+bool GrContextPriv::readSurfacePixels(GrSurfaceProxy* srcProxy, SkColorSpace* srcColorSpace,
+                                      int left, int top, int width, int height,
+                                      GrPixelConfig dstConfig, SkColorSpace* dstColorSpace,
+                                      void* buffer, size_t rowBytes, uint32_t flags) {
     // TODO: Color space conversion
 
-    ASSERT_SINGLE_OWNER
-    RETURN_FALSE_IF_ABANDONED
-    ASSERT_OWNED_RESOURCE(src);
-    SkASSERT(src);
-    GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::readSurfacePixels");
+    ASSERT_SINGLE_OWNER_PRIV
+    RETURN_FALSE_IF_ABANDONED_PRIV
+    ASSERT_OWNED_PROXY_PRIV(srcProxy);
+    SkASSERT(srcProxy);
+    GR_AUDIT_TRAIL_AUTO_FRAME(&fContext->fAuditTrail, "GrContextPriv::readSurfacePixels");
+
+    // MDB TODO: delay this instantiation until later in the method
+    GrSurface* src = srcProxy->instantiate(fContext->resourceProvider());
+    if (!src) {
+        return false;
+    }
 
-    this->testPMConversionsIfNecessary(flags);
+    fContext->testPMConversionsIfNecessary(flags);
 
     // Adjust the params so that if we wind up using an intermediate surface we've already done
     // all the trimming and the temporary can be the min size required.
@@ -438,7 +453,7 @@ bool GrContext::readSurfacePixels(GrSurface* src, SkColorSpace* srcColorSpace,
     }
 
     if (!(kDontFlush_PixelOpsFlag & flags) && src->surfacePriv().hasPendingWrite()) {
-        this->contextPriv().flush(nullptr); // MDB TODO: tighten this
+        this->flush(nullptr); // MDB TODO: tighten this
     }
 
     bool unpremul = SkToBool(kUnpremul_PixelOpsFlag & flags);
@@ -454,18 +469,17 @@ bool GrContext::readSurfacePixels(GrSurface* src, SkColorSpace* srcColorSpace,
     GrGpu::DrawPreference drawPreference = GrGpu::kNoDraw_DrawPreference;
     // Don't prefer to draw for the conversion (and thereby access a texture from the cache) when
     // we've already determined that there isn't a roundtrip preserving conversion processor pair.
-    if (unpremul && this->validPMUPMConversionExists(src->config())) {
+    if (unpremul && fContext->validPMUPMConversionExists(src->config())) {
         drawPreference = GrGpu::kCallerPrefersDraw_DrawPreference;
     }
 
     GrGpu::ReadPixelTempDrawInfo tempDrawInfo;
-    if (!fGpu->getReadPixelsInfo(src, width, height, rowBytes, dstConfig, &drawPreference,
-                                 &tempDrawInfo)) {
+    if (!fContext->fGpu->getReadPixelsInfo(src, width, height, rowBytes, dstConfig,
+                                           &drawPreference, &tempDrawInfo)) {
         return false;
     }
 
-    sk_sp<GrSurface> surfaceToRead(SkRef(src));
-    sk_sp<GrTextureProxy> drawnProxy;
+    sk_sp<GrSurfaceProxy> proxyToRead = sk_ref_sp(srcProxy);
     bool didTempDraw = false;
     if (GrGpu::kNoDraw_DrawPreference != drawPreference) {
         if (SkBackingFit::kExact == tempDrawInfo.fTempSurfaceFit) {
@@ -478,7 +492,7 @@ bool GrContext::readSurfacePixels(GrSurface* src, SkColorSpace* srcColorSpace,
         // TODO: Need to decide the semantics of this function for color spaces. Do we support
         // conversion to a passed-in color space? For now, specifying nullptr means that this
         // path will do no conversion, so it will match the behavior of the non-draw path.
-        sk_sp<GrRenderTargetContext> tempRTC = this->makeRenderTargetContext(
+        sk_sp<GrRenderTargetContext> tempRTC = fContext->makeRenderTargetContext(
                                                            tempDrawInfo.fTempSurfaceFit,
                                                            tempDrawInfo.fTempSurfaceDesc.fWidth,
                                                            tempDrawInfo.fTempSurfaceDesc.fHeight,
@@ -488,10 +502,10 @@ bool GrContext::readSurfacePixels(GrSurface* src, SkColorSpace* srcColorSpace,
                                                            tempDrawInfo.fTempSurfaceDesc.fOrigin);
         if (tempRTC) {
             SkMatrix textureMatrix = SkMatrix::MakeTrans(SkIntToScalar(left), SkIntToScalar(top));
-            sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(sk_ref_sp(src->asTexture()));
+            sk_sp<GrTextureProxy> proxy = sk_ref_sp(srcProxy->asTextureProxy());
             sk_sp<GrFragmentProcessor> fp;
             if (unpremul) {
-                fp = this->createPMToUPMEffect(proxy, textureMatrix);
+                fp = fContext->createPMToUPMEffect(proxy, textureMatrix);
                 fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), tempDrawInfo.fSwizzle);
                 if (fp) {
                     unpremul = false; // we no longer need to do this on CPU after the read back.
@@ -502,7 +516,7 @@ bool GrContext::readSurfacePixels(GrSurface* src, SkColorSpace* srcColorSpace,
                 }
             }
             if (!fp && tempRTC) {
-                fp = GrSimpleTextureEffect::Make(this->resourceProvider(), std::move(proxy),
+                fp = GrSimpleTextureEffect::Make(fContext->resourceProvider(), std::move(proxy),
                                                  nullptr, textureMatrix);
                 fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), tempDrawInfo.fSwizzle);
             }
@@ -514,8 +528,7 @@ bool GrContext::readSurfacePixels(GrSurface* src, SkColorSpace* srcColorSpace,
                 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
                 tempRTC->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), rect,
                                   nullptr);
-                drawnProxy = tempRTC->asTextureProxyRef();
-                surfaceToRead = sk_ref_sp(drawnProxy->instantiate(this->resourceProvider()));
+                proxyToRead = tempRTC->asTextureProxyRef();
                 left = 0;
                 top = 0;
                 didTempDraw = true;
@@ -523,6 +536,11 @@ bool GrContext::readSurfacePixels(GrSurface* src, SkColorSpace* srcColorSpace,
         }
     }
 
+    if (!proxyToRead) {
+        return false;
+    }
+
+    GrSurface* surfaceToRead = proxyToRead->instantiate(fContext->resourceProvider());
     if (!surfaceToRead) {
         return false;
     }
@@ -532,11 +550,11 @@ bool GrContext::readSurfacePixels(GrSurface* src, SkColorSpace* srcColorSpace,
     }
     GrPixelConfig configToRead = dstConfig;
     if (didTempDraw) {
-        this->contextPriv().flushSurfaceWrites(drawnProxy.get());
+        this->flushSurfaceWrites(proxyToRead.get());
         configToRead = tempDrawInfo.fReadConfig;
     }
-    if (!fGpu->readPixels(surfaceToRead.get(), left, top, width, height, configToRead, buffer,
-                          rowBytes)) {
+    if (!fContext->fGpu->readPixels(surfaceToRead, left, top, width, height, configToRead,
+                                    buffer, rowBytes)) {
         return false;
     }
 
@@ -815,7 +833,7 @@ sk_sp<GrRenderTargetContext> GrContext::makeRenderTargetContext(SkBackingFit fit
 
     sk_sp<GrTexture> tex;
     if (SkBackingFit::kExact == fit) {
-        tex.reset(this->resourceProvider()->createTexture(desc, budgeted));
+        tex = this->resourceProvider()->createTexture(desc, budgeted);
     } else {
         tex.reset(this->resourceProvider()->createApproxTexture(desc, 0));
     }
@@ -878,7 +896,7 @@ void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) {
 
 void GrContext::testPMConversionsIfNecessary(uint32_t flags) {
     ASSERT_SINGLE_OWNER
-    if (SkToBool(kUnpremul_PixelOpsFlag & flags)) {
+    if (SkToBool(GrContextPriv::kUnpremul_PixelOpsFlag & flags)) {
         if (!fDidTestPMConversions) {
             test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion);
             fDidTestPMConversions = true;
index 0f77ec2d4c87b30f3ba4bce039d7c45cbaddd1e9..369e8e7ff9eb3d700142610ff6d71e79e0b08517 100644 (file)
@@ -96,6 +96,68 @@ public:
      */
     void prepareSurfaceForExternalIO(GrSurfaceProxy*);
 
+   /**
+    * These flags can be used with the read/write pixels functions below.
+    */
+    enum PixelOpsFlags {
+        /** The GrContext will not be flushed before the surface read or write. This means that
+            the read or write may occur before previous draws have executed. */
+        kDontFlush_PixelOpsFlag = 0x1,
+        /** Any surface writes should be flushed to the backend 3D API after the surface operation
+            is complete */
+        kFlushWrites_PixelOp = 0x2,
+        /** The src for write or dst read is unpremultiplied. This is only respected if both the
+            config src and dst configs are an RGBA/BGRA 8888 format. */
+        kUnpremul_PixelOpsFlag  = 0x4,
+    };
+
+    /**
+     * Reads a rectangle of pixels from a surface.
+     * @param surface       the surface to read from.
+     * @param srcColorSpace color space of the surface
+     * @param left          left edge of the rectangle to read (inclusive)
+     * @param top           top edge of the rectangle to read (inclusive)
+     * @param width         width of rectangle to read in pixels.
+     * @param height        height of rectangle to read in pixels.
+     * @param config        the pixel config of the destination buffer
+     * @param dstColorSpace color space of the destination buffer
+     * @param buffer        memory to read the rectangle into.
+     * @param rowBytes      number of bytes bewtween consecutive rows. Zero means rows are tightly
+     *                      packed.
+     * @param pixelOpsFlags see PixelOpsFlags enum above.
+     *
+     * @return true if the read succeeded, false if not. The read can fail because of an unsupported
+     *         pixel configs
+     */
+    bool readSurfacePixels(GrSurfaceProxy* src, SkColorSpace* srcColorSpace,
+                           int left, int top, int width, int height,
+                           GrPixelConfig config, SkColorSpace* dstColorSpace, void* buffer,
+                           size_t rowBytes = 0,
+                           uint32_t pixelOpsFlags = 0);
+
+    /**
+     * Writes a rectangle of pixels to a surface.
+     * @param surface       the surface to write to.
+     * @param dstColorSpace color space of the surface
+     * @param left          left edge of the rectangle to write (inclusive)
+     * @param top           top edge of the rectangle to write (inclusive)
+     * @param width         width of rectangle to write in pixels.
+     * @param height        height of rectangle to write in pixels.
+     * @param config        the pixel config of the source buffer
+     * @param srcColorSpace color space of the source buffer
+     * @param buffer        memory to read pixels from
+     * @param rowBytes      number of bytes between consecutive rows. Zero
+     *                      means rows are tightly packed.
+     * @param pixelOpsFlags see PixelOpsFlags enum above.
+     * @return true if the write succeeded, false if not. The write can fail because of an
+     *         unsupported combination of surface and src configs.
+     */
+    bool writeSurfacePixels(GrSurfaceProxy* src, SkColorSpace* dstColorSpace,
+                            int left, int top, int width, int height,
+                            GrPixelConfig config, SkColorSpace* srcColorSpace, const void* buffer,
+                            size_t rowBytes,
+                            uint32_t pixelOpsFlags = 0);
+
 private:
     explicit GrContextPriv(GrContext* context) : fContext(context) {}
     GrContextPriv(const GrContextPriv&); // unimpl
index 8ef09a4a3c1c98fe9abe119108a2c73364022191..76a67c083e6a61c42bdfbbb1bccc4846f736f9b5 100644 (file)
@@ -8,6 +8,7 @@
 #include "GrRenderTargetContext.h"
 #include "GrAppliedClip.h"
 #include "GrColor.h"
+#include "GrContextPriv.h"
 #include "GrDrawingManager.h"
 #include "GrFixedClip.h"
 #include "GrGpuResourcePriv.h"
@@ -162,18 +163,14 @@ bool GrRenderTargetContext::onReadPixels(const SkImageInfo& dstInfo, void* dstBu
 
     // TODO: this seems to duplicate code in SkImage_Gpu::onReadPixels
     if (kUnpremul_SkAlphaType == dstInfo.alphaType()) {
-        flags |= GrContext::kUnpremul_PixelOpsFlag;
+        flags |= GrContextPriv::kUnpremul_PixelOpsFlag;
     }
 
-    // Deferral of the VRAM resources must end in this instance anyway
-    sk_sp<GrRenderTarget> rt(
-                        sk_ref_sp(fRenderTargetProxy->instantiate(fContext->resourceProvider())));
-    if (!rt) {
-        return false;
-    }
-
-    return rt->readPixels(this->getColorSpace(), x, y, dstInfo.width(), dstInfo.height(),
-                          config, dstInfo.colorSpace(), dstBuffer, dstRowBytes, flags);
+    return fContext->contextPriv().readSurfacePixels(fRenderTargetProxy.get(),
+                                                     this->getColorSpace(), x, y,
+                                                     dstInfo.width(), dstInfo.height(), config,
+                                                     dstInfo.colorSpace(),
+                                                     dstBuffer, dstRowBytes, flags);
 }
 
 // TODO: move this (and GrTextureContext::onReadPixels) to GrSurfaceContext?
@@ -185,18 +182,14 @@ bool GrRenderTargetContext::onWritePixels(const SkImageInfo& srcInfo, const void
         return false;
     }
     if (kUnpremul_SkAlphaType == srcInfo.alphaType()) {
-        flags |= GrContext::kUnpremul_PixelOpsFlag;
-    }
-
-    // Deferral of the VRAM resources must end in this instance anyway
-    sk_sp<GrRenderTarget> rt(
-                        sk_ref_sp(fRenderTargetProxy->instantiate(fContext->resourceProvider())));
-    if (!rt) {
-        return false;
+        flags |= GrContextPriv::kUnpremul_PixelOpsFlag;
     }
 
-    return rt->writePixels(this->getColorSpace(), x, y, srcInfo.width(), srcInfo.height(),
-                           config, srcInfo.colorSpace(), srcBuffer, srcRowBytes, flags);
+    return fContext->contextPriv().writeSurfacePixels(fRenderTargetProxy.get(),
+                                                      this->getColorSpace(), x, y,
+                                                      srcInfo.width(), srcInfo.height(),
+                                                      config, srcInfo.colorSpace(),
+                                                      srcBuffer, srcRowBytes, flags);
 }
 
 
@@ -1787,7 +1780,7 @@ void GrRenderTargetContext::setupDstTexture(GrRenderTarget* rt, const GrClip& cl
         desc.fHeight = rt->height();
         dstPoint = {copyRect.fLeft, copyRect.fTop};
         dstOffset = {0, 0};
-        copy.reset(fContext->resourceProvider()->createTexture(desc, SkBudgeted::kYes, kFlags));
+        copy = fContext->resourceProvider()->createTexture(desc, SkBudgeted::kYes, kFlags);
     } else {
         desc.fWidth = copyRect.width();
         desc.fHeight = copyRect.height();
index 42f5e29d71906ac19c4bf7b847d6229b9ca13f01..0cb71c50efce57bb23d912ff38826f0b10b82206 100644 (file)
@@ -10,6 +10,7 @@
 #include "GrBuffer.h"
 #include "GrCaps.h"
 #include "GrContext.h"
+#include "GrContextPriv.h"
 #include "GrGpu.h"
 #include "GrPathRendering.h"
 #include "GrRenderTarget.h"
@@ -47,9 +48,13 @@ bool GrResourceProvider::IsFunctionallyExact(GrSurfaceProxy* proxy) {
     return proxy->priv().isExact() || (SkIsPow2(proxy->width()) && SkIsPow2(proxy->height()));
 }
 
-GrTexture* GrResourceProvider::createMipMappedTexture(const GrSurfaceDesc& desc,
-                                                      SkBudgeted budgeted, const GrMipLevel* texels,
-                                                      int mipLevelCount, uint32_t flags,
+// MDB TODO: this should probably be a factory on GrSurfaceProxy
+sk_sp<GrTextureProxy> GrResourceProvider::createMipMappedTexture(
+                                                      const GrSurfaceDesc& desc,
+                                                      SkBudgeted budgeted,
+                                                      const GrMipLevel* texels,
+                                                      int mipLevelCount,
+                                                      uint32_t flags,
                                                       SkDestinationSurfaceColorMode mipColorMode) {
     ASSERT_SINGLE_OWNER
 
@@ -74,17 +79,19 @@ GrTexture* GrResourceProvider::createMipMappedTexture(const GrSurfaceDesc& desc,
     if (!GrPixelConfigIsCompressed(desc.fConfig)) {
         if (mipLevelCount < 2) {
             flags |= kExact_Flag | kNoCreate_Flag;
-            if (GrTexture* texture = this->refScratchTexture(desc, flags)) {
+            sk_sp<GrTexture> tex(this->refScratchTexture(desc, flags));
+            if (tex) {
+                sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(tex);
                 if (!mipLevelCount ||
-                    texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
-                                         texels[0].fPixels, texels[0].fRowBytes)) {
+                    fGpu->getContext()->contextPriv().writeSurfacePixels(
+                                proxy.get(), nullptr, 0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
+                                nullptr, texels[0].fPixels, texels[0].fRowBytes)) {
                     if (SkBudgeted::kNo == budgeted) {
-                        texture->resourcePriv().makeUnbudgeted();
+                        tex->resourcePriv().makeUnbudgeted();
                     }
-                    texture->texturePriv().setMipColorMode(mipColorMode);
-                    return texture;
+                    tex->texturePriv().setMipColorMode(mipColorMode);
+                    return proxy;
                 }
-                texture->unref();
             }
         }
     }
@@ -93,25 +100,34 @@ GrTexture* GrResourceProvider::createMipMappedTexture(const GrSurfaceDesc& desc,
     for (int i = 0; i < mipLevelCount; ++i) {
         texelsShallowCopy.push_back(texels[i]);
     }
-    GrTexture* texture = fGpu->createTexture(desc, budgeted, texelsShallowCopy);
-    if (texture) {
-        texture->texturePriv().setMipColorMode(mipColorMode);
+    sk_sp<GrTexture> tex(fGpu->createTexture(desc, budgeted, texelsShallowCopy));
+    if (tex) {
+        tex->texturePriv().setMipColorMode(mipColorMode);
     }
-    return texture;
+
+    return GrSurfaceProxy::MakeWrapped(std::move(tex));
 }
 
-GrTexture* GrResourceProvider::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
-                                             const void* srcData, size_t rowBytes, uint32_t flags) {
-    GrMipLevel tempTexels;
-    GrMipLevel* texels = nullptr;
-    int levelCount = 0;
-    if (srcData) {
-        tempTexels.fPixels = srcData;
-        tempTexels.fRowBytes = rowBytes;
-        texels = &tempTexels;
-        levelCount = 1;
-    }
-    return this->createMipMappedTexture(desc, budgeted, texels, levelCount, flags);
+sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
+                                                   uint32_t flags) {
+    if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
+        !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
+        return nullptr;
+    }
+
+    if (!GrPixelConfigIsCompressed(desc.fConfig)) {
+        flags |= kExact_Flag | kNoCreate_Flag;
+        sk_sp<GrTexture> tex(this->refScratchTexture(desc, flags));
+        if (tex) {
+            if (SkBudgeted::kNo == budgeted) {
+                tex->resourcePriv().makeUnbudgeted();
+            }
+            return tex;
+        }
+    }
+
+    sk_sp<GrTexture> tex(fGpu->createTexture(desc, budgeted));
+    return tex;
 }
 
 GrTexture* GrResourceProvider::createApproxTexture(const GrSurfaceDesc& desc, uint32_t flags) {
index a4abd723eab39032bbcd00b1b8df881f2422bc5b..5cb64e092e5eaa53cbf8233783191d71bf4e131c 100644 (file)
@@ -47,29 +47,12 @@ public:
      * @param texels        A contiguous array of mipmap levels
      * @param mipLevelCount The amount of elements in the texels array
      */
-    GrTexture* createMipMappedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
-                                      const GrMipLevel* texels, int mipLevelCount,
-                                      uint32_t flags = 0,
-                                      SkDestinationSurfaceColorMode mipColorMode =
+    sk_sp<GrTextureProxy> createMipMappedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
+                                                 const GrMipLevel* texels, int mipLevelCount,
+                                                 uint32_t flags = 0,
+                                                 SkDestinationSurfaceColorMode mipColorMode =
                                                         SkDestinationSurfaceColorMode::kLegacy);
 
-    /**
-     * This function is a shim which creates a SkTArray<GrMipLevel> of size 1.
-     * It then calls createTexture with that SkTArray.
-     *
-     * @param srcData   Pointer to the pixel values (optional).
-     * @param rowBytes  The number of bytes between rows of the texture. Zero
-     *                  implies tightly packed rows. For compressed pixel configs, this
-     *                  field is ignored.
-     */
-    GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, const void* srcData,
-                             size_t rowBytes, uint32_t flags = 0);
-
-    /** Shortcut for creating a texture with no initial data to upload. */
-    GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, uint32_t flags = 0) {
-        return this->createTexture(desc, budgeted, nullptr, 0, flags);
-    }
-
     /** Assigns a unique key to the texture. The texture will be findable via this key using
     findTextureByUniqueKey(). If an existing texture has this key, it's key will be removed. */
     void assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy*);
@@ -86,6 +69,11 @@ public:
      */
     GrTexture* createApproxTexture(const GrSurfaceDesc&, uint32_t flags);
 
+    /** Create an exact fit texture with no initial data to upload.
+     */
+    sk_sp<GrTexture> createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
+                                   uint32_t flags = 0);
+
     ///////////////////////////////////////////////////////////////////////////
     // Wrapped Backend Surfaces
 
index 49753af8f92e8a9c756108d0ef828f39bc7be164..4c9e3b4c1e38f0b69bba9aac7cddf77259ebd216 100644 (file)
@@ -139,30 +139,6 @@ bool GrSurfacePriv::AdjustWritePixelParams(int surfaceWidth,
 
 //////////////////////////////////////////////////////////////////////////////
 
-bool GrSurface::writePixels(SkColorSpace* dstColorSpace, int left, int top, int width, int height,
-                            GrPixelConfig config, SkColorSpace* srcColorSpace, const void* buffer,
-                            size_t rowBytes, uint32_t pixelOpsFlags) {
-    // go through context so that all necessary flushing occurs
-    GrContext* context = this->getContext();
-    if (nullptr == context) {
-        return false;
-    }
-    return context->writeSurfacePixels(this, dstColorSpace, left, top, width, height, config,
-                                       srcColorSpace, buffer, rowBytes, pixelOpsFlags);
-}
-
-bool GrSurface::readPixels(SkColorSpace* srcColorSpace, int left, int top, int width, int height,
-                           GrPixelConfig config, SkColorSpace* dstColorSpace, void* buffer,
-                           size_t rowBytes, uint32_t pixelOpsFlags) {
-    // go through context so that all necessary flushing occurs
-    GrContext* context = this->getContext();
-    if (nullptr == context) {
-        return false;
-    }
-    return context->readSurfacePixels(this, srcColorSpace, left, top, width, height, config,
-                                      dstColorSpace, buffer, rowBytes, pixelOpsFlags);
-}
-
 bool GrSurface::hasPendingRead() const {
     const GrTexture* thisTex = this->asTexture();
     if (thisTex && thisTex->internalHasPendingRead()) {
index 2506540bf8fd9225284309b5b5a6c5bcee405c62..c243086f4743abac66985521808382c89ecb2ae4 100644 (file)
@@ -46,7 +46,7 @@ GrSurface* GrSurfaceProxy::instantiate(GrResourceProvider* resourceProvider) {
     if (SkBackingFit::kApprox == fFit) {
         fTarget = resourceProvider->createApproxTexture(fDesc, fFlags);
     } else {
-        fTarget = resourceProvider->createTexture(fDesc, fBudgeted, fFlags);
+        fTarget = resourceProvider->createTexture(fDesc, fBudgeted, fFlags).release();
     }
     if (!fTarget) {
         return nullptr;
@@ -216,9 +216,16 @@ sk_sp<GrTextureProxy> GrSurfaceProxy::MakeDeferred(GrResourceProvider* resourceP
                                                    const void* srcData,
                                                    size_t rowBytes) {
     if (srcData) {
-        // If we have srcData, for now, we create a wrapped GrTextureProxy
-        sk_sp<GrTexture> tex(resourceProvider->createTexture(desc, budgeted, srcData, rowBytes));
-        return GrSurfaceProxy::MakeWrapped(std::move(tex));
+        GrMipLevel tempTexels;
+        GrMipLevel* texels = nullptr;
+        int levelCount = 0;
+        if (srcData) {
+            tempTexels.fPixels = srcData;
+            tempTexels.fRowBytes = rowBytes;
+            texels = &tempTexels;
+            levelCount = 1;
+        }
+        return resourceProvider->createMipMappedTexture(desc, budgeted, texels, levelCount);
     }
 
     return GrSurfaceProxy::MakeDeferred(resourceProvider, desc, SkBackingFit::kExact, budgeted);
index 00cc97cf53feadd228a9e02bd545983aaccca3e0..f9462907956aa2d29e71ad7a663abb34c8ef8ff6 100644 (file)
@@ -120,17 +120,14 @@ bool GrTextureContext::onReadPixels(const SkImageInfo& dstInfo, void* dstBuffer,
 
     // TODO: this seems to duplicate code in SkImage_Gpu::onReadPixels
     if (kUnpremul_SkAlphaType == dstInfo.alphaType()) {
-        flags |= GrContext::kUnpremul_PixelOpsFlag;
+        flags |= GrContextPriv::kUnpremul_PixelOpsFlag;
     }
 
-    // Deferral of the VRAM resources must end in this instance anyway
-    sk_sp<GrTexture> tex(sk_ref_sp(fTextureProxy->instantiate(fContext->resourceProvider())));
-    if (!tex) {
-        return false;
-    }
-
-    return tex->readPixels(this->getColorSpace(), x, y, dstInfo.width(), dstInfo.height(),
-                           config, dstInfo.colorSpace(), dstBuffer, dstRowBytes, flags);
+    return fContext->contextPriv().readSurfacePixels(fTextureProxy.get(), this->getColorSpace(),
+                                                     x, y, dstInfo.width(), dstInfo.height(),
+                                                     config,
+                                                     dstInfo.colorSpace(), dstBuffer, dstRowBytes,
+                                                     flags);
 }
 
 // TODO: move this (and GrRenderTargetContext::onReadPixels) to GrSurfaceContext?
@@ -143,15 +140,12 @@ bool GrTextureContext::onWritePixels(const SkImageInfo& srcInfo, const void* src
         return false;
     }
     if (kUnpremul_SkAlphaType == srcInfo.alphaType()) {
-        flags |= GrContext::kUnpremul_PixelOpsFlag;
-    }
-
-    // Deferral of the VRAM resources must end in this instance anyway
-    sk_sp<GrTexture> tex(sk_ref_sp(fTextureProxy->instantiate(fContext->resourceProvider())));
-    if (!tex) {
-        return false;
+        flags |= GrContextPriv::kUnpremul_PixelOpsFlag;
     }
 
-    return tex->writePixels(this->getColorSpace(), x, y, srcInfo.width(), srcInfo.height(),
-                            config, srcInfo.colorSpace(), srcBuffer, srcRowBytes, flags);
+    return fContext->contextPriv().writeSurfacePixels(fTextureProxy.get(), this->getColorSpace(),
+                                                      x, y, srcInfo.width(), srcInfo.height(),
+                                                      config,
+                                                      srcInfo.colorSpace(), srcBuffer, srcRowBytes,
+                                                      flags);
 }
index 56ce5455a7e37d810d35d484ef7785f41886ee45..5f21e1d479b8322576b8d88c39edbe2311a9aabf 100644 (file)
@@ -241,13 +241,11 @@ sk_sp<GrTextureProxy> GrGenerateMipMapsAndUploadToTextureProxy(GrContext* ctx,
         texels[i].fRowBytes = generatedMipLevel.fPixmap.rowBytes();
     }
 
-    sk_sp<GrTexture> tex(ctx->resourceProvider()->createMipMappedTexture(desc,
-                                                                         SkBudgeted::kYes,
-                                                                         texels.get(),
-                                                                         mipLevelCount,
-                                                                         0, colorMode));
-
-    return GrSurfaceProxy::MakeWrapped(std::move(tex));
+    return ctx->resourceProvider()->createMipMappedTexture(desc,
+                                                           SkBudgeted::kYes,
+                                                           texels.get(),
+                                                           mipLevelCount,
+                                                           0, colorMode);
 }
 
 sk_sp<GrTextureProxy> GrUploadMipMapToTextureProxy(GrContext* ctx, const SkImageInfo& info,
@@ -259,11 +257,9 @@ sk_sp<GrTextureProxy> GrUploadMipMapToTextureProxy(GrContext* ctx, const SkImage
     }
 
     const GrCaps* caps = ctx->caps();
-    sk_sp<GrTexture> tex(ctx->resourceProvider()->createMipMappedTexture(
-                                                           GrImageInfoToSurfaceDesc(info, *caps),
+    return ctx->resourceProvider()->createMipMappedTexture(GrImageInfoToSurfaceDesc(info, *caps),
                                                            SkBudgeted::kYes, texels,
-                                                           mipLevelCount, 0, colorMode));
-    return GrSurfaceProxy::MakeWrapped(std::move(tex));
+                                                           mipLevelCount, 0, colorMode);
 }
 
 sk_sp<GrTextureProxy> GrRefCachedBitmapTextureProxy(GrContext* ctx,
index 5785be2a26438745fb4276e4869ed708961aead8..26ef5963c1ab8ec0a8ca0478731543187abd7c5a 100644 (file)
@@ -162,7 +162,7 @@ int GrTextureStripAtlas::lockRow(const SkBitmap& bitmap) {
         // that is not currently in use
         fTexContext->writePixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes(),
                                  0, rowNumber * fDesc.fRowHeight,
-                                 GrContext::kDontFlush_PixelOpsFlag);
+                                 GrContextPriv::kDontFlush_PixelOpsFlag);
     }
 
     SkASSERT(rowNumber >= 0);
index 9c9aaa79b324c2b3eb8cba176f1c614d13f997ba..08c2e0d0cac2f9849f3380fc1d0940ac6b786526 100644 (file)
@@ -191,7 +191,7 @@ bool SkImage_Gpu::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size
     uint32_t flags = 0;
     if (kUnpremul_SkAlphaType == rec.fInfo.alphaType() && kPremul_SkAlphaType == fAlphaType) {
         // let the GPU perform this transformation for us
-        flags = GrContext::kUnpremul_PixelOpsFlag;
+        flags = GrContextPriv::kUnpremul_PixelOpsFlag;
     }
 
     sk_sp<GrSurfaceContext> sContext = fContext->contextPriv().makeWrappedSurfaceContext(
index 193c37dd4a902b7dd48ae3463db1a36fa425aa5e..2d16fb2ff2d46ac9624cb9b6f8afa3eecb3ce294 100644 (file)
@@ -92,8 +92,7 @@ static sk_sp<SkSurface> create_gpu_surface_backend_texture_as_render_target(
     backingDesc.fOrigin = kDefault_GrSurfaceOrigin;
     backingDesc.fFlags = kRenderTarget_GrSurfaceFlag;
 
-    (*backingSurface)
-            .reset(context->resourceProvider()->createTexture(backingDesc, SkBudgeted::kNo));
+    *backingSurface = context->resourceProvider()->createTexture(backingDesc, SkBudgeted::kNo);
 
     GrBackendTextureDesc desc;
     desc.fConfig = config;
index 4214e4eebffad8dfcff458b4a94071a321a5a94e..5adc2e7892a42abae7c2fb872b727a72d3575d08 100644 (file)
@@ -17,6 +17,7 @@
 
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
+#include "GrContextPriv.h"
 #include "GrResourceProvider.h"
 #include "GrTexture.h"
 #include "SkHalf.h"
@@ -51,14 +52,18 @@ void runFPTest(skiatest::Reporter* reporter, GrContext* context,
         desc.fHeight = DEV_H;
         desc.fConfig = config;
         desc.fOrigin = 0 == origin ? kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
-        sk_sp<GrTexture> fpTexture(context->resourceProvider()->createTexture(
-            desc, SkBudgeted::kNo, controlPixelData.begin(), 0));
+        sk_sp<GrTextureProxy> fpProxy = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
+                                                                     desc, SkBudgeted::kNo,
+                                                                     controlPixelData.begin(), 0);
         // Floating point textures are NOT supported everywhere
-        if (nullptr == fpTexture) {
+        if (!fpProxy) {
             continue;
         }
-        REPORTER_ASSERT(reporter,
-                        fpTexture->readPixels(0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer.begin(), 0));
+        bool result = context->contextPriv().readSurfacePixels(fpProxy.get(), nullptr,
+                                                               0, 0, DEV_W, DEV_H,
+                                                               desc.fConfig, nullptr,
+                                                               readBuffer.begin(), 0);
+        REPORTER_ASSERT(reporter, result);
         REPORTER_ASSERT(reporter,
                         0 == memcmp(readBuffer.begin(), controlPixelData.begin(), readBuffer.bytes()));
     }
index 489aec13910898788414dfbd27f47ff20374af4c..5400d92bc62abe7482793171b657d03118c166a5 100644 (file)
@@ -285,28 +285,30 @@ bool GrDrawingManager::ProgramUnitTest(GrContext*, int) { return true; }
 bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) {
     GrDrawingManager* drawingManager = context->contextPriv().drawingManager();
 
+    sk_sp<GrTextureProxy> proxies[2];
+
     // setup dummy textures
     GrSurfaceDesc dummyDesc;
     dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag;
+    dummyDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
     dummyDesc.fConfig = kRGBA_8888_GrPixelConfig;
     dummyDesc.fWidth = 34;
     dummyDesc.fHeight = 18;
-    sk_sp<GrTexture> dummyTexture1(
-        context->resourceProvider()->createTexture(dummyDesc, SkBudgeted::kNo, nullptr, 0));
+    proxies[0] = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
+                                              dummyDesc, SkBudgeted::kNo, nullptr, 0);
     dummyDesc.fFlags = kNone_GrSurfaceFlags;
+    dummyDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
     dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
     dummyDesc.fWidth = 16;
     dummyDesc.fHeight = 22;
-    sk_sp<GrTexture> dummyTexture2(
-        context->resourceProvider()->createTexture(dummyDesc, SkBudgeted::kNo, nullptr, 0));
+    proxies[1] = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
+                                              dummyDesc, SkBudgeted::kNo, nullptr, 0);
 
-    if (!dummyTexture1 || ! dummyTexture2) {
+    if (!proxies[0] || !proxies[1]) {
         SkDebugf("Could not allocate dummy textures");
         return false;
     }
 
-    GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
-
     // dummy scissor state
     GrScissorState scissor;
 
@@ -326,7 +328,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) {
         std::unique_ptr<GrLegacyMeshDrawOp> op(GrRandomDrawOp(&random, context));
         SkASSERT(op);
 
-        GrProcessorTestData ptd(&random, context, renderTargetContext.get(), dummyTextures);
+        GrProcessorTestData ptd(&random, context, renderTargetContext.get(), proxies);
         set_random_color_coverage_stages(&grPaint, &ptd, maxStages);
         set_random_xpf(&grPaint, &ptd);
         bool snapToCenters = set_random_state(&grPaint, &random);
@@ -360,7 +362,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) {
         for (int j = 0; j < 10; ++j) {
             std::unique_ptr<GrLegacyMeshDrawOp> op(GrRandomDrawOp(&random, context));
             SkASSERT(op);
-            GrProcessorTestData ptd(&random, context, renderTargetContext.get(), dummyTextures);
+            GrProcessorTestData ptd(&random, context, renderTargetContext.get(), proxies);
             GrPaint grPaint;
             grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
 
index d98d0d042847e89a0870b25d3cce8899fa6865c0..97700b1a85ceef982ad8528638048b53d792791d 100644 (file)
@@ -27,11 +27,10 @@ DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) {
     desc.fWidth = 256;
     desc.fHeight = 256;
     desc.fSampleCnt = 0;
-    GrSurface* texRT1 = context->resourceProvider()->createTexture(
-            desc, SkBudgeted::kNo, nullptr, 0);
+    sk_sp<GrSurface> texRT1 = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo);
 
-    REPORTER_ASSERT(reporter, texRT1 == texRT1->asRenderTarget());
-    REPORTER_ASSERT(reporter, texRT1 == texRT1->asTexture());
+    REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asRenderTarget());
+    REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asTexture());
     REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) ==
                     texRT1->asTexture());
     REPORTER_ASSERT(reporter, texRT1->asRenderTarget() ==
@@ -40,10 +39,10 @@ DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) {
                     static_cast<GrSurface*>(texRT1->asTexture()));
 
     desc.fFlags = kNone_GrSurfaceFlags;
-    GrSurface* tex1 = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo, nullptr, 0);
+    sk_sp<GrTexture> tex1 = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo);
     REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget());
-    REPORTER_ASSERT(reporter, tex1 == tex1->asTexture());
-    REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1) == tex1->asTexture());
+    REPORTER_ASSERT(reporter, tex1.get() == tex1->asTexture());
+    REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1.get()) == tex1->asTexture());
 
     GrBackendObject backendTex = context->getGpu()->createTestingOnlyBackendTexture(
         nullptr, 256, 256, kRGBA_8888_GrPixelConfig);
@@ -66,8 +65,6 @@ DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) {
     REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
                     static_cast<GrSurface*>(texRT2->asTexture()));
 
-    texRT1->unref();
-    tex1->unref();
     context->getGpu()->deleteTestingOnlyBackendTexture(backendTex);
 }
 
index fe67925fda7c874da66a1c5fcd00c8a3a98ec63c..95ade044bdd0429bc96c010c86a2ec437e65b007 100644 (file)
@@ -181,18 +181,6 @@ DEF_TEST(ImageFilterCache_ImageBackedRaster, reporter) {
 #include "GrContext.h"
 #include "GrResourceProvider.h"
 
-static GrTexture* create_texture(GrContext* context) {
-    SkBitmap srcBM = create_bm();
-
-    GrSurfaceDesc desc;
-    desc.fConfig = kRGBA_8888_GrPixelConfig;
-    desc.fFlags  = kNone_GrSurfaceFlags;
-    desc.fWidth  = kFullSize;
-    desc.fHeight = kFullSize;
-
-    return context->resourceProvider()->createTexture(desc, SkBudgeted::kNo, srcBM.getPixels(), 0);
-}
-
 static sk_sp<GrTextureProxy> create_proxy(GrResourceProvider* resourceProvider) {
     SkBitmap srcBM = create_bm();
 
@@ -208,10 +196,16 @@ static sk_sp<GrTextureProxy> create_proxy(GrResourceProvider* resourceProvider)
                                         srcBM.rowBytes());
 }
 
-
 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ctxInfo) {
-    sk_sp<GrTexture> srcTexture(create_texture(ctxInfo.grContext()));
-    if (!srcTexture) {
+    GrContext* context = ctxInfo.grContext();
+
+    sk_sp<GrTextureProxy> srcProxy(create_proxy(context->resourceProvider()));
+    if (!srcProxy) {
+        return;
+    }
+
+    GrTexture* tex = srcProxy->instantiate(context->resourceProvider());
+    if (!tex) {
         return;
     }
 
@@ -222,8 +216,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ct
     backendDesc.fWidth = kFullSize;
     backendDesc.fHeight = kFullSize;
     backendDesc.fSampleCnt = 0;
-    backendDesc.fTextureHandle = srcTexture->getTextureHandle();
-    sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(ctxInfo.grContext(),
+    backendDesc.fTextureHandle = tex->getTextureHandle();
+    sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(context,
                                                      backendDesc,
                                                      kPremul_SkAlphaType));
     if (!srcImage) {
index 59bb38b02ac7549ba9105f89648164a4c36cdb61..f3e3482b071e272fe22146853dcd12ac25346751 100644 (file)
 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageStorageLoad, reporter, ctxInfo) {
     class TestFP : public GrFragmentProcessor {
     public:
-        static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTexture> texture, GrSLMemoryModel mm,
+        static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
+                                               sk_sp<GrTextureProxy> proxy,
+                                               GrSLMemoryModel mm,
                                                GrSLRestrict restrict) {
-            return sk_sp<GrFragmentProcessor>(new TestFP(std::move(texture), mm, restrict));
+            // MDB TODO: remove this once ImageStorageAccess is converted to GrTextureProxy
+            sk_sp<GrTexture> tex(sk_ref_sp(proxy->instantiate(resourceProvider)));
+            if (!tex) {
+                return nullptr;
+            }
+
+            return sk_sp<GrFragmentProcessor>(new TestFP(std::move(tex), mm, restrict));
         }
 
         const char* name() const override { return "Image Load Test FP"; }
@@ -127,15 +135,17 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageStorageLoad, reporter, ctxInfo) {
                     continue;
                 }
                 desc.fConfig = test.fConfig;
-                sk_sp<GrTexture> imageStorageTexture(context->resourceProvider()->createTexture(
-                        desc, SkBudgeted::kYes, test.fData.get(), 0));
+                sk_sp<GrTextureProxy> imageStorageTexture =
+                    GrSurfaceProxy::MakeDeferred(context->resourceProvider(), desc,
+                                                 SkBudgeted::kYes, test.fData.get(), 0);
 
                 sk_sp<GrRenderTargetContext> rtContext =
                     context->makeRenderTargetContext(SkBackingFit::kExact, kS, kS,
                                                      kRGBA_8888_GrPixelConfig, nullptr);
                 GrPaint paint;
                 paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
-                paint.addColorFragmentProcessor(TestFP::Make(imageStorageTexture, mm, restrict));
+                paint.addColorFragmentProcessor(TestFP::Make(context->resourceProvider(),
+                                                             imageStorageTexture, mm, restrict));
                 rtContext->drawPaint(GrNoClip(), std::move(paint), SkMatrix::I());
                 std::unique_ptr<uint32_t[]> readData(new uint32_t[kS * kS]);
                 SkImageInfo info = SkImageInfo::Make(kS, kS, kRGBA_8888_SkColorType,
index 8ef57318ed5716cfb227a86f55e732b503619285..eacd0617a2dde06fb9b9bbf979239c754cbd78ca 100644 (file)
@@ -10,6 +10,7 @@
 #if SK_SUPPORT_GPU
 #include "GrClip.h"
 #include "GrContext.h"
+#include "GrContextPriv.h"
 #include "GrRenderTargetContext.h"
 #include "GrResourceProvider.h"
 #include "GrTexture.h"
@@ -64,7 +65,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
         levels[1].fPixels = testData.get();
         levels[1].fRowBytes = (kS / 2) * sizeof(int32_t);
 
-        sk_sp<GrTexture> temp(context->resourceProvider()->createMipMappedTexture(desc,
+        sk_sp<GrTextureProxy> temp(context->resourceProvider()->createMipMappedTexture(
+                                                                                  desc,
                                                                                   SkBudgeted::kYes,
                                                                                   levels, 2));
         REPORTER_ASSERT(reporter, !temp);
@@ -80,21 +82,21 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
         return;
     }
 
-    GrTexture* texture = proxy->instantiate(context->resourceProvider());
-    REPORTER_ASSERT(reporter, texture);
-    if (!texture) {
-        return;
-    }
-
     std::unique_ptr<int32_t[]> readData(new int32_t[kS * kS]);
     // Test that reading to a non-integer config fails.
     {
-        bool success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_GrPixelConfig, readData.get());
+        bool success = context->contextPriv().readSurfacePixels(proxy.get(), nullptr,
+                                                                0, 0, kS, kS,
+                                                                kRGBA_8888_GrPixelConfig,
+                                                                nullptr, readData.get());
         REPORTER_ASSERT(reporter, !success);
     }
     {
         std::unique_ptr<uint16_t[]> halfData(new uint16_t[4 * kS * kS]);
-        bool success = texture->readPixels(0, 0, kS, kS, kRGBA_half_GrPixelConfig, halfData.get());
+        bool success = context->contextPriv().readSurfacePixels(proxy.get(), nullptr,
+                                                                0, 0, kS, kS,
+                                                                kRGBA_half_GrPixelConfig,
+                                                                nullptr, halfData.get());
         REPORTER_ASSERT(reporter, !success);
     }
     {
@@ -102,8 +104,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
         // we don't support. Right now this test is counting on GR_RGBA_INTEGER/GL_BYTE being the
         // implementation-dependent second format).
         sk_bzero(readData.get(), sizeof(int32_t) * kS * kS);
-        bool success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig,
-                                           readData.get());
+        bool success = context->contextPriv().readSurfacePixels(proxy.get(), nullptr,
+                                                                0, 0, kS, kS,
+                                                                kRGBA_8888_sint_GrPixelConfig,
+                                                                nullptr, readData.get());
         REPORTER_ASSERT(reporter, success);
         if (success) {
             check_pixels(reporter, kS, kS, testData.get(), readData.get(), "readPixels");
@@ -111,8 +115,12 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
     }
     {
         // readPixels should fail if we attempt to use the unpremul flag with an integer texture.
-        bool success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig,
-                                           readData.get(), 0, GrContext::kUnpremul_PixelOpsFlag);
+        bool success = context->contextPriv().readSurfacePixels(
+                                                proxy.get(), nullptr,
+                                                0, 0, kS, kS,
+                                                kRGBA_8888_sint_GrPixelConfig,
+                                                nullptr, readData.get(), 0,
+                                                GrContextPriv::kUnpremul_PixelOpsFlag);
         REPORTER_ASSERT(reporter, !success);
     }
 
@@ -125,16 +133,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
             return;
         }
 
-        GrSurface* copySurface = dstContext->asTextureProxy()->instantiate(
-                                                                    context->resourceProvider());
-        REPORTER_ASSERT(reporter, copySurface);
-        if (!copySurface) {
-            return;
-        }
-
         sk_bzero(readData.get(), sizeof(int32_t) * kS * kS);
-        bool success = copySurface->readPixels(0, 0, kS, kS,
-                                               kRGBA_8888_sint_GrPixelConfig, readData.get());
+        bool success = context->contextPriv().readSurfacePixels(dstContext->asSurfaceProxy(),
+                                                                nullptr, 0, 0, kS, kS,
+                                                                kRGBA_8888_sint_GrPixelConfig,
+                                                                nullptr, readData.get());
         REPORTER_ASSERT(reporter, success);
         if (success) {
             check_pixels(reporter, kS, kS, testData.get(), readData.get(), "copyIntegerToInteger");
@@ -168,27 +171,39 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
 
     {
         // Can't write pixels from a non-int config.
-        bool success = texture->writePixels(0, 0, kS/2, kS/2, kRGBA_8888_GrPixelConfig,
-                                            bottomRightQuarter, kRowBytes);
+        bool success = context->contextPriv().writeSurfacePixels(proxy.get(), nullptr,
+                                                                 0, 0, kS/2, kS/2,
+                                                                 kRGBA_8888_GrPixelConfig, nullptr,
+                                                                 bottomRightQuarter, kRowBytes);
         REPORTER_ASSERT(reporter, !success);
     }
     {
         // Can't use unpremul flag.
-        bool success = texture->writePixels(0, 0, kS/2, kS/2, kRGBA_8888_sint_GrPixelConfig,
+        bool success = context->contextPriv().writeSurfacePixels(
+                                            proxy.get(), nullptr,
+                                            0, 0, kS/2, kS/2,
+                                            kRGBA_8888_sint_GrPixelConfig,
+                                            nullptr,
                                             bottomRightQuarter, kRowBytes,
-                                            GrContext::kUnpremul_PixelOpsFlag);
+                                            GrContextPriv::kUnpremul_PixelOpsFlag);
         REPORTER_ASSERT(reporter, !success);
     }
     {
-        bool success = texture->writePixels(0, 0, kS/2, kS/2, kRGBA_8888_sint_GrPixelConfig,
-                                            bottomRightQuarter, kRowBytes);
+        bool success = context->contextPriv().writeSurfacePixels(proxy.get(), nullptr,
+                                                                 0, 0, kS/2, kS/2,
+                                                                 kRGBA_8888_sint_GrPixelConfig,
+                                                                 nullptr,
+                                                                 bottomRightQuarter, kRowBytes);
         REPORTER_ASSERT(reporter, success);
         if (!success) {
             return;
         }
 
         sk_bzero(readData.get(), sizeof(int32_t) * kS * kS);
-        success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig, readData.get());
+        success = context->contextPriv().readSurfacePixels(proxy.get(), nullptr,
+                                                           0, 0, kS, kS,
+                                                           kRGBA_8888_sint_GrPixelConfig,
+                                                           nullptr, readData.get(), 0);
         REPORTER_ASSERT(reporter, success);
         if (!success) {
             return;
@@ -219,10 +234,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
         expectedData.get()[i] = ((0xFF * a) << 24) | ((0xFF * b) << 16) |
                                 ((0xFF * g) << 8) | (0xFF * r);
     }
-    texture->writePixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig, testData.get());
-
-    sk_sp<GrTextureProxy> intTextureProxy = GrSurfaceProxy::MakeWrapped(sk_ref_sp(texture));
-    texture = nullptr; // unused from here on out
+    context->contextPriv().writeSurfacePixels(proxy.get(), nullptr,
+                                              0, 0, kS, kS,
+                                              kRGBA_8888_sint_GrPixelConfig, nullptr,
+                                              testData.get(), 0);
 
     sk_sp<GrRenderTargetContext> rtContext = context->makeRenderTargetContext(
             SkBackingFit::kExact, kS, kS, kRGBA_8888_GrPixelConfig, nullptr);
@@ -238,7 +253,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
 
     for (auto filter : kNamedFilters) {
         sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(context->resourceProvider(),
-                                                                  intTextureProxy, nullptr,
+                                                                  proxy, nullptr,
                                                                   SkMatrix::I(),
                                                                   filter.fMode));
         REPORTER_ASSERT(reporter, fp);
index 7a51651e7fbff47fb58af5bb7098430ed87e402e..35d9dfc3c5418a315f9b73d5d7400d53006531d6 100644 (file)
@@ -15,6 +15,7 @@
 
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
+#include "GrContextPriv.h"
 #include "GrResourceProvider.h"
 #include "GrTexture.h"
 
@@ -116,10 +117,13 @@ void runTest(skiatest::Reporter* reporter, GrContext* context,
         desc.fHeight = DEV_H;
         desc.fConfig = config;
         desc.fOrigin = 0 == origin ? kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
-        sk_sp<GrTexture> fpTexture(context->resourceProvider()->createTexture(
-            desc, SkBudgeted::kNo, controlPixelData.begin(), 0));
-        SkASSERT(fpTexture);
-        fpTexture->readPixels(0, 0, DEV_W, DEV_H, kRGBA_8888_GrPixelConfig, readBuffer.begin(), 0);
+        sk_sp<GrTextureProxy> fpProxy = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
+                                                                     desc, SkBudgeted::kNo,
+                                                                     controlPixelData.begin(), 0);
+        SkASSERT(fpProxy);
+        context->contextPriv().readSurfacePixels(fpProxy.get(), nullptr, 0, 0, DEV_W, DEV_H,
+                                                 kRGBA_8888_GrPixelConfig, nullptr,
+                                                 readBuffer.begin(), 0);
         if (kRGBA_4444_GrPixelConfig == config) {
             check_4444(reporter, controlPixelData, readBuffer);
         } else {
index b8691f268972555a4e9a6e411026d5ecebaa3fd7..3eb4e16f20f54ae11b6f5b2825e97ae18e55bd65 100644 (file)
@@ -146,12 +146,12 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(ProcessorRefTest, reporter, ctxInfo) {
                                                                       desc,
                                                                       SkBackingFit::kExact,
                                                                       SkBudgeted::kYes));
-            sk_sp<GrTexture> texture2(
-                    context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
-            sk_sp<GrTexture> texture3(
-                    context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
-            sk_sp<GrTexture> texture4(
-                    context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
+            sk_sp<GrTexture> texture2 =
+                    context->resourceProvider()->createTexture(desc, SkBudgeted::kYes);
+            sk_sp<GrTexture> texture3 =
+                    context->resourceProvider()->createTexture(desc, SkBudgeted::kYes);
+            sk_sp<GrTexture> texture4 =
+                    context->resourceProvider()->createTexture(desc, SkBudgeted::kYes);
             sk_sp<GrBuffer> buffer(texelBufferSupport
                                            ? context->resourceProvider()->createBuffer(
                                                      1024, GrBufferType::kTexel_GrBufferType,
@@ -298,6 +298,8 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
     desc.fFlags = kRenderTarget_GrSurfaceFlag;
     desc.fConfig = kRGBA_8888_GrPixelConfig;
 
+    sk_sp<GrTextureProxy> proxies[2];
+
     // Put premul data into the RGBA texture that the test FPs can optionally use.
     std::unique_ptr<GrColor[]> rgbaData(new GrColor[256 * 256]);
     for (int y = 0; y < 256; ++y) {
@@ -306,8 +308,8 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
                     texel_color(random.nextULessThan(256), random.nextULessThan(256));
         }
     }
-    sk_sp<GrTexture> tex0(context->resourceProvider()->createTexture(
-            desc, SkBudgeted::kYes, rgbaData.get(), 256 * sizeof(GrColor)));
+    proxies[0] = GrSurfaceProxy::MakeDeferred(context->resourceProvider(), desc, SkBudgeted::kYes,
+                                              rgbaData.get(), 256 * sizeof(GrColor));
 
     // Put random values into the alpha texture that the test FPs can optionally use.
     desc.fConfig = kAlpha_8_GrPixelConfig;
@@ -317,10 +319,9 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
             alphaData.get()[256 * y + x] = random.nextULessThan(256);
         }
     }
-    sk_sp<GrTexture> tex1(context->resourceProvider()->createTexture(desc, SkBudgeted::kYes,
-                                                                     alphaData.get(), 256));
-    GrTexture* textures[] = {tex0.get(), tex1.get()};
-    GrProcessorTestData testData(&random, context, rtc.get(), textures);
+    proxies[1] = GrSurfaceProxy::MakeDeferred(context->resourceProvider(), desc, SkBudgeted::kYes,
+                                              alphaData.get(), 256);
+    GrProcessorTestData testData(&random, context, rtc.get(), proxies);
 
     // Use a different array of premul colors for the output of the fragment processor that preceeds
     // the fragment processor under test.
index 648ae1d6c8e37176ddcca64658fc3811ef2c2aad..7657e28f5aa9dbf66cb5e2013b81286ba0f8e189 100644 (file)
@@ -137,7 +137,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
                                 if (SkBackingFit::kApprox == fit) {
                                     tex.reset(provider->createApproxTexture(desc, 0));
                                 } else {
-                                    tex.reset(provider->createTexture(desc, budgeted));
+                                    tex = provider->createTexture(desc, budgeted);
                                 }
 
                                 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(
@@ -170,7 +170,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
                                 if (SkBackingFit::kApprox == fit) {
                                     tex.reset(provider->createApproxTexture(desc, 0));
                                 } else {
-                                    tex.reset(provider->createTexture(desc, budgeted));
+                                    tex = provider->createTexture(desc, budgeted);
                                 }
 
                                 sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(provider,
@@ -249,7 +249,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
                     // Internal offscreen render target.
                     if (renderable) {
                         desc.fFlags = kRenderTarget_GrSurfaceFlag;
-                        tex.reset(provider->createTexture(desc, budgeted));
+                        tex = provider->createTexture(desc, budgeted);
                         sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget()));
 
                         sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(rt));
@@ -264,7 +264,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
                     if (!tex) {
                         SkASSERT(kNone_GrSurfaceFlags == desc.fFlags );
                         desc.fSampleCnt = 0;
-                        tex.reset(provider->createTexture(desc, budgeted));
+                        tex = provider->createTexture(desc, budgeted);
                     }
 
                     sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(tex));
index 774f0af06aa53e4f053cd52e288df09294deb5df..c67e62b0909b6be4cd61bb36e13609e980799bde 100644 (file)
@@ -16,6 +16,7 @@
 
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
+#include "GrContextPriv.h"
 #include "GrResourceProvider.h"
 #include "SkGr.h"
 #endif
@@ -123,11 +124,16 @@ static void fill_src_canvas(SkCanvas* canvas) {
 }
 
 #if SK_SUPPORT_GPU
-static void fill_src_texture(GrTexture* texture) {
+static void fill_src_texture(GrContext* context, GrTextureProxy* proxy) {
     SkBitmap bmp = make_src_bitmap();
     bmp.lockPixels();
-    texture->writePixels(0, 0, DEV_W, DEV_H, kSkia8888_GrPixelConfig, bmp.getPixels(),
-                         bmp.rowBytes());
+
+    SkDEBUGCODE(bool result =) context->contextPriv().writeSurfacePixels(
+                                                            proxy, nullptr,
+                                                            0, 0, DEV_W, DEV_H,
+                                                            kSkia8888_GrPixelConfig, nullptr,
+                                                            bmp.getPixels(), bmp.rowBytes());
+    SkASSERT(result);
     bmp.unlockPixels();
 }
 #endif
@@ -436,8 +442,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Gpu, reporter, ctxInfo) {
 #endif
 
 #if SK_SUPPORT_GPU
-static void test_readpixels_texture(skiatest::Reporter* reporter, GrTexture* texture) {
-    fill_src_texture(texture);
+static void test_readpixels_texture(skiatest::Reporter* reporter,
+                                    GrContext* context, sk_sp<GrTextureProxy> proxy) {
+    fill_src_texture(context, proxy.get());
     for (size_t rect = 0; rect < SK_ARRAY_COUNT(gReadPixelsTestRects); ++rect) {
         const SkIRect& srcRect = gReadPixelsTestRects[rect];
         for (BitmapInit bmi = kFirstBitmapInit; bmi <= kLast_BitmapInit; bmi = nextBMI(bmi)) {
@@ -452,16 +459,18 @@ static void test_readpixels_texture(skiatest::Reporter* reporter, GrTexture* tex
                 // Try doing the read directly from a non-renderable texture
                 if (startsWithPixels) {
                     fill_dst_bmp_with_init_data(&bmp);
-                    GrPixelConfig dstConfig =
-                            SkImageInfo2GrPixelConfig(bmp.info(), *texture->getContext()->caps());
+                    GrPixelConfig dstConfig = SkImageInfo2GrPixelConfig(bmp.info(),
+                                                                        *context->caps());
                     uint32_t flags = 0;
                     if (gReadPixelsConfigs[c].fAlphaType == kUnpremul_SkAlphaType) {
-                        flags = GrContext::kUnpremul_PixelOpsFlag;
+                        flags = GrContextPriv::kUnpremul_PixelOpsFlag;
                     }
                     bmp.lockPixels();
-                    bool success = texture->readPixels(srcRect.fLeft, srcRect.fTop, bmp.width(),
-                                                       bmp.height(), dstConfig, bmp.getPixels(),
-                                                       bmp.rowBytes(), flags);
+                    bool success = context->contextPriv().readSurfacePixels(
+                                                       proxy.get(), nullptr,
+                                                       srcRect.fLeft, srcRect.fTop, bmp.width(),
+                                                       bmp.height(), dstConfig, nullptr,
+                                                       bmp.getPixels(), bmp.rowBytes(), flags);
                     bmp.unlockPixels();
                     check_read(reporter, bmp, srcRect.fLeft, srcRect.fTop,
                                success, true,
@@ -481,9 +490,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) {
             desc.fHeight = DEV_H;
             desc.fConfig = kSkia8888_GrPixelConfig;
             desc.fOrigin = origin;
-            sk_sp<GrTexture> texture(ctxInfo.grContext()->resourceProvider()->createTexture(desc,
-                SkBudgeted::kNo));
-            test_readpixels_texture(reporter, texture.get());
+            sk_sp<GrTexture> texture =
+                    ctxInfo.grContext()->resourceProvider()->createTexture(desc, SkBudgeted::kNo);
+            test_readpixels_texture(reporter, ctxInfo.grContext(),
+                                    GrSurfaceProxy::MakeWrapped(std::move(texture)));
         }
     }
 }
index ac34b9dc327c14b4bb44efebedc4417c2f996171..2a68191a2da3082a6c45c844f0e315d7cbf3b516 100644 (file)
@@ -159,9 +159,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
                     rgbaData[y * X_SIZE + x] = GrColorPackRGBA(6, 7, 8, alphaData[y * X_SIZE + x]);
                 }
             }
-            sk_sp<GrTexture> texture(
-                context->resourceProvider()->createTexture(desc, SkBudgeted::kNo, rgbaData, 0));
-            if (!texture) {
+            sk_sp<GrTextureProxy> proxy =
+                GrSurfaceProxy::MakeDeferred(context->resourceProvider(), desc, SkBudgeted::kNo,
+                                             rgbaData, 0);
+            if (!proxy) {
                 // We always expect to be able to create a RGBA texture
                 if (!rt  && kRGBA_8888_GrPixelConfig == desc.fConfig) {
                     ERRORF(reporter, "Failed to create RGBA texture.");
@@ -177,8 +178,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
                 memset(readback.get(), kClearValue, nonZeroRowBytes * Y_SIZE);
 
                 // read the texture back
-                bool result = texture->readPixels(0, 0, desc.fWidth, desc.fHeight,
-                                                  kAlpha_8_GrPixelConfig,
+                bool result = context->contextPriv().readSurfacePixels(
+                                                  proxy.get(), nullptr,
+                                                  0, 0, desc.fWidth, desc.fHeight,
+                                                  kAlpha_8_GrPixelConfig, nullptr,
                                                   readback.get(), rowBytes);
                 REPORTER_ASSERT_MESSAGE(reporter, result, "8888 readPixels failed");
 
index a7a2b4540d4985b99978ea97cc5153f7e9b5816e..fcf3fe88f39ba7bda014c822181bdd3c8193f323 100644 (file)
@@ -184,7 +184,7 @@ DEF_GPUTEST_FOR_CONTEXTS(ResourceCacheStencilBuffers, &is_rendering_and_not_angl
             smallMSAART0 && smallMSAART0->asRenderTarget() &&
             smallMSAART0->asRenderTarget()->numColorSamples() < 8) {
             smallMSAADesc.fSampleCnt = 8;
-            smallMSAART1.reset(resourceProvider->createTexture(smallMSAADesc, SkBudgeted::kNo));
+            smallMSAART1 = resourceProvider->createTexture(smallMSAADesc, SkBudgeted::kNo);
             sk_sp<GrTexture> smallMSAART1(
                 resourceProvider->createTexture(smallMSAADesc, SkBudgeted::kNo));
             if (smallMSAART1 && smallMSAART1->asRenderTarget()) {
@@ -1514,13 +1514,13 @@ static sk_sp<GrTexture> make_normal_texture(GrResourceProvider* provider,
     desc.fConfig = kRGBA_8888_GrPixelConfig;
     desc.fSampleCnt = sampleCnt;
 
-    return sk_sp<GrTexture>(provider->createTexture(desc, SkBudgeted::kYes));
+    return provider->createTexture(desc, SkBudgeted::kYes);
 }
 
-static sk_sp<GrTexture> make_mipmap_texture(GrResourceProvider* provider,
-                                            GrSurfaceFlags flags,
-                                            int width, int height,
-                                            int sampleCnt) {
+static sk_sp<GrTextureProxy> make_mipmap_proxy(GrResourceProvider* provider,
+                                               GrSurfaceFlags flags,
+                                               int width, int height,
+                                               int sampleCnt) {
     SkBitmap bm;
 
     bm.allocN32Pixels(width, height, true);
@@ -1552,8 +1552,7 @@ static sk_sp<GrTexture> make_mipmap_texture(GrResourceProvider* provider,
     desc.fSampleCnt = sampleCnt;
     desc.fIsMipMapped = true;
 
-    return sk_sp<GrTexture>(provider->createMipMappedTexture(desc, SkBudgeted::kYes,
-                                                             texels.get(), mipLevelCount));
+    return provider->createMipMappedTexture(desc, SkBudgeted::kYes, texels.get(), mipLevelCount);
 }
 
 // Exercise GrSurface::gpuMemorySize for different combos of MSAA, RT-only,
@@ -1564,42 +1563,49 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GPUMemorySize, reporter, ctxInfo) {
 
     static const int kSize = 64;
 
-    sk_sp<GrTexture> tex;
-
     // Normal versions
-    tex = make_normal_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 0);
-    size_t size = tex->gpuMemorySize();
-    REPORTER_ASSERT(reporter, kSize*kSize*4 == size);
+    {
+        sk_sp<GrTexture> tex;
+
+        tex = make_normal_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 0);
+        size_t size = tex->gpuMemorySize();
+        REPORTER_ASSERT(reporter, kSize*kSize*4 == size);
+
+        if (context->caps()->maxSampleCount() >= 4) {
+            tex = make_normal_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 4);
+            size = tex->gpuMemorySize();
+            REPORTER_ASSERT(reporter, kSize*kSize*4 == size ||    // msaa4 failed
+                                      kSize*kSize*4*4 == size ||  // auto-resolving
+                                      kSize*kSize*4*5 == size);   // explicit resolve buffer
+        }
 
-    if (context->caps()->maxSampleCount() >= 4) {
-        tex = make_normal_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 4);
+        tex = make_normal_texture(provider, kNone_GrSurfaceFlags, kSize, kSize, 0);
         size = tex->gpuMemorySize();
-        REPORTER_ASSERT(reporter, kSize*kSize*4 == size ||    // msaa4 failed
-                                  kSize*kSize*4*4 == size ||  // auto-resolving
-                                  kSize*kSize*4*5 == size);   // explicit resolve buffer
+        REPORTER_ASSERT(reporter, kSize*kSize*4 == size);
     }
 
-    tex = make_normal_texture(provider, kNone_GrSurfaceFlags, kSize, kSize, 0);
-    size = tex->gpuMemorySize();
-    REPORTER_ASSERT(reporter, kSize*kSize*4 == size);
 
     // Mipmapped versions
-    tex = make_mipmap_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 0);
-    size = tex->gpuMemorySize();
-    REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
+    {
+        sk_sp<GrTextureProxy> proxy;
 
-    if (context->caps()->maxSampleCount() >= 4) {
-        tex = make_mipmap_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 4);
-        size = tex->gpuMemorySize();
-        REPORTER_ASSERT(reporter, 
+        proxy = make_mipmap_proxy(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 0);
+        size_t size = proxy->gpuMemorySize();
+        REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
+
+        if (context->caps()->maxSampleCount() >= 4) {
+            proxy = make_mipmap_proxy(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 4);
+            size = proxy->gpuMemorySize();
+            REPORTER_ASSERT(reporter,
                             kSize*kSize*4+(kSize*kSize*4)/3 == size ||   // msaa4 failed
                             kSize*kSize*4*4+(kSize*kSize*4)/3 == size || // auto-resolving
                             kSize*kSize*4*5+(kSize*kSize*4)/3 == size);  // explicit resolve buffer
-    }
+        }
 
-    tex = make_mipmap_texture(provider, kNone_GrSurfaceFlags, kSize, kSize, 0);
-    size = tex->gpuMemorySize();
-    REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
+        proxy = make_mipmap_proxy(provider, kNone_GrSurfaceFlags, kSize, kSize, 0);
+        size = proxy->gpuMemorySize();
+        REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
+    }
 }
 
 #endif
index 9729774cd0aab53334d2f317e3c6bba639cfb69a..e3087e639e7f05ddf1dd43af0cb1663c535562f4 100644 (file)
@@ -169,6 +169,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SRGBReadWritePixels, reporter, ctxInfo) {
                                                  kPremul_SkAlphaType);
     GrSurfaceDesc desc;
     desc.fFlags = kRenderTarget_GrSurfaceFlag;
+    desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
     desc.fWidth = kW;
     desc.fHeight = kH;
     desc.fConfig = kSRGBA_8888_GrPixelConfig;
index d0349614f1727feb20ed45050cd4f51ac509286a..aca7509748c0ea52a5e22bfeb832590a00c9f126 100644 (file)
@@ -80,6 +80,8 @@ void test_copy_from_surface(skiatest::Reporter* reporter, GrContext* context,
         }
 
         copyDstDesc.fFlags = flags;
+        copyDstDesc.fOrigin = (kNone_GrSurfaceFlags == flags) ? kTopLeft_GrSurfaceOrigin
+                                                              : kBottomLeft_GrSurfaceOrigin;
 
         sk_sp<GrSurfaceContext> dstContext(GrSurfaceProxy::TestCopy(context, copyDstDesc, proxy));
 
@@ -106,6 +108,8 @@ void test_copy_to_surface(skiatest::Reporter* reporter, GrResourceProvider* reso
 
     for (auto flags : { kNone_GrSurfaceFlags, kRenderTarget_GrSurfaceFlag }) {
         copySrcDesc.fFlags = flags;
+        copySrcDesc.fOrigin = (kNone_GrSurfaceFlags == flags) ? kTopLeft_GrSurfaceOrigin
+                                                              : kBottomLeft_GrSurfaceOrigin;
 
         sk_sp<GrTextureProxy> src(GrSurfaceProxy::MakeDeferred(resourceProvider,
                                                                copySrcDesc,
index 8b6a56bd9f687f9c9cbab90deec59e16010ba85f..50fc84fda805996960b90c7e1061c0ebf479ecf0 100644 (file)
@@ -12,6 +12,7 @@
 #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS && defined(SK_VULKAN)
 
 #include "GrContextFactory.h"
+#include "GrContextPriv.h"
 #include "GrTest.h"
 #include "Test.h"
 #include "vk/GrVkGpu.h"
@@ -82,51 +83,60 @@ void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, GrPixe
     surfDesc.fHeight = kHeight;
     surfDesc.fConfig = config;
     surfDesc.fSampleCnt = 0;
-    GrTexture* tex0 = gpu->createTexture(surfDesc, SkBudgeted::kNo, srcBuffer, 0);
+    sk_sp<GrTexture> tex0(gpu->createTexture(surfDesc, SkBudgeted::kNo, srcBuffer, 0));
     if (tex0) {
         REPORTER_ASSERT(reporter, canCreate);
-        gpu->readPixels(tex0, 0, 0, kWidth, kHeight, config, dstBuffer, 0);
+        gpu->readPixels(tex0.get(), 0, 0, kWidth, kHeight, config, dstBuffer, 0);
         REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
                                                                          dstBuffer,
                                                                          config,
                                                                          kWidth,
                                                                          kHeight));
 
-        tex0->writePixels(2, 10, 10, 2, config, srcBuffer);
+        sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(tex0);
+
+        bool success = context->contextPriv().writeSurfacePixels(proxy.get(), nullptr,
+                                                                 2, 10, 10, 2,
+                                                                 config, nullptr, srcBuffer, 0);
+        REPORTER_ASSERT(reporter, success);
+
         memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor));
-        gpu->readPixels(tex0, 2, 10, 10, 2, config, dstBuffer, 0);
+        gpu->readPixels(tex0.get(), 2, 10, 10, 2, config, dstBuffer, 0);
         REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
                                                                          dstBuffer,
                                                                          config,
                                                                          10,
                                                                          2));
-
-        tex0->unref();
     } else {
         REPORTER_ASSERT(reporter, !canCreate);
     }
 
     surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
-    GrTexture* tex1 = gpu->createTexture(surfDesc, SkBudgeted::kNo, srcBuffer, 0);
+    sk_sp<GrTexture> tex1(gpu->createTexture(surfDesc, SkBudgeted::kNo, srcBuffer, 0));
     if (tex1) {
         REPORTER_ASSERT(reporter, canCreate);
-        gpu->readPixels(tex1, 0, 0, kWidth, kHeight, config, dstBuffer, 0);
+        gpu->readPixels(tex1.get(), 0, 0, kWidth, kHeight, config, dstBuffer, 0);
         REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
                                                                          dstBuffer,
                                                                          config,
                                                                          kWidth,
                                                                          kHeight));
 
-        tex1->writePixels(5, 4, 4, 5, config, srcBuffer);
+        sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(tex1);
+
+        bool success = context->contextPriv().writeSurfacePixels(proxy.get(), nullptr,
+                                                                 5, 4, 4, 5, config, nullptr,
+                                                                 srcBuffer, 0);
+        REPORTER_ASSERT(reporter, success);
+
         memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor));
-        gpu->readPixels(tex1, 5, 4, 4, 5, config, dstBuffer, 0);
+        gpu->readPixels(tex1.get(), 5, 4, 4, 5, config, dstBuffer, 0);
         REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
                                                                          dstBuffer,
                                                                          config,
                                                                          4,
                                                                          5));
 
-        tex1->unref();
     } else {
         REPORTER_ASSERT(reporter, !canCreate);
     }