bool SkPaint2GrPaint(GrContext* context, GrRenderTarget* rt, const SkPaint& skPaint, const SkMatrix& viewM, bool constantColor, GrPaint* grPaint) { SkShader* shader = skPaint.getShader(); if (NULL == shader) { return SkPaint2GrPaintNoShader(context, rt, skPaint, SkColor2GrColor(skPaint.getColor()), constantColor, grPaint); } GrColor paintColor = SkColor2GrColor(skPaint.getColor()); // Start a new block here in order to preserve our context state after calling // asFragmentProcessor(). Since these calls get passed back to the client, we don't really // want them messing around with the context. { // Allow the shader to modify paintColor and also create an effect to be installed as // the first color effect on the GrPaint. GrFragmentProcessor* fp = NULL; if (!shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintColor, grPaint->getProcessorDataManager(), &fp)) { return false; } if (fp) { grPaint->addColorProcessor(fp)->unref(); constantColor = false; } } // The grcolor is automatically set when calling asFragmentProcessor. // If the shader can be seen as an effect it returns true and adds its effect to the grpaint. return SkPaint2GrPaintNoShader(context, rt, skPaint, paintColor, constantColor, grPaint); }
bool SkPaint2GrPaint(GrContext* context, GrRenderTarget* rt, const SkPaint& skPaint, const SkMatrix& viewM, bool constantColor, GrPaint* grPaint) { SkShader* shader = skPaint.getShader(); if (nullptr == shader) { return SkPaint2GrPaintNoShader(context, rt, skPaint, SkColor2GrColor(skPaint.getColor()), constantColor, grPaint); } GrColor paintColor = SkColor2GrColor(skPaint.getColor()); const GrFragmentProcessor* fp = shader->asFragmentProcessor(context, viewM, NULL, skPaint.getFilterQuality(), grPaint->getProcessorDataManager()); if (!fp) { return false; } grPaint->addColorFragmentProcessor(fp)->unref(); constantColor = false; // The grcolor is automatically set when calling asFragmentProcessor. // If the shader can be seen as an effect it returns true and adds its effect to the grpaint. return SkPaint2GrPaintNoShader(context, rt, skPaint, paintColor, constantColor, grPaint); }