Make SkGpuDevice::drawVertices perform color byte order swap and premul step using...
authorBrian Salomon <bsalomon@google.com>
Sun, 29 Jan 2017 14:34:17 +0000 (09:34 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Mon, 30 Jan 2017 16:39:41 +0000 (16:39 +0000)
Change-Id: I8153ba8c6bb48d8b15d524fbfafbe3c6d83f39c5
Reviewed-on: https://skia-review.googlesource.com/7727
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>

18 files changed:
include/gpu/GrRenderTargetContext.h
src/gpu/GrDefaultGeoProcFactory.cpp
src/gpu/GrDefaultGeoProcFactory.h
src/gpu/GrRenderTargetContext.cpp
src/gpu/SkGpuDevice.cpp
src/gpu/ops/GrAAConvexPathRenderer.cpp
src/gpu/ops/GrAAFillRectOp.cpp
src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
src/gpu/ops/GrAAStrokeRectOp.cpp
src/gpu/ops/GrDrawAtlasOp.cpp
src/gpu/ops/GrDrawVerticesOp.cpp
src/gpu/ops/GrDrawVerticesOp.h
src/gpu/ops/GrLatticeOp.cpp
src/gpu/ops/GrMSAAPathRenderer.cpp
src/gpu/ops/GrNonAAFillRectOp.cpp
src/gpu/ops/GrNonAAFillRectPerspectiveOp.cpp
src/gpu/ops/GrRegionOp.cpp
src/gpu/ops/GrTessellatingPathRenderer.cpp

index 3056449..040e896 100644 (file)
@@ -195,6 +195,10 @@ public:
                   const SkPath&,
                   const GrStyle& style);
 
+    enum class ColorArrayType {
+        kPremulGrColor,
+        kSkColor,
+    };
     /**
      * Draws vertices with a paint.
      *
@@ -211,6 +215,7 @@ public:
      *                          are drawn non-indexed.
      * @param   indexCount      if indices is non-null then this is the
      *                          number of indices.
+     * @param   ColorArrayType  Determines how the color array should be interpreted.
      */
     void drawVertices(const GrClip&,
                       GrPaint&& paint,
@@ -219,9 +224,10 @@ public:
                       int vertexCount,
                       const SkPoint positions[],
                       const SkPoint texs[],
-                      const GrColor colors[],
+                      const uint32_t colors[],
                       const uint16_t indices[],
-                      int indexCount);
+                      int indexCount,
+                      ColorArrayType = ColorArrayType::kPremulGrColor);
 
     /**
      * Draws textured sprites from an atlas with a paint. This currently does not support AA for the
index 9da0ffe..ab57c0b 100644 (file)
  */
 
 enum GPFlag {
-    kColor_GPFlag =                 0x1,
-    kLocalCoord_GPFlag =            0x2,
-    kCoverage_GPFlag=               0x4,
+    kColorAttribute_GPFlag          = 0x1,
+    kColorAttributeIsSkColor_GPFlag = 0x2,
+    kLocalCoordAttribute_GPFlag     = 0x4,
+    kCoverageAttribute_GPFlag       = 0x8,
 };
 
 class DefaultGeoProc : public GrGeometryProcessor {
 public:
     static sk_sp<GrGeometryProcessor> Make(uint32_t gpTypeFlags,
-                                             GrColor color,
-                                             const SkMatrix& viewMatrix,
-                                             const SkMatrix& localMatrix,
-                                             bool localCoordsWillBeRead,
-                                             uint8_t coverage) {
+                                           GrColor color,
+                                           const SkMatrix& viewMatrix,
+                                           const SkMatrix& localMatrix,
+                                           bool localCoordsWillBeRead,
+                                           uint8_t coverage) {
         return sk_sp<GrGeometryProcessor>(new DefaultGeoProc(
                 gpTypeFlags, color, viewMatrix, localMatrix, coverage, localCoordsWillBeRead));
     }
@@ -71,7 +72,17 @@ public:
 
             // Setup pass through color
             if (gp.hasVertexColor()) {
-                varyingHandler->addPassThroughAttribute(gp.inColor(), args.fOutputColor);
+                GrGLSLVertToFrag varying(kVec4f_GrSLType);
+                varyingHandler->addVarying("color", &varying);
+                if (gp.fFlags & kColorAttributeIsSkColor_GPFlag) {
+                    // Do a red/blue swap and premul the color.
+                    vertBuilder->codeAppendf("%s = vec4(%s.a*%s.bgr, %s.a);", varying.vsOut(),
+                                             gp.inColor()->fName, gp.inColor()->fName,
+                                             gp.inColor()->fName);
+                } else {
+                    vertBuilder->codeAppendf("%s = %s;\n", varying.vsOut(), gp.inColor()->fName);
+                }
+                fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, varying.fsIn());
             } else {
                 this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
                                         &fColorUniform);
