Revert "Revert "Remove GrSurface::desc() method.""
authorBrian Salomon <bsalomon@google.com>
Thu, 18 May 2017 14:02:08 +0000 (10:02 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Thu, 18 May 2017 16:20:55 +0000 (16:20 +0000)
This reverts commit c96da1e51e1ca72d54dda49f32891bd41530ad31.

Bug: skia:
Change-Id: I8242400a137413c01c7ef614b4fa733be7dcf939
Reviewed-on: https://skia-review.googlesource.com/17311
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>

include/gpu/GrSurface.h
src/gpu/gl/GrGLGpu.cpp
src/gpu/gl/GrGLGpu.h
src/gpu/vk/GrVkGpu.cpp

index b6d1c50..6626765 100644 (file)
@@ -50,11 +50,6 @@ public:
     GrPixelConfig config() const { return fDesc.fConfig; }
 
     /**
-     * Return the descriptor describing the surface.
-     */
-    const GrSurfaceDesc& desc() const { return fDesc; }
-
-    /**
      * @return the texture associated with the surface, may be null.
      */
     virtual GrTexture* asTexture() { return nullptr; }
index d77ca71..51fef2c 100644 (file)
@@ -769,10 +769,12 @@ bool GrGLGpu::onWritePixels(GrSurface* surface,
     if (GrPixelConfigIsCompressed(glTex->config())) {
         // We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixels()
         SkASSERT(config == glTex->config());
-        success = this->uploadCompressedTexData(glTex->desc(), glTex->target(), texels,
+        success = this->uploadCompressedTexData(glTex->config(), glTex->width(), glTex->height(),
+                                                glTex->origin(), glTex->target(), texels,
                                                 kWrite_UploadType, left, top, width, height);
     } else {
-        success = this->uploadTexData(glTex->desc(), glTex->target(), kWrite_UploadType,
+        success = this->uploadTexData(glTex->config(), glTex->width(), glTex->height(),
+                                      glTex->origin(), glTex->target(), kWrite_UploadType,
                                       left, top, width, height, config, texels);
     }
 
@@ -808,8 +810,9 @@ bool GrGLGpu::onTransferPixels(GrSurface* surface,
     mipLevel.fRowBytes = rowBytes;
     SkSTArray<1, GrMipLevel> texels;
     texels.push_back(mipLevel);
-    success = this->uploadTexData(glTex->desc(), glTex->target(), kTransfer_UploadType,
-                                  left, top, width, height, config, texels);
+    success = this->uploadTexData(glTex->config(), glTex->width(), glTex->height(), glTex->origin(),
+                                  glTex->target(), kTransfer_UploadType, left, top, width, height,
+                                  config, texels);
     return success;
 }
 
@@ -844,7 +847,7 @@ static inline GrGLint config_alignment(GrPixelConfig config) {
 /**
  * Creates storage space for the texture and fills it with texels.
  *
- * @param desc           The surface descriptor for the texture being created.
+ * @param config         Pixel config of the texture.
  * @param interface      The GL interface in use.
  * @param caps           The capabilities of the GL device.
  * @param internalFormat The data format used for the internal storage of the texture. May be sized.
@@ -854,10 +857,8 @@ static inline GrGLint config_alignment(GrPixelConfig config) {
  * @param texels         The texel data of the texture being created.
  * @param baseWidth      The width of the texture's base mipmap level
  * @param baseHeight     The height of the texture's base mipmap level
- * @param succeeded      Set to true if allocating and populating the texture completed
- *                       without error.
  */
-static bool allocate_and_populate_uncompressed_texture(const GrSurfaceDesc& desc,
+static bool allocate_and_populate_uncompressed_texture(GrPixelConfig config,
                                                        const GrGLInterface& interface,
                                                        const GrGLCaps& caps,
                                                        GrGLenum target,
@@ -869,21 +870,19 @@ static bool allocate_and_populate_uncompressed_texture(const GrSurfaceDesc& desc
                                                        int baseWidth, int baseHeight) {
     CLEAR_ERROR_BEFORE_ALLOC(&interface);
 
-    bool useTexStorage = caps.isConfigTexSupportEnabled(desc.fConfig);
+    bool useTexStorage = caps.isConfigTexSupportEnabled(config);
     // We can only use TexStorage if we know we will not later change the storage requirements.
     // This means if we may later want to add mipmaps, we cannot use TexStorage.
     // Right now, we cannot know if we will later add mipmaps or not.
     // The only time we can use TexStorage is when we already have the
     // mipmaps or are using a format incompatible with MIP maps.
-    useTexStorage &= texels.count() > 1 || GrPixelConfigIsSint(desc.fConfig);
+    useTexStorage &= texels.count() > 1 || GrPixelConfigIsSint(config);
 
     if (useTexStorage) {
         // We never resize or change formats of textures.
         GL_ALLOC_CALL(&interface,
-                      TexStorage2D(target,
-                                   SkTMax(texels.count(), 1),
-                                   internalFormatForTexStorage,
-                                   desc.fWidth, desc.fHeight));
+                      TexStorage2D(target, SkTMax(texels.count(), 1), internalFormatForTexStorage,
+                                   baseWidth, baseHeight));
         GrGLenum error = CHECK_ALLOC_ERROR(&interface);
         if (error != GR_GL_NO_ERROR) {
             return  false;
@@ -894,8 +893,8 @@ static bool allocate_and_populate_uncompressed_texture(const GrSurfaceDesc& desc
                     continue;
                 }
                 int twoToTheMipLevel = 1 << currentMipLevel;
-                int currentWidth = SkTMax(1, desc.fWidth / twoToTheMipLevel);
-                int currentHeight = SkTMax(1, desc.fHeight / twoToTheMipLevel);
+                int currentWidth = SkTMax(1, baseWidth / twoToTheMipLevel);
+                int currentHeight = SkTMax(1, baseHeight / twoToTheMipLevel);
 
                 GR_GL_CALL(&interface,
                            TexSubImage2D(target,
@@ -954,13 +953,14 @@ static bool allocate_and_populate_uncompressed_texture(const GrSurfaceDesc& desc
 /**
  * Creates storage space for the texture and fills it with texels.
  *
+ * @param config         Compressed pixel config of the texture.
  * @param desc           The surface descriptor for the texture being created.
  * @param interface      The GL interface in use.
  * @param caps           The capabilities of the GL device.
  * @param internalFormat The data format used for the internal storage of the texture.
  * @param texels         The texel data of the texture being created.
  */
-static bool allocate_and_populate_compressed_texture(const GrSurfaceDesc& desc,
+static bool allocate_and_populate_compressed_texture(GrPixelConfig config,
                                                      const GrGLInterface& interface,
                                                      const GrGLCaps& caps,
                                                      GrGLenum target, GrGLenum internalFormat,
@@ -968,7 +968,7 @@ static bool allocate_and_populate_compressed_texture(const GrSurfaceDesc& desc,
                                                      int baseWidth, int baseHeight) {
     CLEAR_ERROR_BEFORE_ALLOC(&interface);
 
-    bool useTexStorage = caps.isConfigTexSupportEnabled(desc.fConfig);
+    bool useTexStorage = caps.isConfigTexSupportEnabled(config);
     // We can only use TexStorage if we know we will not later change the storage requirements.
     // This means if we may later want to add mipmaps, we cannot use TexStorage.
     // Right now, we cannot know if we will later add mipmaps or not.
@@ -999,8 +999,7 @@ static bool allocate_and_populate_compressed_texture(const GrSurfaceDesc& desc,
 
                 // Make sure that the width and height that we pass to OpenGL
                 // is a multiple of the block size.
-                size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, currentWidth,
-                                                             currentHeight);
+                size_t dataSize = GrCompressedFormatDataSize(config, currentWidth, currentHeight);
                 GR_GL_CALL(&interface, CompressedTexSubImage2D(target,
                                                                currentMipLevel,
                                                                0, // left
@@ -1020,7 +1019,7 @@ static bool allocate_and_populate_compressed_texture(const GrSurfaceDesc& desc,
 
             // Make sure that the width and height that we pass to OpenGL
             // is a multiple of the block size.
-            size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, baseWidth, baseHeight);
+            size_t dataSize = GrCompressedFormatDataSize(config, baseWidth, baseHeight);
 
             GL_ALLOC_CALL(&interface,
                           CompressedTexImage2D(target,
@@ -1062,16 +1061,14 @@ static void restore_pixelstore_state(const GrGLInterface& interface, const GrGLC
     }
 }
 
-bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc,
-                            GrGLenum target,
-                            UploadType uploadType,
-                            int left, int top, int width, int height,
-                            GrPixelConfig dataConfig,
+bool GrGLGpu::uploadTexData(GrPixelConfig texConfig, int texWidth, int texHeight,
+                            GrSurfaceOrigin texOrigin, GrGLenum target, UploadType uploadType,
+                            int left, int top, int width, int height, GrPixelConfig dataConfig,
                             const SkTArray<GrMipLevel>& texels) {
     // If we're uploading compressed data then we should be using uploadCompressedTexData
     SkASSERT(!GrPixelConfigIsCompressed(dataConfig));
 
-    SkASSERT(this->caps()->isConfigTexturable(desc.fConfig));
+    SkASSERT(this->caps()->isConfigTexturable(texConfig));
 
     // texels is const.
     // But we may need to flip the texture vertically to prepare it.
@@ -1103,11 +1100,10 @@ bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc,
             currentWidth > SK_MaxS32) {
             return false;
         }
-        if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, &left, &top,
-                                               &currentWidth,
-                                               &currentHeight,
-                                               &texelsShallowCopy[currentMipLevel].fPixels,
-                                               &texelsShallowCopy[currentMipLevel].fRowBytes)) {
+        if (!GrSurfacePriv::AdjustWritePixelParams(texWidth, texHeight, bpp, &left, &top,
+                                                   &currentWidth, &currentHeight,
+                                                   &texelsShallowCopy[currentMipLevel].fPixels,
+                                                   &texelsShallowCopy[currentMipLevel].fRowBytes)) {
             return false;
         }
         if (currentWidth < 0 || currentHeight < 0) {
@@ -1120,12 +1116,12 @@ bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc,
     // External format and type come from the upload data.
     GrGLenum externalFormat;
     GrGLenum externalType;
-    if (!this->glCaps().getTexImageFormats(desc.fConfig, dataConfig, &internalFormat,
-                                           &externalFormat, &externalType)) {
+    if (!this->glCaps().getTexImageFormats(texConfig, dataConfig, &internalFormat, &externalFormat,
+                                           &externalType)) {
         return false;
     }
     // TexStorage requires a sized format, and internalFormat may or may not be
-    GrGLenum internalFormatForTexStorage = this->glCaps().configSizedInternalFormat(desc.fConfig);
+    GrGLenum internalFormatForTexStorage = this->glCaps().configSizedInternalFormat(texConfig);
 
     /*
      *  Check whether to allocate a temporary buffer for flipping y or
@@ -1137,7 +1133,7 @@ bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc,
     bool swFlipY = false;
     bool glFlipY = false;
 
-    if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin && !texelsShallowCopy.empty()) {
+    if (kBottomLeft_GrSurfaceOrigin == texOrigin && !texelsShallowCopy.empty()) {
         if (caps.unpackFlipYSupport()) {
             glFlipY = true;
         } else {
@@ -1220,22 +1216,22 @@ bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc,
         if (glFlipY) {
             GR_GL_CALL(interface, PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE));
         }
-        GR_GL_CALL(interface, PixelStorei(GR_GL_UNPACK_ALIGNMENT,
-                                          config_alignment(desc.fConfig)));
+        GR_GL_CALL(interface, PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(texConfig)));
     }
 
     bool succeeded = true;
-    if (kNewTexture_UploadType == uploadType &&
-        0 == left && 0 == top &&
-        desc.fWidth == width && desc.fHeight == height) {
-        succeeded = allocate_and_populate_uncompressed_texture(desc, *interface, caps, target,
-                                                               internalFormat,
-                                                               internalFormatForTexStorage,
-                                                               externalFormat, externalType,
-                                                               texelsShallowCopy, width, height);
+    if (kNewTexture_UploadType == uploadType) {
+        if (0 == left && 0 == top && texWidth == width && texHeight == height) {
+            succeeded = allocate_and_populate_uncompressed_texture(
+                    texConfig, *interface, caps, target, internalFormat,
+                    internalFormatForTexStorage, externalFormat, externalType, texelsShallowCopy,
+                    width, height);
+        } else {
+            succeeded = false;
+        }
     } else {
         if (swFlipY || glFlipY) {
-            top = desc.fHeight - (top + height);
+            top = texHeight - (top + height);
         }
         for (int currentMipLevel = 0; currentMipLevel < texelsShallowCopy.count();
              currentMipLevel++) {
@@ -1263,45 +1259,44 @@ bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc,
 // create a CompressedTexData struct that takes a desc/ptr and figures out
 // the proper upload semantics. Then users can construct this function how they
 // see fit if they want to go against the "standard" way to do it.
-bool GrGLGpu::uploadCompressedTexData(const GrSurfaceDesc& desc,
-                                      GrGLenum target,
-                                      const SkTArray<GrMipLevel>& texels,
-                                      UploadType uploadType,
+bool GrGLGpu::uploadCompressedTexData(GrPixelConfig config, int texWidth, int texHeight,
+                                      GrSurfaceOrigin texOrigin, GrGLenum target,
+                                      const SkTArray<GrMipLevel>& texels, UploadType uploadType,
                                       int left, int top, int width, int height) {
-    SkASSERT(this->caps()->isConfigTexturable(desc.fConfig));
+    SkASSERT(this->caps()->isConfigTexturable(config));
 
     // No support for software flip y, yet...
-    SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin);
+    SkASSERT(kBottomLeft_GrSurfaceOrigin != texOrigin);
 
     const GrGLInterface* interface = this->glInterface();
     const GrGLCaps& caps = this->glCaps();
 
     if (-1 == width) {
-        width = desc.fWidth;
+        width = texWidth;
     }
 #ifdef SK_DEBUG
     else {
-        SkASSERT(width <= desc.fWidth);
+        SkASSERT(width <= texWidth);
     }
 #endif
 
     if (-1 == height) {
-        height = desc.fHeight;
+        height = texHeight;
     }
 #ifdef SK_DEBUG
     else {
-        SkASSERT(height <= desc.fHeight);
+        SkASSERT(height <= texHeight);
     }
 #endif
 
     // We only need the internal format for compressed 2D textures.
     GrGLenum internalFormat;
-    if (!caps.getCompressedTexImageFormats(desc.fConfig, &internalFormat)) {
+    if (!caps.getCompressedTexImageFormats(config, &internalFormat)) {
         return false;
     }
 
     if (kNewTexture_UploadType == uploadType) {
-        return allocate_and_populate_compressed_texture(desc, *interface, caps, target,
+        return allocate_and_populate_compressed_texture(config, *interface, caps, target,
                                                         internalFormat, texels, width, height);
     } else {
         for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLevel++) {
@@ -1313,8 +1308,7 @@ bool GrGLGpu::uploadCompressedTexData(const GrSurfaceDesc& desc,
 
             // Make sure that the width and height that we pass to OpenGL
             // is a multiple of the block size.
-            size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, currentWidth,
-                                                         currentHeight);
+            size_t dataSize = GrCompressedFormatDataSize(config, currentWidth, currentHeight);
             GL_CALL(CompressedTexSubImage2D(target,
                                             currentMipLevel,
                                             left, top,
@@ -1586,7 +1580,8 @@ GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc,
     GrGLTexture::TexParams initialTexParams;
     set_initial_texture_params(this->glInterface(), idDesc.fInfo, &initialTexParams);
 
-    if (!this->uploadCompressedTexData(desc, idDesc.fInfo.fTarget, texels)) {
+    if (!this->uploadCompressedTexData(desc.fConfig, desc.fWidth, desc.fHeight, desc.fOrigin,
+                                       idDesc.fInfo.fTarget, texels)) {
         GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID));
         return return_null_texture();
     }
@@ -1762,9 +1757,9 @@ bool GrGLGpu::createTextureImpl(const GrSurfaceDesc& desc, GrGLTextureInfo* info
     if (info) {
         set_initial_texture_params(this->glInterface(), *info, initialTexParams);
     }
-    if (!this->uploadTexData(desc, info->fTarget, kNewTexture_UploadType, 0, 0,
-                             desc.fWidth, desc.fHeight,
-                             desc.fConfig, texels)) {
+    if (!this->uploadTexData(desc.fConfig, desc.fWidth, desc.fHeight, desc.fOrigin, info->fTarget,
+                             kNewTexture_UploadType, 0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
+                             texels)) {
         GL_CALL(DeleteTextures(1, &(info->fID)));
         return false;
     }
@@ -1772,8 +1767,7 @@ bool GrGLGpu::createTextureImpl(const GrSurfaceDesc& desc, GrGLTextureInfo* info
 }
 
 GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
-                                                                     int width,
-                                                                     int height) {
+                                                                     int width, int height) {
     SkASSERT(width >= rt->width());
     SkASSERT(height >= rt->height());
 
index 041ecfb..cf3d38f 100644 (file)
@@ -361,11 +361,9 @@ private:
         kWrite_UploadType,         // we are using TexSubImage2D to copy data to an existing texture
         kTransfer_UploadType,      // we are using a transfer buffer to copy data
     };
-    bool uploadTexData(const GrSurfaceDesc& desc,
-                       GrGLenum target,
-                       UploadType uploadType,
-                       int left, int top, int width, int height,
-                       GrPixelConfig dataConfig,
+    bool uploadTexData(GrPixelConfig texConfig, int texWidth, int texHeight,
+                       GrSurfaceOrigin texOrigin, GrGLenum target, UploadType uploadType, int left,
+                       int top, int width, int height, GrPixelConfig dataConfig,
                        const SkTArray<GrMipLevel>& texels);
 
     // helper for onCreateCompressedTexture. If width and height are
@@ -374,12 +372,11 @@ private:
     // whenever a new texture needs to be created. Otherwise, we assume that
     // the texture is already in GPU memory and that it's going to be updated
     // with new data.
-    bool uploadCompressedTexData(const GrSurfaceDesc& desc,
-                                 GrGLenum target,
+    bool uploadCompressedTexData(GrPixelConfig texAndDataConfig, int texWidth, int texHeight,
+                                 GrSurfaceOrigin texOrigin, GrGLenum target,
                                  const SkTArray<GrMipLevel>& texels,
-                                 UploadType uploadType = kNewTexture_UploadType,
-                                 int left = 0, int top = 0,
-                                 int width = -1, int height = -1);
+                                 UploadType uploadType = kNewTexture_UploadType, int left = 0,
+                                 int top = 0, int width = -1, int height = -1);
 
     bool createRenderTargetObjects(const GrSurfaceDesc&, const GrGLTextureInfo& texInfo,
                                    GrGLRenderTarget::IDDesc*);
index 8469755..c438acc 100644 (file)
@@ -503,9 +503,7 @@ bool GrVkGpu::uploadTexDataLinear(GrVkTexture* tex,
 
     size_t bpp = GrBytesPerPixel(dataConfig);
 
-    const GrSurfaceDesc& desc = tex->desc();
-
-    if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, &left, &top,
+    if (!GrSurfacePriv::AdjustWritePixelParams(tex->width(), tex->height(), bpp, &left, &top,
                                                &width, &height, &data, &rowBytes)) {
         return false;
     }
@@ -528,7 +526,7 @@ bool GrVkGpu::uploadTexDataLinear(GrVkTexture* tex,
                                                     &subres,
                                                     &layout));
 
-    int texTop = kBottomLeft_GrSurfaceOrigin == desc.fOrigin ? tex->height() - top - height : top;
+    int texTop = kBottomLeft_GrSurfaceOrigin == tex->origin() ? tex->height() - top - height : top;
     const GrVkAlloc& alloc = tex->alloc();
     VkDeviceSize offset = alloc.fOffset + texTop*layout.rowPitch + left*bpp;
     VkDeviceSize size = height*layout.rowPitch;
@@ -538,7 +536,7 @@ bool GrVkGpu::uploadTexDataLinear(GrVkTexture* tex,
         return false;
     }
 
-    if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) {
+    if (kBottomLeft_GrSurfaceOrigin == tex->origin()) {
         // copy into buffer by rows
         const char* srcRow = reinterpret_cast<const char*>(data);
         char* dstRow = reinterpret_cast<char*>(mapPtr)+(height - 1)*layout.rowPitch;
@@ -578,8 +576,7 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex,
         return false;
     }
 
-    const GrSurfaceDesc& desc = tex->desc();
-    SkASSERT(this->caps()->isConfigTexturable(desc.fConfig));
+    SkASSERT(this->caps()->isConfigTexturable(tex->config()));
     size_t bpp = GrBytesPerPixel(dataConfig);
 
     // texels is const.
@@ -593,17 +590,15 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex,
     }
 
     // Determine whether we need to flip when we copy into the buffer
-    bool flipY = (kBottomLeft_GrSurfaceOrigin == desc.fOrigin && !texelsShallowCopy.empty());
+    bool flipY = (kBottomLeft_GrSurfaceOrigin == tex->origin() && !texelsShallowCopy.empty());
 
     // adjust any params (left, top, currentWidth, currentHeight
     // find the combined size of all the mip levels and the relative offset of
     // each into the collective buffer
     // Do the first level separately because we may need to adjust width and height
     // (for the non-mipped case).
-    if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, &left, &top,
-                                               &width,
-                                               &height,
-                                               &texelsShallowCopy[0].fPixels,
+    if (!GrSurfacePriv::AdjustWritePixelParams(tex->width(), tex->height(), bpp, &left, &top,
+                                               &width, &height, &texelsShallowCopy[0].fPixels,
                                                &texelsShallowCopy[0].fRowBytes)) {
         return false;
     }
@@ -619,9 +614,8 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex,
     for (int currentMipLevel = 1; currentMipLevel < texelsShallowCopy.count(); currentMipLevel++) {
         currentWidth = SkTMax(1, currentWidth/2);
         currentHeight = SkTMax(1, currentHeight/2);
-        if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, &left, &top,
-                                                   &currentWidth,
-                                                   &currentHeight,
+        if (!GrSurfacePriv::AdjustWritePixelParams(tex->width(), tex->height(), bpp, &left, &top,
+                                                   &currentWidth, &currentHeight,
                                                    &texelsShallowCopy[currentMipLevel].fPixels,
                                                    &texelsShallowCopy[currentMipLevel].fRowBytes)) {
             return false;