GrDrawVerticesOp::GrDrawVerticesOp(const Helper::MakeArgs& helperArgs, GrColor color, sk_sp<SkVertices> vertices, GrPrimitiveType primitiveType, GrAAType aaType, bool gammaCorrect, sk_sp<GrColorSpaceXform> colorSpaceXform, const SkMatrix& viewMatrix) : INHERITED(ClassID()) , fHelper(helperArgs, aaType) , fPrimitiveType(primitiveType) , fColorSpaceXform(std::move(colorSpaceXform)) { SkASSERT(vertices); fVertexCount = vertices->vertexCount(); fIndexCount = vertices->indexCount(); fColorArrayType = vertices->hasColors() ? ColorArrayType::kSkColor : ColorArrayType::kPremulGrColor; // GrColor is linearized (and gamut converted) during paint conversion, but SkColors need to be // handled in the shader fLinearizeColors = gammaCorrect && vertices->hasColors(); Mesh& mesh = fMeshes.push_back(); mesh.fColor = color; mesh.fViewMatrix = viewMatrix; mesh.fVertices = std::move(vertices); mesh.fIgnoreTexCoords = false; mesh.fIgnoreColors = false; fFlags = 0; if (mesh.hasPerVertexColors()) { fFlags |= kRequiresPerVertexColors_Flag; } if (mesh.hasExplicitLocalCoords()) { fFlags |= kAnyMeshHasExplicitLocalCoords; } IsZeroArea zeroArea; if (GrIsPrimTypeLines(primitiveType) || GrPrimitiveType::kPoints == primitiveType) { zeroArea = IsZeroArea::kYes; } else { zeroArea = IsZeroArea::kNo; } this->setTransformedBounds(mesh.fVertices->bounds(), viewMatrix, HasAABloat::kNo, zeroArea); }
GrDrawVerticesOp::GrDrawVerticesOp(const Helper::MakeArgs& helperArgs, GrColor color, sk_sp<SkVertices> vertices, const SkVertices::Bone bones[], int boneCount, GrPrimitiveType primitiveType, GrAAType aaType, sk_sp<GrColorSpaceXform> colorSpaceXform, const SkMatrix& viewMatrix) : INHERITED(ClassID()) , fHelper(helperArgs, aaType) , fPrimitiveType(primitiveType) , fColorSpaceXform(std::move(colorSpaceXform)) { SkASSERT(vertices); fVertexCount = vertices->vertexCount(); fIndexCount = vertices->indexCount(); fColorArrayType = vertices->hasColors() ? ColorArrayType::kSkColor : ColorArrayType::kPremulGrColor; Mesh& mesh = fMeshes.push_back(); mesh.fColor = color; mesh.fViewMatrix = viewMatrix; mesh.fVertices = std::move(vertices); mesh.fIgnoreTexCoords = false; mesh.fIgnoreColors = false; mesh.fIgnoreBones = false; if (mesh.fVertices->hasBones() && bones) { // Perform the transformations on the CPU instead of the GPU. mesh.fVertices = mesh.fVertices->applyBones(bones, boneCount); } else { if (bones && boneCount > 1) { // NOTE: This should never be used. All bone transforms are being done on the CPU // instead of the GPU. // Copy the bone data. fBones.assign(bones, bones + boneCount); } } fFlags = 0; if (mesh.hasPerVertexColors()) { fFlags |= kRequiresPerVertexColors_Flag; } if (mesh.hasExplicitLocalCoords()) { fFlags |= kAnyMeshHasExplicitLocalCoords_Flag; } if (mesh.hasBones()) { fFlags |= kHasBones_Flag; } // Special case for meshes with a world transform but no bone weights. // These will be considered normal vertices draws without bones. if (!mesh.fVertices->hasBones() && boneCount == 1) { SkMatrix worldTransform; worldTransform.setAffine(bones[0].values); mesh.fViewMatrix.preConcat(worldTransform); } IsZeroArea zeroArea; if (GrIsPrimTypeLines(primitiveType) || GrPrimitiveType::kPoints == primitiveType) { zeroArea = IsZeroArea::kYes; } else { zeroArea = IsZeroArea::kNo; } if (this->hasBones()) { // We don't know the bounds if there are deformations involved, so attempt to calculate // the maximum possible. SkRect bounds = SkRect::MakeEmpty(); const SkRect originalBounds = bones[0].mapRect(mesh.fVertices->bounds()); for (int i = 1; i < boneCount; i++) { const SkVertices::Bone& matrix = bones[i]; bounds.join(matrix.mapRect(originalBounds)); } this->setTransformedBounds(bounds, mesh.fViewMatrix, HasAABloat::kNo, zeroArea); } else { this->setTransformedBounds(mesh.fVertices->bounds(), mesh.fViewMatrix, HasAABloat::kNo, zeroArea); } }