@@ -128,12 +139,9 @@ public:
                                   GrProcessorKeyBuilder* b) {
             const DefaultGeoProc& def = gp.cast<DefaultGeoProc>();
             uint32_t key = def.fFlags;
-            key |= def.hasVertexColor() << 8;
-            key |= def.hasVertexCoverage() << 9;
-            key |= (def.coverage() == 0xff) ? (0x1 << 10) : 0;
-            key |= (def.localCoordsWillBeRead() && def.localMatrix().hasPerspective()) ? (0x1 << 24)
-                                                                                       : 0x0;
-            key |= ComputePosKey(def.viewMatrix()) << 25;
+            key |= (def.coverage() == 0xff) ? 0x10 : 0;
+            key |= (def.localCoordsWillBeRead() && def.localMatrix().hasPerspective()) ? 0x20 : 0x0;
+            key |= ComputePosKey(def.viewMatrix()) << 20;
             b->add32(key);
         }
 
@@ -189,39 +197,32 @@ private:
                    const SkMatrix& localMatrix,
                    uint8_t coverage,
                    bool localCoordsWillBeRead)
-            : fInPosition(nullptr)
-            , fInColor(nullptr)
-            , fInLocalCoords(nullptr)
-            , fInCoverage(nullptr)
-            , fColor(color)
+            : fColor(color)
             , fViewMatrix(viewMatrix)
             , fLocalMatrix(localMatrix)
             , fCoverage(coverage)
             , fFlags(gpTypeFlags)
             , fLocalCoordsWillBeRead(localCoordsWillBeRead) {
         this->initClassID<DefaultGeoProc>();
-        bool hasColor = SkToBool(gpTypeFlags & kColor_GPFlag);
-        bool hasExplicitLocalCoords = SkToBool(gpTypeFlags & kLocalCoord_GPFlag);
-        bool hasCoverage = SkToBool(gpTypeFlags & kCoverage_GPFlag);
         fInPosition = &this->addVertexAttrib("inPosition", kVec2f_GrVertexAttribType,
                                              kHigh_GrSLPrecision);
-        if (hasColor) {
+        if (fFlags & kColorAttribute_GPFlag) {
             fInColor = &this->addVertexAttrib("inColor", kVec4ub_GrVertexAttribType);
         }
-        if (hasExplicitLocalCoords) {
+        if (fFlags & kLocalCoordAttribute_GPFlag) {
             fInLocalCoords = &this->addVertexAttrib("inLocalCoord", kVec2f_GrVertexAttribType,
                                                     kHigh_GrSLPrecision);
             this->setHasExplicitLocalCoords();
         }
-        if (hasCoverage) {
+        if (fFlags & kCoverageAttribute_GPFlag) {
             fInCoverage = &this->addVertexAttrib("inCoverage", kFloat_GrVertexAttribType);
         }
     }
 
-    const Attribute* fInPosition;
-    const Attribute* fInColor;
-    const Attribute* fInLocalCoords;
-    const Attribute* fInCoverage;
+    const Attribute* fInPosition = nullptr;
+    const Attribute* fInColor = nullptr;
+    const Attribute* fInLocalCoords = nullptr;
+    const Attribute* fInCoverage = nullptr;
     GrColor fColor;
     SkMatrix fViewMatrix;
     SkMatrix fLocalMatrix;
@@ -239,19 +240,23 @@ GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc);
 sk_sp<GrGeometryProcessor> DefaultGeoProc::TestCreate(GrProcessorTestData* d) {
     uint32_t flags = 0;
     if (d->fRandom->nextBool()) {
-        flags |= kColor_GPFlag;
+        flags |= kColorAttribute_GPFlag;
     }
     if (d->fRandom->nextBool()) {
-        flags |= kCoverage_GPFlag;
+        flags |= kColorAttributeIsSkColor_GPFlag;
     }
     if (d->fRandom->nextBool()) {
-        flags |= kLocalCoord_GPFlag;
+        flags |= kCoverageAttribute_GPFlag;
+    }
+    if (d->fRandom->nextBool()) {
+        flags |= kLocalCoordAttribute_GPFlag;
     }
 
     return DefaultGeoProc::Make(flags,
                                 GrRandomColor(d->fRandom),
                                 GrTest::TestMatrix(d->fRandom),
                                 GrTest::TestMatrix(d->fRandom),
+
                                 d->fRandom->nextBool(),
                                 GrRandomCoverage(d->fRandom));
 }
@@ -261,9 +266,13 @@ sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::Make(const Color& color,
                                                          const LocalCoords& localCoords,
                                                          const SkMatrix& viewMatrix) {
     uint32_t flags = 0;
-    flags |= color.fType == Color::kAttribute_Type ? kColor_GPFlag : 0;
-    flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverage_GPFlag : 0;
-    flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoord_GPFlag : 0;
+    if (Color::kPremulGrColorAttribute_Type == color.fType) {
+        flags |= kColorAttribute_GPFlag;
+    } else if (Color::kUnpremulSkColorAttribute_Type == color.fType) {
+        flags |= kColorAttribute_GPFlag | kColorAttributeIsSkColor_GPFlag;
+    }
+    flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverageAttribute_GPFlag : 0;
+    flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoordAttribute_GPFlag : 0;
 
     uint8_t inCoverage = coverage.fCoverage;
     bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type;
index 238c154..00ee90d 100644 (file)
@@ -62,18 +62,13 @@ namespace GrDefaultGeoProcFactory {
 
     struct Color {
         enum Type {
-            kNone_Type,
-            kUniform_Type,
-            kAttribute_Type,
+            kPremulGrColorUniform_Type,
+            kPremulGrColorAttribute_Type,
+            kUnpremulSkColorAttribute_Type,
         };
-        explicit Color(GrColor color) : fType(kUniform_Type), fColor(color) {}
+        explicit Color(GrColor color) : fType(kPremulGrColorUniform_Type), fColor(color) {}
         Color(Type type) : fType(type), fColor(GrColor_ILLEGAL) {
-            SkASSERT(type != kUniform_Type);
-
-            // TODO This is temporary
-            if (kAttribute_Type == type) {
-                fColor = GrColor_WHITE;
-            }
+            SkASSERT(type != kPremulGrColorUniform_Type);
         }
 
         Type fType;
index f11f45e..13fa56f 100644 (file)
@@ -876,9 +876,10 @@ void GrRenderTargetContext::drawVertices(const GrClip& clip,
                                          int vertexCount,
                                          const SkPoint positions[],
                                          const SkPoint texCoords[],
-                                         const GrColor colors[],
+                                         const uint32_t colors[],
                                          const uint16_t indices[],
-                                         int indexCount) {
+                                         int indexCount,
+                                         ColorArrayType colorArrayType) {
     ASSERT_SINGLE_OWNER
     RETURN_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
@@ -895,9 +896,9 @@ void GrRenderTargetContext::drawVertices(const GrClip& clip,
 
     viewMatrix.mapRect(&bounds);
 
-    std::unique_ptr<GrDrawOp> op =
-            GrDrawVerticesOp::Make(paint.getColor(), primitiveType, viewMatrix, positions,
-                                   vertexCount, indices, indexCount, colors, texCoords, bounds);
+    std::unique_ptr<GrDrawOp> op = GrDrawVerticesOp::Make(
+            paint.getColor(), primitiveType, viewMatrix, positions, vertexCount, indices,
+            indexCount, colors, texCoords, bounds, colorArrayType);
 
     GrPipelineBuilder pipelineBuilder(std::move(paint), GrAAType::kNone);
     this->getOpList()->addDrawOp(pipelineBuilder, this, clip, std::move(op));
index f4ee544..b799545 100644 (file)
@@ -1646,16 +1646,6 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
 
     GrPrimitiveType primType = gVertexMode2PrimitiveType[vmode];
 
-    SkAutoSTMalloc<128, GrColor> convertedColors(0);
-    if (colors) {
-        // need to convert byte order and from non-PM to PM. TODO: Keep unpremul until after
-        // interpolation.
-        convertedColors.reset(vertexCount);
-        for (int i = 0; i < vertexCount; ++i) {
-            convertedColors[i] = SkColorToPremulGrColor(colors[i]);
-        }
-        colors = convertedColors.get();
-    }
     GrPaint grPaint;
     if (texs && paint.getShader()) {
         if (colors) {
@@ -1697,7 +1687,8 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
                                        texs,
                                        colors,
                                        indices,
-                                       indexCount);
+                                       indexCount,
+                                       GrRenderTargetContext::ColorArrayType::kSkColor);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
index a279a8c..f39902f 100644 (file)
@@ -717,7 +717,8 @@ static sk_sp<GrGeometryProcessor> create_fill_gp(bool tweakAlphaForCoverage,
     }
     LocalCoords::Type localCoordsType =
             usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type;
-    return MakeForDeviceSpace(Color::kAttribute_Type, coverageType, localCoordsType, viewMatrix);
+    return MakeForDeviceSpace(Color::kPremulGrColorAttribute_Type, coverageType, localCoordsType,
+                              viewMatrix);
 }
 
 class AAConvexPathOp final : public GrMeshDrawOp {
index 5c585bf..a0fc9f0 100644 (file)
@@ -211,7 +211,7 @@ private:
     void onPrepareDraws(Target* target) const override {
         using namespace GrDefaultGeoProcFactory;
 
-        Color color(Color::kAttribute_Type);
+        Color color(Color::kPremulGrColorAttribute_Type);
         Coverage::Type coverageType;
         if (fCanTweakAlphaForCoverage) {
             coverageType = Coverage::kSolid_Type;
index caa086e..fd09d91 100644 (file)
@@ -114,7 +114,8 @@ static sk_sp<GrGeometryProcessor> create_fill_gp(bool tweakAlphaForCoverage,
     }
     LocalCoords::Type localCoordsType =
             usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type;
-    return MakeForDeviceSpace(Color::kAttribute_Type, coverageType, localCoordsType, viewMatrix);
+    return MakeForDeviceSpace(Color::kPremulGrColorAttribute_Type, coverageType, localCoordsType,
+                              viewMatrix);
 }
 
 class AAFlatteningConvexPathOp final : public GrMeshDrawOp {
index 8a5fec1..b05e722 100644 (file)
@@ -105,7 +105,8 @@ static sk_sp<GrGeometryProcessor> create_stroke_rect_gp(bool tweakAlphaForCovera
     }
     LocalCoords::Type localCoordsType =
             usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type;
-    return MakeForDeviceSpace(Color::kAttribute_Type, coverageType, localCoordsType, viewMatrix);
+    return MakeForDeviceSpace(Color::kPremulGrColorAttribute_Type, coverageType, localCoordsType,
+                              viewMatrix);
 }
 
 class AAStrokeRectOp final : public GrMeshDrawOp {
index c9dffe6..4d78a7d 100644 (file)
@@ -35,7 +35,7 @@ static sk_sp<GrGeometryProcessor> make_gp(bool hasColors,
     using namespace GrDefaultGeoProcFactory;
     Color gpColor(color);
     if (hasColors) {
-        gpColor.fType = Color::kAttribute_Type;
+        gpColor.fType = Color::kPremulGrColorAttribute_Type;
     }
 
     return GrDefaultGeoProcFactory::Make(gpColor, Coverage::kSolid_Type,
index ed2c072..3448249 100644 (file)
 #include "GrInvariantOutput.h"
 #include "GrOpFlushState.h"
 
-static sk_sp<GrGeometryProcessor> set_vertex_attributes(bool hasLocalCoords,
-                                                        int* colorOffset,
-                                                        int* texOffset,
-                                                        const SkMatrix& viewMatrix) {
+static sk_sp<GrGeometryProcessor> set_vertex_attributes(
+        bool hasLocalCoords,
+        int* colorOffset,
+        GrRenderTargetContext::ColorArrayType colorArrayType,
+        int* texOffset,
+        const SkMatrix& viewMatrix) {
     using namespace GrDefaultGeoProcFactory;
     *texOffset = -1;
     *colorOffset = -1;
@@ -23,17 +25,22 @@ static sk_sp<GrGeometryProcessor> set_vertex_attributes(bool hasLocalCoords,
             hasLocalCoords ? LocalCoords::kHasExplicit_Type : LocalCoords::kUsePosition_Type;
     *colorOffset = sizeof(SkPoint);
     if (hasLocalCoords) {
-        *texOffset = sizeof(SkPoint) + sizeof(GrColor);
+        *texOffset = sizeof(SkPoint) + sizeof(uint32_t);
     }
-    return GrDefaultGeoProcFactory::Make(Color::kAttribute_Type, Coverage::kSolid_Type,
-                                         localCoordsType, viewMatrix);
+    Color::Type colorType =
+            (colorArrayType == GrRenderTargetContext::ColorArrayType::kPremulGrColor)
+                    ? Color::kPremulGrColorAttribute_Type
+                    : Color::kUnpremulSkColorAttribute_Type;
+    return GrDefaultGeoProcFactory::Make(colorType, Coverage::kSolid_Type, localCoordsType,
+                                         viewMatrix);
 }
 
 GrDrawVerticesOp::GrDrawVerticesOp(GrColor color, GrPrimitiveType primitiveType,
                                    const SkMatrix& viewMatrix, const SkPoint* positions,
                                    int vertexCount, const uint16_t* indices, int indexCount,
-                                   const GrColor* colors, const SkPoint* localCoords,
-                                   const SkRect& bounds)
+                                   const uint32_t* colors, const SkPoint* localCoords,
+                                   const SkRect& bounds,
+                                   GrRenderTargetContext::ColorArrayType colorArrayType)
         : INHERITED(ClassID()) {
     SkASSERT(positions);
 
@@ -49,8 +56,12 @@ GrDrawVerticesOp::GrDrawVerticesOp(GrColor color, GrPrimitiveType primitiveType,
     if (colors) {
         fVariableColor = true;
         mesh.fColors.append(vertexCount, colors);
+        fColorArrayType = colorArrayType;
     } else {
         fVariableColor = false;
+        // When we tessellate we will fill a color array with the GrColor value passed above as
+        // 'color'.
+        fColorArrayType = GrRenderTargetContext::ColorArrayType::kPremulGrColor;
     }
 
     if (localCoords) {
@@ -85,6 +96,7 @@ void GrDrawVerticesOp::applyPipelineOptimizations(const GrPipelineOptimizations&
         fMeshes[0].fColor = overrideColor;
         fMeshes[0].fColors.reset();
         fVariableColor = false;
+        fColorArrayType = GrRenderTargetContext::ColorArrayType::kPremulGrColor;
     }
     if (!optimizations.readsLocalCoords()) {
         fMeshes[0].fLocalCoords.reset();
@@ -94,12 +106,12 @@ void GrDrawVerticesOp::applyPipelineOptimizations(const GrPipelineOptimizations&
 void GrDrawVerticesOp::onPrepareDraws(Target* target) const {
     bool hasLocalCoords = !fMeshes[0].fLocalCoords.isEmpty();
     int colorOffset = -1, texOffset = -1;
-    sk_sp<GrGeometryProcessor> gp(
-            set_vertex_attributes(hasLocalCoords, &colorOffset, &texOffset, fViewMatrix));
+    sk_sp<GrGeometryProcessor> gp(set_vertex_attributes(hasLocalCoords, &colorOffset,
+                                                        fColorArrayType, &texOffset, fViewMatrix));
     size_t vertexStride = gp->getVertexStride();
 
     SkASSERT(vertexStride ==
-             sizeof(SkPoint) + (hasLocalCoords ? sizeof(SkPoint) : 0) + sizeof(GrColor));
+             sizeof(SkPoint) + (hasLocalCoords ? sizeof(SkPoint) : 0) + sizeof(uint32_t));
 
     int instanceCount = fMeshes.count();
 
@@ -141,9 +153,9 @@ void GrDrawVerticesOp::onPrepareDraws(Target* target) const {
         for (int j = 0; j < mesh.fPositions.count(); ++j) {
             *((SkPoint*)verts) = mesh.fPositions[j];
             if (mesh.fColors.isEmpty()) {
-                *(GrColor*)((intptr_t)verts + colorOffset) = mesh.fColor;
+                *(uint32_t*)((intptr_t)verts + colorOffset) = mesh.fColor;
             } else {
-                *(GrColor*)((intptr_t)verts + colorOffset) = mesh.fColors[j];
+                *(uint32_t*)((intptr_t)verts + colorOffset) = mesh.fColors[j];
             }
             if (hasLocalCoords) {
                 *(SkPoint*)((intptr_t)verts + texOffset) = mesh.fLocalCoords[j];
@@ -189,6 +201,10 @@ bool GrDrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
         return false;
     }
 
+    if (fColorArrayType != that->fColorArrayType) {
+        return false;
+    }
+
     if (!fVariableColor) {
         if (that->fVariableColor || that->fMeshes[0].fColor != fMeshes[0].fColor) {
             fVariableColor = true;
@@ -251,8 +267,8 @@ static SkPoint random_point(SkRandom* random, SkScalar min, SkScalar max) {
 static void randomize_params(size_t count, size_t maxVertex, SkScalar min, SkScalar max,
                              SkRandom* random, SkTArray<SkPoint>* positions,
                              SkTArray<SkPoint>* texCoords, bool hasTexCoords,
-                             SkTArray<GrColor>* colors, bool hasColors, SkTArray<uint16_t>* indices,
-                             bool hasIndices) {
+                             SkTArray<uint32_t>* colors, bool hasColors,
+                             SkTArray<uint16_t>* indices, bool hasIndices) {
     for (uint32_t v = 0; v < count; v++) {
         positions->push_back(random_point(random, min, max));
         if (hasTexCoords) {
@@ -275,7 +291,7 @@ DRAW_OP_TEST_DEFINE(VerticesOp) {
     // TODO make 'sensible' indexbuffers
     SkTArray<SkPoint> positions;
     SkTArray<SkPoint> texCoords;
-    SkTArray<GrColor> colors;
+    SkTArray<uint32_t> colors;
     SkTArray<uint16_t> indices;
 
     bool hasTexCoords = random->nextBool();
@@ -296,6 +312,9 @@ DRAW_OP_TEST_DEFINE(VerticesOp) {
                          hasIndices);
     }
 
+    GrRenderTargetContext::ColorArrayType colorArrayType =
+            random->nextBool() ? GrRenderTargetContext::ColorArrayType::kPremulGrColor
+                               : GrRenderTargetContext::ColorArrayType::kSkColor;
     SkMatrix viewMatrix = GrTest::TestMatrix(random);
     SkRect bounds;
     SkDEBUGCODE(bool result =) bounds.setBoundsCheck(positions.begin(), vertexCount);
@@ -306,7 +325,7 @@ DRAW_OP_TEST_DEFINE(VerticesOp) {
     GrColor color = GrRandomColor(random);
     return GrDrawVerticesOp::Make(color, type, viewMatrix, positions.begin(), vertexCount,
                                   indices.begin(), hasIndices ? vertexCount : 0, colors.begin(),
-                                  texCoords.begin(), bounds);
+                                  texCoords.begin(), bounds, colorArrayType);
 }
 
 #endif
index 680b41f..38b1a47 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "GrColor.h"
 #include "GrMeshDrawOp.h"
+#include "GrRenderTargetContext.h"
 #include "GrTypes.h"
 #include "SkMatrix.h"
 #include "SkRect.h"
@@ -25,11 +26,12 @@ public:
     static std::unique_ptr<GrDrawOp> Make(GrColor color, GrPrimitiveType primitiveType,
                                           const SkMatrix& viewMatrix, const SkPoint* positions,
                                           int vertexCount, const uint16_t* indices, int indexCount,
-                                          const GrColor* colors, const SkPoint* localCoords,
-                                          const SkRect& bounds) {
-        return std::unique_ptr<GrDrawOp>(
-                new GrDrawVerticesOp(color, primitiveType, viewMatrix, positions, vertexCount,
-                                     indices, indexCount, colors, localCoords, bounds));
+                                          const uint32_t* colors, const SkPoint* localCoords,
+                                          const SkRect& bounds,
+                                          GrRenderTargetContext::ColorArrayType colorArrayType) {
+        return std::unique_ptr<GrDrawOp>(new GrDrawVerticesOp(
+                color, primitiveType, viewMatrix, positions, vertexCount, indices, indexCount,
+                colors, localCoords, bounds, colorArrayType));
     }
 
     const char* name() const override { return "DrawVerticesOp"; }
@@ -46,8 +48,8 @@ public:
 private:
     GrDrawVerticesOp(GrColor color, GrPrimitiveType primitiveType, const SkMatrix& viewMatrix,
                      const SkPoint* positions, int vertexCount, const uint16_t* indices,
-                     int indexCount, const GrColor* colors, const SkPoint* localCoords,
-                     const SkRect& bounds);
+                     int indexCount, const uint32_t* colors, const SkPoint* localCoords,
+                     const SkRect& bounds, GrRenderTargetContext::ColorArrayType colorArrayType);
 
     void getPipelineAnalysisInput(GrPipelineAnalysisDrawOpInput* input) const override;
     void applyPipelineOptimizations(const GrPipelineOptimizations&) override;
@@ -66,7 +68,7 @@ private:
         GrColor fColor;  // Only used if there are no per-vertex colors
         SkTDArray<SkPoint> fPositions;
         SkTDArray<uint16_t> fIndices;
-        SkTDArray<GrColor> fColors;
+        SkTDArray<uint32_t> fColors;
         SkTDArray<SkPoint> fLocalCoords;
     };
 
@@ -75,6 +77,7 @@ private:
     bool fVariableColor;
     int fVertexCount;
     int fIndexCount;
+    GrRenderTargetContext::ColorArrayType fColorArrayType;
 
     SkSTArray<1, Mesh, true> fMeshes;
 
index 93c6f0f..319e505 100644 (file)
@@ -17,7 +17,7 @@
 
 static sk_sp<GrGeometryProcessor> create_gp() {
     using namespace GrDefaultGeoProcFactory;
-    return GrDefaultGeoProcFactory::Make(Color::kAttribute_Type, Coverage::kSolid_Type,
+    return GrDefaultGeoProcFactory::Make(Color::kPremulGrColorAttribute_Type, Coverage::kSolid_Type,
                                          LocalCoords::kHasExplicit_Type, SkMatrix::I());
 }
 
index 26fdf5d..62dc49b 100644 (file)
@@ -401,7 +401,7 @@ private:
             sk_sp<GrGeometryProcessor> lineGP;
             {
                 using namespace GrDefaultGeoProcFactory;
-                lineGP = GrDefaultGeoProcFactory::Make(Color(Color::kAttribute_Type),
+                lineGP = GrDefaultGeoProcFactory::Make(Color(Color::kPremulGrColorAttribute_Type),
                                                        Coverage::kSolid_Type,
                                                        LocalCoords(LocalCoords::kUnused_Type),
                                                        fViewMatrix);
index eb2143d..7ef6cad 100644 (file)
@@ -30,7 +30,7 @@ static const int kIndicesPerInstance = 6;
  */
 static sk_sp<GrGeometryProcessor> make_gp() {
     using namespace GrDefaultGeoProcFactory;
-    return GrDefaultGeoProcFactory::Make(Color::kAttribute_Type, Coverage::kSolid_Type,
+    return GrDefaultGeoProcFactory::Make(Color::kPremulGrColorAttribute_Type, Coverage::kSolid_Type,
                                          LocalCoords::kHasExplicit_Type, SkMatrix::I());
 }
 
index b919a0d..cec1cfc 100644 (file)
@@ -41,16 +41,17 @@ static sk_sp<GrGeometryProcessor> make_persp_gp(const SkMatrix& viewMatrix,
         LocalCoords localCoords(hasExplicitLocalCoords ? LocalCoords::kHasExplicit_Type
                                                        : LocalCoords::kUsePosition_Type,
                                 localMatrix);
-        return GrDefaultGeoProcFactory::Make(Color::kAttribute_Type, Coverage::kSolid_Type,
-                                             localCoords, viewMatrix);
+        return GrDefaultGeoProcFactory::Make(Color::kPremulGrColorAttribute_Type,
+                                             Coverage::kSolid_Type, localCoords, viewMatrix);
     } else if (hasExplicitLocalCoords) {
         LocalCoords localCoords(LocalCoords::kHasExplicit_Type, localMatrix);
-        return GrDefaultGeoProcFactory::Make(Color::kAttribute_Type, Coverage::kSolid_Type,
-                                             localCoords, SkMatrix::I());
+        return GrDefaultGeoProcFactory::Make(Color::kPremulGrColorAttribute_Type,
+                                             Coverage::kSolid_Type, localCoords, SkMatrix::I());
     } else {
         LocalCoords localCoords(LocalCoords::kUsePosition_Type, localMatrix);
-        return GrDefaultGeoProcFactory::MakeForDeviceSpace(
-                Color::kAttribute_Type, Coverage::kSolid_Type, localCoords, viewMatrix);
+        return GrDefaultGeoProcFactory::MakeForDeviceSpace(Color::kPremulGrColorAttribute_Type,
+                                                           Coverage::kSolid_Type, localCoords,
+                                                           viewMatrix);
     }
 }
 
index 32a8150..fae79d0 100644 (file)
@@ -19,7 +19,7 @@ static const int kIndicesPerInstance = 6;
 
 static sk_sp<GrGeometryProcessor> make_gp(const SkMatrix& viewMatrix) {
     using namespace GrDefaultGeoProcFactory;
-    return GrDefaultGeoProcFactory::Make(Color::kAttribute_Type, Coverage::kSolid_Type,
+    return GrDefaultGeoProcFactory::Make(Color::kPremulGrColorAttribute_Type, Coverage::kSolid_Type,
                                          LocalCoords::kUsePosition_Type, viewMatrix);
 }
 
index bd474a2..509ac9f 100644 (file)
@@ -280,7 +280,7 @@ private:
                                                         : LocalCoords::kUnused_Type;
             Coverage::Type coverageType;
             if (fAntiAlias) {
-                color = Color(Color::kAttribute_Type);
+                color = Color(Color::kPremulGrColorAttribute_Type);
                 if (fCanTweakAlphaForCoverage) {
                     coverageType = Coverage::kSolid_Type;
                 } else {