Remove special case arena-based allocation of Compose and Color shaders

This is set up to eliminate SkComposeShader.h and SkColorShader.h

Bug: skia:13438
Change-Id: I16d3ea233220061559f5499fb0824dba1e3e699d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/555160
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2022-07-01 12:46:42 -04:00 committed by SkCQ
parent 72ae8ebf5f
commit 79a71e7fd2
2 changed files with 24 additions and 22 deletions

View File

@ -9,6 +9,7 @@
#include "include/core/SkMatrix.h"
#include "include/core/SkRSXform.h"
#include "src/core/SkBlendModePriv.h"
#include "src/core/SkBlenderBase.h"
#include "src/core/SkColorSpacePriv.h"
#include "src/core/SkColorSpaceXformSteps.h"
#include "src/core/SkCoreBlitters.h"
@ -17,10 +18,8 @@
#include "src/core/SkRasterClip.h"
#include "src/core/SkRasterPipeline.h"
#include "src/core/SkScan.h"
#include "src/core/SkScan.h"
#include "src/core/SkVM.h"
#include "src/core/SkVMBlitter.h"
#include "src/shaders/SkComposeShader.h"
#include "src/shaders/SkShaderBase.h"
static void fill_rect(const SkMatrix& ctm, const SkRasterClip& rc,
@ -186,15 +185,16 @@ void SkDraw::drawAtlas(const SkRSXform xform[],
if (gUseSkVMBlitter || !rpblit()) {
auto updateShader = as_SB(atlasShader)->updatableShader(&alloc);
UpdatableColorShader* colorShader = nullptr;
SkShaderBase* shader = nullptr;
sk_sp<SkShader> shader;
if (colors) {
colorShader = alloc.make<UpdatableColorShader>(fDst.colorSpace());
shader = alloc.make<SkShader_Blend>(
std::move(blender), sk_ref_sp(colorShader), sk_ref_sp(updateShader));
shader = SkShaders::Blend(std::move(blender),
sk_ref_sp(colorShader),
sk_ref_sp(updateShader));
} else {
shader = as_SB(updateShader);
shader = sk_ref_sp(updateShader);
}
p.setShader(sk_ref_sp(shader));
p.setShader(std::move(shader));
if (auto blitter = SkVMBlitter::Make(fDst, p, *fMatrixProvider, &alloc,
fRC->clipShader())) {
SkPath scratchPath;

View File

@ -10,6 +10,7 @@
#include "include/private/SkVx.h"
#include "src/core/SkArenaAlloc.h"
#include "src/core/SkAutoBlitterChoose.h"
#include "src/core/SkBlenderBase.h"
#include "src/core/SkConvertPixels.h"
#include "src/core/SkCoreBlitters.h"
#include "src/core/SkDraw.h"
@ -21,8 +22,6 @@
#include "src/core/SkVMBlitter.h"
#include "src/core/SkVertState.h"
#include "src/core/SkVerticesPriv.h"
#include "src/shaders/SkColorShader.h"
#include "src/shaders/SkComposeShader.h"
#include "src/shaders/SkShaderBase.h"
struct Matrix43 {
@ -375,29 +374,33 @@ void SkDraw::drawFixedVertices(const SkVertices* vertices,
}
// Combines per-vertex colors with 'shader' using 'blender'.
auto applyShaderColorBlend = [&](SkShader* shader) -> SkShader* {
auto applyShaderColorBlend = [&](SkShader* shader) -> sk_sp<SkShader> {
if (!colors) {
return shader;
return sk_ref_sp(shader);
}
if (blenderIsDst) {
return triColorShader;
return sk_ref_sp(triColorShader);
}
sk_sp<SkShader> shaderWithWhichToBlend;
if (!shader) {
// When there is no shader then the blender applies to the vertex colors and opaque
// paint color.
shader = outerAlloc->make<SkColor4Shader>(paint.getColor4f().makeOpaque(), nullptr);
shaderWithWhichToBlend = SkShaders::Color(paint.getColor4f().makeOpaque(), nullptr);
} else {
shaderWithWhichToBlend = sk_ref_sp(shader);
}
return outerAlloc->make<SkShader_Blend>(
blender, sk_ref_sp(triColorShader), sk_ref_sp(shader));
return SkShaders::Blend(blender,
sk_ref_sp(triColorShader),
std::move(shaderWithWhichToBlend));
};
auto rpblit = [&]() {
VertState state(vertexCount, indices, indexCount);
VertState::Proc vertProc = state.chooseProc(info.mode());
SkShader* shader = applyShaderColorBlend(paintShader);
sk_sp<SkShader> blendShader = applyShaderColorBlend(paintShader);
SkPaint shaderPaint(paint);
shaderPaint.setShader(sk_ref_sp(shader));
shaderPaint.setShader(blendShader);
if (!texCoords) { // only tricolor shader
auto blitter = SkCreateRasterPipelineBlitter(
@ -423,8 +426,8 @@ void SkDraw::drawFixedVertices(const SkVertices* vertices,
shaderPaint,
nullptr,
*fMatrixProvider};
if (auto updater = as_SB(shader)->appendUpdatableStages(rec)) {
bool isOpaque = shader->isOpaque();
if (auto updater = as_SB(blendShader)->appendUpdatableStages(rec)) {
bool isOpaque = blendShader->isOpaque();
if (triColorShader) {
isOpaque = false; // unless we want to walk all the colors, and see if they are
// all opaque (and the blend mode will keep them that way
@ -499,10 +502,10 @@ void SkDraw::drawFixedVertices(const SkVertices* vertices,
texCoordShader = as_SB(shader)->updatableShader(outerAlloc);
shader = texCoordShader;
}
shader = applyShaderColorBlend(shader);
sk_sp<SkShader> blenderShader = applyShaderColorBlend(shader);
SkPaint shaderPaint{paint};
shaderPaint.setShader(sk_ref_sp(shader));
shaderPaint.setShader(std::move(blenderShader));
auto blitter = SkVMBlitter::Make(
fDst, shaderPaint, *fMatrixProvider, outerAlloc, this->fRC->clipShader());
if (!blitter) {
@ -545,7 +548,6 @@ void SkDraw::drawVertices(const SkVertices* vertices,
constexpr size_t kDefVertexCount = 16;
constexpr size_t kOuterSize = sizeof(SkTriColorShader) +
sizeof(SkShader_Blend) +
(2 * sizeof(SkPoint) + sizeof(SkColor4f)) * kDefVertexCount;
SkSTArenaAlloc<kOuterSize> outerAlloc;