Remove min texture size support
authorbsalomon <bsalomon@google.com>
Wed, 28 Oct 2015 15:37:44 +0000 (08:37 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 28 Oct 2015 15:37:44 +0000 (08:37 -0700)
BUG=skia:4524

Review URL: https://codereview.chromium.org/1430643002

12 files changed:
include/gpu/GrCaps.h
include/gpu/GrContextOptions.h
src/core/SkImageCacherator.cpp
src/gpu/GrCaps.cpp
src/gpu/GrGpu.cpp
src/gpu/GrTextureParamsAdjuster.cpp
src/gpu/GrTextureParamsAdjuster.h
src/gpu/GrTextureProvider.cpp
src/gpu/SkGr.cpp
src/gpu/gl/GrGLCaps.cpp
src/gpu/gl/GrGLGpu.cpp
src/image/SkImage_Gpu.cpp

index 0f376f9..811a74f 100644 (file)
@@ -189,8 +189,6 @@ public:
 
     int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
     int maxTextureSize() const { return fMaxTextureSize; }
-    /** 0 unless GPU has problems with small textures */
-    int minTextureSize() const { return fMinTextureSize; }
 
     // Will be 0 if MSAA is not supported
     int maxSampleCount() const { return fMaxSampleCount; }
@@ -265,7 +263,6 @@ protected:
 
     int fMaxRenderTargetSize;
     int fMaxTextureSize;
-    int fMinTextureSize;
     int fMaxSampleCount;
 
     // The first entry for each config is without msaa and the second is with.
index 6b93927..4b70105 100644 (file)
@@ -15,7 +15,6 @@ struct GrContextOptions {
         : fDrawPathToCompressedTexture(false)
         , fSuppressPrints(false)
         , fMaxTextureSizeOverride(SK_MaxS32)
-        , fMinTextureSizeOverride(0)
         , fSuppressDualSourceBlending(false)
         , fGeometryBufferMapThreshold(-1)
         , fUseDrawInsteadOfPartialRenderTargetWrite(false)
@@ -34,7 +33,6 @@ struct GrContextOptions {
         detected values. */
 
     int  fMaxTextureSizeOverride;
-    int  fMinTextureSizeOverride;
     bool fSuppressDualSourceBlending;
 
     /** the threshold in bytes above which we will use a buffer mapping API to map vertex and index
index 71afc0e..bf9bea0 100644 (file)
@@ -287,8 +287,6 @@ public:
     }
 
 protected:
-    GrTexture* peekOriginalTexture() override { return nullptr; }
-
     // TODO: consider overriding this, for the case where the underlying generator might be
     //       able to efficiently produce a "stretched" texture natively (e.g. picture-backed)
     //    GrTexture* generateTextureForParams(GrContext*, const SkGrStretch&) override;
@@ -309,10 +307,6 @@ protected:
         }
     }
 
-    bool getROBitmap(SkBitmap* bitmap) override {
-        return fCacher->lockAsBitmap(bitmap, fClient);
-    }
-
 private:
     SkImageCacherator*      fCacher;
     const SkImage*          fClient;
index cab44b9..4095f1a 100644 (file)
@@ -106,7 +106,6 @@ GrCaps::GrCaps(const GrContextOptions& options) {
 
     fMaxRenderTargetSize = 1;
     fMaxTextureSize = 1;
-    fMinTextureSize = 1;
     fMaxSampleCount = 0;
 
     memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
@@ -122,7 +121,6 @@ GrCaps::GrCaps(const GrContextOptions& options) {
 
 void GrCaps::applyOptionsOverrides(const GrContextOptions& options) {
     fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride);
-    fMinTextureSize = SkTMax(fMinTextureSize, options.fMinTextureSizeOverride);
 }
 
 static SkString map_flags_to_string(uint32_t flags) {
@@ -172,7 +170,6 @@ SkString GrCaps::dump() const {
     }
 
     r.appendf("Max Texture Size                   : %d\n", fMaxTextureSize);
-    r.appendf("Min Texture Size                   : %d\n", fMinTextureSize);
     r.appendf("Max Render Target Size             : %d\n", fMaxRenderTargetSize);
     r.appendf("Max Sample Count                   : %d\n", fMaxSampleCount);
 
index 48fc740..4970a63 100644 (file)
@@ -57,21 +57,11 @@ void GrGpu::contextAbandoned() {}
 
 bool GrGpu::makeCopyForTextureParams(int width, int height, const GrTextureParams& textureParams,
                                      GrTextureParamsAdjuster::CopyParams* copyParams) const {
-    bool doCopy = false;
     const GrCaps& caps = *this->caps();
     if (textureParams.isTiled() && !caps.npotTextureTileSupport() &&
         (!SkIsPow2(width) || !SkIsPow2(height))) {
-        doCopy = true;
-        copyParams->fWidth = GrNextPow2(SkTMax(width, caps.minTextureSize()));
-        copyParams->fHeight = GrNextPow2(SkTMax(height, caps.minTextureSize()));
-    } else if (width < caps.minTextureSize() || height < caps.minTextureSize()) {
-        // The small texture issues appear to be with tiling. Hence it seems ok to scale
-        // them up using the GPU. If issues persist we may need to CPU-stretch.
-        doCopy = true;
-        copyParams->fWidth = SkTMax(width, caps.minTextureSize());
-        copyParams->fHeight = SkTMax(height, caps.minTextureSize());
-    }
-    if (doCopy) {
+        copyParams->fWidth = GrNextPow2(width);
+        copyParams->fHeight = GrNextPow2(height);
         switch (textureParams.filterMode()) {
             case GrTextureParams::kNone_FilterMode:
                 copyParams->fFilter = GrTextureParams::kNone_FilterMode;
@@ -82,8 +72,9 @@ bool GrGpu::makeCopyForTextureParams(int width, int height, const GrTextureParam
                 copyParams->fFilter = GrTextureParams::kBilerp_FilterMode;
                 break;
         }
+        return true;
     }
-    return doCopy;
+    return false;
 }
 
 static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) {
index 9940f9e..ee3d135 100644 (file)
@@ -79,28 +79,6 @@ static GrTexture* copy_on_gpu(GrTexture* inputTexture, const CopyParams& copyPar
     return copy.detach();
 }
 
-static SkBitmap copy_on_cpu(const SkBitmap& bmp, const CopyParams& copyParams) {
-    SkBitmap stretched;
-    stretched.allocN32Pixels(copyParams.fWidth, copyParams.fHeight);
-    SkCanvas canvas(stretched);
-    SkPaint paint;
-    switch (copyParams.fFilter) {
-        case GrTextureParams::kNone_FilterMode:
-            paint.setFilterQuality(kNone_SkFilterQuality);
-            break;
-        case GrTextureParams::kBilerp_FilterMode:
-            paint.setFilterQuality(kLow_SkFilterQuality);
-            break;
-        case GrTextureParams::kMipMap_FilterMode:
-            paint.setFilterQuality(kMedium_SkFilterQuality);
-            break;
-    }
-    SkRect dstRect = SkRect::MakeWH(SkIntToScalar(copyParams.fWidth),
-                                    SkIntToScalar(copyParams.fHeight));
-    canvas.drawBitmapRect(bmp, dstRect, &paint);
-    return stretched;
-}
-
 GrTexture* GrTextureParamsAdjuster::refTextureForParams(GrContext* ctx,
                                                         const GrTextureParams& params) {
     CopyParams copyParams;
@@ -131,22 +109,9 @@ GrTexture* GrTextureParamsAdjuster::refTextureForParams(GrContext* ctx,
 
 GrTexture* GrTextureParamsAdjuster::generateTextureForParams(GrContext* ctx,
                                                              const CopyParams& copyParams) {
-    if ((this->width() < ctx->caps()->minTextureSize() ||
-         this->height() < ctx->caps()->minTextureSize()) && !this->peekOriginalTexture())
-    {
-        // we can't trust our ability to use HW to perform the stretch, so we request
-        // a raster instead, and perform the stretch on the CPU.
-        SkBitmap bitmap;
-        if (!this->getROBitmap(&bitmap)) {
-            return nullptr;
-        }
-        SkBitmap stretchedBmp = copy_on_cpu(bitmap, copyParams);
-        return GrUploadBitmapToTexture(ctx, stretchedBmp);
-    } else {
-        SkAutoTUnref<GrTexture> original(this->refOriginalTexture(ctx));
-        if (!original) {
-            return nullptr;
-        }
-        return copy_on_gpu(original, copyParams);
+    SkAutoTUnref<GrTexture> original(this->refOriginalTexture(ctx));
+    if (!original) {
+        return nullptr;
     }
+    return copy_on_gpu(original, copyParams);
 }
index c244aaf..bc08c71 100644 (file)
@@ -43,10 +43,6 @@ public:
     GrTexture* refTextureForParams(GrContext*, const GrTextureParams&);
 
 protected:
-    /** If the original is a inherently texture that can be returned for "free" then return it
-        without ref'ing it. Otherwise, return null. */
-    virtual GrTexture* peekOriginalTexture() = 0;
-
     /**
      *  Return the maker's "original" texture. It is the responsibility of the maker
      *  to make this efficient ... if the texture is being generated, the maker must handle
@@ -66,9 +62,8 @@ protected:
      *  Return a new (uncached) texture that is the stretch of the maker's original.
      *
      *  The base-class handles general logic for this, and only needs access to the following
-     *  methods:
-     *  - onRefOriginalTexture()
-     *  - onGetROBitmap()
+     *  method:
+     *  - refOriginalTexture()
      *
      *  Subclass may override this if they can handle creating the texture more directly than
      *  by copying.
@@ -82,13 +77,6 @@ protected:
      */
     virtual void didCacheCopy(const GrUniqueKey& copyKey) = 0;
 
-    /**
-     *  Some GPUs are unreliable w/ very small texture sizes. If we run into that case, this
-     *  method will be called (in service of onGenerateParamsTexture) to return a raster version
-     *  of the original texture.
-     */
-    virtual bool getROBitmap(SkBitmap*) = 0;
-
     /** Helper for creating a key for a copy from an original key. */
     static void MakeCopyKeyFromOrigKey(const GrUniqueKey& origKey,
                                        const CopyParams& copyParams,
index 26384ab..cb652f7 100644 (file)
@@ -70,10 +70,10 @@ GrTexture* GrTextureProvider::refScratchTexture(const GrSurfaceDesc& inDesc,
     if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_GrSurfaceFlag)) {
         if (!(kExact_ScratchTextureFlag & flags)) {
             // bin by pow2 with a reasonable min
-            const int minSize = SkTMin(16, fGpu->caps()->minTextureSize());
+            const int kMinSize = 16;
             GrSurfaceDesc* wdesc = desc.writable();
-            wdesc->fWidth  = SkTMax(minSize, GrNextPow2(desc->fWidth));
-            wdesc->fHeight = SkTMax(minSize, GrNextPow2(desc->fHeight));
+            wdesc->fWidth  = SkTMax(kMinSize, GrNextPow2(desc->fWidth));
+            wdesc->fHeight = SkTMax(kMinSize, GrNextPow2(desc->fHeight));
         }
 
         GrScratchKey key;
index 3c3f3e8..1ffd256 100644 (file)
@@ -217,11 +217,6 @@ static GrTexture* load_etc1_texture(GrContext* ctx, const SkBitmap &bm, GrSurfac
 GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bmp) {
     SkASSERT(!bmp.getTexture());
 
-    if (bmp.width() < ctx->caps()->minTextureSize() ||
-        bmp.height() < ctx->caps()->minTextureSize()) {
-        return nullptr;
-    }
-
     SkBitmap tmpBitmap;
     const SkBitmap* bitmap = &bmp;
 
@@ -291,8 +286,6 @@ public:
     }
 
 protected:
-    GrTexture* peekOriginalTexture() override { return fBitmap.getTexture();  }
-
     GrTexture* refOriginalTexture(GrContext* ctx) override {
         GrTexture* tex = fBitmap.getTexture();
         if (tex) {
@@ -324,12 +317,6 @@ protected:
         InstallInvalidator(copyKey, fBitmap.pixelRef());
     }
 
-    bool getROBitmap(SkBitmap* bitmap) override {
-        SkASSERT(!fBitmap.getTexture());
-        *bitmap = fBitmap;
-        return true;
-    }
-
 private:
     static void InstallInvalidator(const GrUniqueKey& key, SkPixelRef* pixelRef) {
         class Invalidator : public SkPixelRef::GenIDChangeListener {
index ec945ea..9879846 100644 (file)
@@ -424,11 +424,6 @@ void GrGLCaps::init(const GrContextOptions& contextOptions,
     // attachment, hence this min:
     fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
 
-    // This GPU seems to have problems when tiling small textures
-    if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
-        fMinTextureSize = 16;
-    }
-
     fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
 
     // Disable scratch texture reuse on Mali and Adreno devices
index feeac93..a0809c1 100644 (file)
@@ -1184,7 +1184,7 @@ void inline get_stencil_rb_sizes(const GrGLInterface* gl,
 }
 
 int GrGLGpu::getCompatibleStencilIndex(GrPixelConfig config) {
-    int size = this->caps()->minTextureSize();
+    static const int kSize = 16;
     if (kUnknownStencilIndex == fPixelConfigToStencilIndex[config]) {
         // Default to unsupported
         fPixelConfigToStencilIndex[config] = kUnsupportedStencilIndex;
@@ -1226,8 +1226,8 @@ int GrGLGpu::getCompatibleStencilIndex(GrPixelConfig config) {
         CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
         GL_ALLOC_CALL(this->glInterface(), TexImage2D(GR_GL_TEXTURE_2D,
                                                       0, internalFormat,
-                                                      size,
-                                                      size,
+                                                      kSize,
+                                                      kSize,
                                                       0,
                                                       externalFormat,
                                                       externalType,
@@ -1266,7 +1266,7 @@ int GrGLGpu::getCompatibleStencilIndex(GrPixelConfig config) {
             CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
             GL_ALLOC_CALL(this->glInterface(), RenderbufferStorage(GR_GL_RENDERBUFFER,
                                                                    sFmt.fInternalFormat,
-                                                                   size, size));
+                                                                   kSize, kSize));
             if (GR_GL_NO_ERROR == GR_GL_GET_ERROR(this->glInterface())) {
                 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
                                                 GR_GL_STENCIL_ATTACHMENT,
@@ -1818,8 +1818,8 @@ static bool read_pixels_pays_for_y_flip(GrRenderTarget* renderTarget, const GrGL
     }
 
     // If the read is really small or smaller than the min texture size, don't force a draw.
-    int minSize = SkTMax(32, caps.minTextureSize());
-    if (width < minSize || height < minSize) {
+    static const int kMinSize = 32;
+    if (width < kMinSize || height < kMinSize) {
         return false;
     }
 
@@ -1857,9 +1857,7 @@ bool GrGLGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height,
     tempDrawInfo->fTempSurfaceDesc.fHeight = height;
     tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0;
     tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU y-flip for TL.
-    tempDrawInfo->fUseExactScratch = this->glCaps().partialFBOReadIsSlow() &&
-                                     width >= this->caps()->minTextureSize() &&
-                                     height >= this->caps()->minTextureSize();
+    tempDrawInfo->fUseExactScratch = this->glCaps().partialFBOReadIsSlow();
 
     // Start off assuming that any temp draw should be to the readConfig, then check if that will
     // be inefficient.
index e5f3aee..8e5ce45 100644 (file)
@@ -87,8 +87,6 @@ public:
     {}
 
 protected:
-    GrTexture* peekOriginalTexture() override { return fOriginal; }
-
     GrTexture* refOriginalTexture(GrContext* ctx) override {
         return SkRef(fOriginal);
     }
@@ -101,10 +99,6 @@ protected:
         as_IB(fImage)->notifyAddedToCache();
     }
 
-    bool getROBitmap(SkBitmap* bitmap) override {
-        return as_IB(fImage)->getROPixels(bitmap);
-    }
-
 private:
     const SkImage*  fImage;
     GrTexture*      fOriginal;