Revert "Move more Ops to skgpu::v1 namespace"
This reverts commit f3158abda3
.
Reason for revert: Broke Flutter build
Original change's description:
> Move more Ops to skgpu::v1 namespace
>
> GrClearOp
> GrDashOp
>
> Bug: skia:11837
> Change-Id: Ib65418952e7d4fb1e419e4942223823f22302b34
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/443518
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>
TBR=robertphillips@google.com,michaelludwig@google.com,skcq-be@skia-corp.google.com.iam.gserviceaccount.com
Change-Id: Ic181ced7f5f2a8ff834fdcfb4e5265b99eef1666
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:11837
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/444365
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
600481f871
commit
5fe828accb
@ -507,16 +507,16 @@ skia_skgpu_v1_sources = [
|
||||
"$_src/gpu/ops/AtlasRenderTask.h",
|
||||
"$_src/gpu/ops/AtlasTextOp.cpp",
|
||||
"$_src/gpu/ops/AtlasTextOp.h",
|
||||
"$_src/gpu/ops/ClearOp.cpp",
|
||||
"$_src/gpu/ops/ClearOp.h",
|
||||
"$_src/gpu/ops/DashLinePathRenderer.cpp",
|
||||
"$_src/gpu/ops/DashLinePathRenderer.h",
|
||||
"$_src/gpu/ops/DashOp.cpp",
|
||||
"$_src/gpu/ops/DashOp.h",
|
||||
"$_src/gpu/ops/DefaultPathRenderer.cpp",
|
||||
"$_src/gpu/ops/DefaultPathRenderer.h",
|
||||
"$_src/gpu/ops/GrAtlasInstancedHelper.cpp",
|
||||
"$_src/gpu/ops/GrAtlasInstancedHelper.h",
|
||||
"$_src/gpu/ops/GrClearOp.cpp",
|
||||
"$_src/gpu/ops/GrClearOp.h",
|
||||
"$_src/gpu/ops/GrDashOp.cpp",
|
||||
"$_src/gpu/ops/GrDashOp.h",
|
||||
"$_src/gpu/ops/GrDrawAtlasOp.cpp",
|
||||
"$_src/gpu/ops/GrDrawAtlasOp.h",
|
||||
"$_src/gpu/ops/GrDrawAtlasPathOp.cpp",
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "src/gpu/GrAuditTrail.h"
|
||||
#include "src/gpu/GrGpu.h"
|
||||
#include "src/gpu/geometry/GrStyledShape.h"
|
||||
#include "src/gpu/ops/DashOp.h"
|
||||
#include "src/gpu/ops/GrDashOp.h"
|
||||
#include "src/gpu/ops/GrMeshDrawOp.h"
|
||||
#include "src/gpu/v1/SurfaceDrawContext_v1.h"
|
||||
|
||||
@ -22,7 +22,7 @@ PathRenderer::CanDrawPath DashLinePathRenderer::onCanDrawPath(const CanDrawPathA
|
||||
if (args.fShape->style().isDashed() && args.fShape->asLine(pts, &inverted)) {
|
||||
// We should never have an inverse dashed case.
|
||||
SkASSERT(!inverted);
|
||||
if (!DashOp::CanDrawDashLine(pts, args.fShape->style(), *args.fViewMatrix)) {
|
||||
if (!GrDashOp::CanDrawDashLine(pts, args.fShape->style(), *args.fViewMatrix)) {
|
||||
return CanDrawPath::kNo;
|
||||
}
|
||||
return CanDrawPath::kYes;
|
||||
@ -33,25 +33,25 @@ PathRenderer::CanDrawPath DashLinePathRenderer::onCanDrawPath(const CanDrawPathA
|
||||
bool DashLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
|
||||
GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(),
|
||||
"DashLinePathRenderer::onDrawPath");
|
||||
DashOp::AAMode aaMode;
|
||||
GrDashOp::AAMode aaMode;
|
||||
switch (args.fAAType) {
|
||||
case GrAAType::kNone:
|
||||
aaMode = DashOp::AAMode::kNone;
|
||||
aaMode = GrDashOp::AAMode::kNone;
|
||||
break;
|
||||
case GrAAType::kMSAA:
|
||||
// In this mode we will use aa between dashes but the outer border uses MSAA. Otherwise,
|
||||
// we can wind up with external edges antialiased and internal edges unantialiased.
|
||||
aaMode = DashOp::AAMode::kCoverageWithMSAA;
|
||||
aaMode = GrDashOp::AAMode::kCoverageWithMSAA;
|
||||
break;
|
||||
case GrAAType::kCoverage:
|
||||
aaMode = DashOp::AAMode::kCoverage;
|
||||
aaMode = GrDashOp::AAMode::kCoverage;
|
||||
break;
|
||||
}
|
||||
SkPoint pts[2];
|
||||
SkAssertResult(args.fShape->asLine(pts, nullptr));
|
||||
GrOp::Owner op = DashOp::MakeDashLineOp(args.fContext, std::move(args.fPaint),
|
||||
*args.fViewMatrix, pts, aaMode, args.fShape->style(),
|
||||
args.fUserStencilSettings);
|
||||
GrOp::Owner op =
|
||||
GrDashOp::MakeDashLineOp(args.fContext, std::move(args.fPaint), *args.fViewMatrix, pts,
|
||||
aaMode, args.fShape->style(), args.fUserStencilSettings);
|
||||
if (!op) {
|
||||
return false;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "src/gpu/ops/ClearOp.h"
|
||||
#include "src/gpu/ops/GrClearOp.h"
|
||||
|
||||
#include "include/gpu/GrRecordingContext.h"
|
||||
#include "src/gpu/GrMemoryPool.h"
|
||||
@ -14,37 +14,31 @@
|
||||
#include "src/gpu/GrProxyProvider.h"
|
||||
#include "src/gpu/GrRecordingContextPriv.h"
|
||||
|
||||
namespace {
|
||||
|
||||
bool contains_scissor(const GrScissorState& a, const GrScissorState& b) {
|
||||
static bool contains_scissor(const GrScissorState& a, const GrScissorState& b) {
|
||||
return !a.enabled() || (b.enabled() && a.rect().contains(b.rect()));
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace skgpu::v1 {
|
||||
|
||||
GrOp::Owner ClearOp::MakeColor(GrRecordingContext* context,
|
||||
const GrScissorState& scissor,
|
||||
std::array<float, 4> color) {
|
||||
return GrOp::Make<ClearOp>(context, Buffer::kColor, scissor, color, false);
|
||||
GrOp::Owner GrClearOp::MakeColor(GrRecordingContext* context,
|
||||
const GrScissorState& scissor,
|
||||
std::array<float, 4> color) {
|
||||
return GrOp::Make<GrClearOp>(context, Buffer::kColor, scissor, color, false);
|
||||
}
|
||||
|
||||
GrOp::Owner ClearOp::MakeStencilClip(GrRecordingContext* context,
|
||||
const GrScissorState& scissor,
|
||||
bool insideMask) {
|
||||
return GrOp::Make<ClearOp>(context,
|
||||
Buffer::kStencilClip,
|
||||
scissor,
|
||||
std::array<float, 4>(),
|
||||
insideMask);
|
||||
GrOp::Owner GrClearOp::MakeStencilClip(GrRecordingContext* context,
|
||||
const GrScissorState& scissor,
|
||||
bool insideMask) {
|
||||
return GrOp::Make<GrClearOp>(context,
|
||||
Buffer::kStencilClip,
|
||||
scissor,
|
||||
std::array<float, 4>(),
|
||||
insideMask);
|
||||
}
|
||||
|
||||
ClearOp::ClearOp(Buffer buffer,
|
||||
const GrScissorState& scissor,
|
||||
std::array<float, 4> color,
|
||||
bool insideMask)
|
||||
: GrOp(ClassID())
|
||||
GrClearOp::GrClearOp(Buffer buffer,
|
||||
const GrScissorState& scissor,
|
||||
std::array<float, 4> color,
|
||||
bool insideMask)
|
||||
: INHERITED(ClassID())
|
||||
, fScissor(scissor)
|
||||
, fColor(color)
|
||||
, fStencilInsideMask(insideMask)
|
||||
@ -52,8 +46,8 @@ ClearOp::ClearOp(Buffer buffer,
|
||||
this->setBounds(SkRect::Make(scissor.rect()), HasAABloat::kNo, IsHairline::kNo);
|
||||
}
|
||||
|
||||
GrOp::CombineResult ClearOp::onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) {
|
||||
auto other = t->cast<ClearOp>();
|
||||
GrOp::CombineResult GrClearOp::onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) {
|
||||
GrClearOp* other = t->cast<GrClearOp>();
|
||||
|
||||
if (other->fBuffer == fBuffer) {
|
||||
// This could be much more complicated. Currently we look at cases where the new clear
|
||||
@ -83,7 +77,7 @@ GrOp::CombineResult ClearOp::onCombineIfPossible(GrOp* t, SkArenaAlloc*, const G
|
||||
return CombineResult::kCannotCombine;
|
||||
}
|
||||
|
||||
void ClearOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
|
||||
void GrClearOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
|
||||
SkASSERT(state->opsRenderPass());
|
||||
if (fBuffer & Buffer::kColor) {
|
||||
state->opsRenderPass()->clear(fScissor, fColor);
|
||||
@ -93,6 +87,3 @@ void ClearOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
|
||||
state->opsRenderPass()->clearStencilClip(fScissor, fStencilInsideMask);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace skgpu::v1
|
||||
|
@ -5,8 +5,8 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef ClearOp_DEFINED
|
||||
#define ClearOp_DEFINED
|
||||
#ifndef GrClearOp_DEFINED
|
||||
#define GrClearOp_DEFINED
|
||||
|
||||
#include "include/gpu/GrTypes.h"
|
||||
#include "src/gpu/GrScissorState.h"
|
||||
@ -15,9 +15,7 @@
|
||||
class GrOpFlushState;
|
||||
class GrRecordingContext;
|
||||
|
||||
namespace skgpu::v1 {
|
||||
|
||||
class ClearOp final : public GrOp {
|
||||
class GrClearOp final : public GrOp {
|
||||
public:
|
||||
DEFINE_OP_CLASS_ID
|
||||
|
||||
@ -45,10 +43,10 @@ private:
|
||||
};
|
||||
GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Buffer);
|
||||
|
||||
ClearOp(Buffer buffer,
|
||||
const GrScissorState& scissor,
|
||||
std::array<float, 4> color,
|
||||
bool stencil);
|
||||
GrClearOp(Buffer buffer,
|
||||
const GrScissorState& scissor,
|
||||
std::array<float, 4> color,
|
||||
bool stencil);
|
||||
|
||||
CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override;
|
||||
|
||||
@ -77,10 +75,10 @@ private:
|
||||
std::array<float, 4> fColor;
|
||||
bool fStencilInsideMask;
|
||||
Buffer fBuffer;
|
||||
|
||||
using INHERITED = GrOp;
|
||||
};
|
||||
|
||||
GR_MAKE_BITFIELD_CLASS_OPS(ClearOp::Buffer)
|
||||
GR_MAKE_BITFIELD_CLASS_OPS(GrClearOp::Buffer)
|
||||
|
||||
} // namespace skgpu::v1
|
||||
|
||||
#endif // ClearOp_DEFINED
|
||||
#endif
|
@ -5,7 +5,7 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "src/gpu/ops/DashOp.h"
|
||||
#include "src/gpu/ops/GrDashOp.h"
|
||||
|
||||
#include "include/gpu/GrRecordingContext.h"
|
||||
#include "src/core/SkMatrixPriv.h"
|
||||
@ -13,6 +13,7 @@
|
||||
#include "src/gpu/GrAppliedClip.h"
|
||||
#include "src/gpu/GrCaps.h"
|
||||
#include "src/gpu/GrDefaultGeoProcFactory.h"
|
||||
#include "src/gpu/GrDrawOpTest.h"
|
||||
#include "src/gpu/GrGeometryProcessor.h"
|
||||
#include "src/gpu/GrMemoryPool.h"
|
||||
#include "src/gpu/GrOpFlushState.h"
|
||||
@ -31,14 +32,51 @@
|
||||
#include "src/gpu/ops/GrMeshDrawOp.h"
|
||||
#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
|
||||
|
||||
using AAMode = skgpu::v1::DashOp::AAMode;
|
||||
using AAMode = GrDashOp::AAMode;
|
||||
|
||||
static const int kAAModeCnt = static_cast<int>(skgpu::v1::DashOp::AAMode::kCoverageWithMSAA) + 1;
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace {
|
||||
// Returns whether or not the gpu can fast path the dash line effect.
|
||||
bool GrDashOp::CanDrawDashLine(const SkPoint pts[2], const GrStyle& style,
|
||||
const SkMatrix& viewMatrix) {
|
||||
// Pts must be either horizontal or vertical in src space
|
||||
if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void calc_dash_scaling(SkScalar* parallelScale, SkScalar* perpScale,
|
||||
const SkMatrix& viewMatrix, const SkPoint pts[2]) {
|
||||
// May be able to relax this to include skew. As of now cannot do perspective
|
||||
// because of the non uniform scaling of bloating a rect
|
||||
if (!viewMatrix.preservesRightAngles()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!style.isDashed() || 2 != style.dashIntervalCnt()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const SkScalar* intervals = style.dashIntervals();
|
||||
if (0 == intervals[0] && 0 == intervals[1]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SkPaint::Cap cap = style.strokeRec().getCap();
|
||||
if (SkPaint::kRound_Cap == cap) {
|
||||
// Current we don't support round caps unless the on interval is zero
|
||||
if (intervals[0] != 0.f) {
|
||||
return false;
|
||||
}
|
||||
// If the width of the circle caps in greater than the off interval we will pick up unwanted
|
||||
// segments of circles at the start and end of the dash line.
|
||||
if (style.strokeRec().getWidth() > intervals[1]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void calc_dash_scaling(SkScalar* parallelScale, SkScalar* perpScale,
|
||||
const SkMatrix& viewMatrix, const SkPoint pts[2]) {
|
||||
SkVector vecSrc = pts[1] - pts[0];
|
||||
if (pts[1] == pts[0]) {
|
||||
vecSrc.set(1.0, 0.0);
|
||||
@ -60,7 +98,7 @@ void calc_dash_scaling(SkScalar* parallelScale, SkScalar* perpScale,
|
||||
|
||||
// calculates the rotation needed to aligned pts to the x axis with pts[0] < pts[1]
|
||||
// Stores the rotation matrix in rotMatrix, and the mapped points in ptsRot
|
||||
void align_to_x_axis(const SkPoint pts[2], SkMatrix* rotMatrix, SkPoint ptsRot[2] = nullptr) {
|
||||
static void align_to_x_axis(const SkPoint pts[2], SkMatrix* rotMatrix, SkPoint ptsRot[2] = nullptr) {
|
||||
SkVector vec = pts[1] - pts[0];
|
||||
if (pts[1] == pts[0]) {
|
||||
vec.set(1.0, 0.0);
|
||||
@ -78,7 +116,7 @@ void align_to_x_axis(const SkPoint pts[2], SkMatrix* rotMatrix, SkPoint ptsRot[2
|
||||
}
|
||||
|
||||
// Assumes phase < sum of all intervals
|
||||
SkScalar calc_start_adjustment(const SkScalar intervals[2], SkScalar phase) {
|
||||
static SkScalar calc_start_adjustment(const SkScalar intervals[2], SkScalar phase) {
|
||||
SkASSERT(phase < intervals[0] + intervals[1]);
|
||||
if (phase >= intervals[0] && phase != 0) {
|
||||
SkScalar srcIntervalLen = intervals[0] + intervals[1];
|
||||
@ -87,8 +125,8 @@ SkScalar calc_start_adjustment(const SkScalar intervals[2], SkScalar phase) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SkScalar calc_end_adjustment(const SkScalar intervals[2], const SkPoint pts[2],
|
||||
SkScalar phase, SkScalar* endingInt) {
|
||||
static SkScalar calc_end_adjustment(const SkScalar intervals[2], const SkPoint pts[2],
|
||||
SkScalar phase, SkScalar* endingInt) {
|
||||
if (pts[1].fX <= pts[0].fX) {
|
||||
return 0;
|
||||
}
|
||||
@ -113,17 +151,17 @@ enum DashCap {
|
||||
kNonRound_DashCap,
|
||||
};
|
||||
|
||||
void setup_dashed_rect(const SkRect& rect,
|
||||
GrVertexWriter& vertices,
|
||||
const SkMatrix& matrix,
|
||||
SkScalar offset,
|
||||
SkScalar bloatX,
|
||||
SkScalar len,
|
||||
SkScalar startInterval,
|
||||
SkScalar endInterval,
|
||||
SkScalar strokeWidth,
|
||||
SkScalar perpScale,
|
||||
DashCap cap) {
|
||||
static void setup_dashed_rect(const SkRect& rect,
|
||||
GrVertexWriter& vertices,
|
||||
const SkMatrix& matrix,
|
||||
SkScalar offset,
|
||||
SkScalar bloatX,
|
||||
SkScalar len,
|
||||
SkScalar startInterval,
|
||||
SkScalar endInterval,
|
||||
SkScalar strokeWidth,
|
||||
SkScalar perpScale,
|
||||
DashCap cap) {
|
||||
SkScalar intervalLength = startInterval + endInterval;
|
||||
// 'dashRect' gets interpolated over the rendered 'rect'. For y we want the perpendicular signed
|
||||
// distance from the stroke center line in device space. 'perpScale' is the scale factor applied
|
||||
@ -162,14 +200,14 @@ void setup_dashed_rect(const SkRect& rect,
|
||||
* Bounding geometry is rendered and the effect computes coverage based on the fragment's
|
||||
* position relative to the dashed line.
|
||||
*/
|
||||
GrGeometryProcessor* make_dash_gp(SkArenaAlloc* arena,
|
||||
const SkPMColor4f&,
|
||||
AAMode aaMode,
|
||||
DashCap cap,
|
||||
const SkMatrix& localMatrix,
|
||||
bool usesLocalCoords);
|
||||
static GrGeometryProcessor* make_dash_gp(SkArenaAlloc* arena,
|
||||
const SkPMColor4f&,
|
||||
AAMode aaMode,
|
||||
DashCap cap,
|
||||
const SkMatrix& localMatrix,
|
||||
bool usesLocalCoords);
|
||||
|
||||
class DashOpImpl final : public GrMeshDrawOp {
|
||||
class DashOp final : public GrMeshDrawOp {
|
||||
public:
|
||||
DEFINE_OP_CLASS_ID
|
||||
|
||||
@ -190,8 +228,8 @@ public:
|
||||
SkPaint::Cap cap,
|
||||
AAMode aaMode, bool fullDash,
|
||||
const GrUserStencilSettings* stencilSettings) {
|
||||
return GrOp::Make<DashOpImpl>(context, std::move(paint), geometry, cap,
|
||||
aaMode, fullDash, stencilSettings);
|
||||
return GrOp::Make<DashOp>(context, std::move(paint), geometry, cap,
|
||||
aaMode, fullDash, stencilSettings);
|
||||
}
|
||||
|
||||
const char* name() const override { return "DashOp"; }
|
||||
@ -227,8 +265,8 @@ public:
|
||||
private:
|
||||
friend class GrOp; // for ctor
|
||||
|
||||
DashOpImpl(GrPaint&& paint, const LineData& geometry, SkPaint::Cap cap, AAMode aaMode,
|
||||
bool fullDash, const GrUserStencilSettings* stencilSettings)
|
||||
DashOp(GrPaint&& paint, const LineData& geometry, SkPaint::Cap cap, AAMode aaMode,
|
||||
bool fullDash, const GrUserStencilSettings* stencilSettings)
|
||||
: INHERITED(ClassID())
|
||||
, fColor(paint.getColor4f())
|
||||
, fFullDash(fullDash)
|
||||
@ -623,7 +661,7 @@ private:
|
||||
}
|
||||
|
||||
CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override {
|
||||
auto that = t->cast<DashOpImpl>();
|
||||
DashOp* that = t->cast<DashOp>();
|
||||
if (fProcessorSet != that->fProcessorSet) {
|
||||
return CombineResult::kCannotCombine;
|
||||
}
|
||||
@ -677,6 +715,9 @@ private:
|
||||
bool fullDash() const { return fFullDash; }
|
||||
SkPaint::Cap cap() const { return fCap; }
|
||||
|
||||
static const int kVertsPerDash = 4;
|
||||
static const int kIndicesPerDash = 6;
|
||||
|
||||
SkSTArray<1, LineData, true> fLines;
|
||||
SkPMColor4f fColor;
|
||||
bool fUsesLocalCoords : 1;
|
||||
@ -693,6 +734,68 @@ private:
|
||||
using INHERITED = GrMeshDrawOp;
|
||||
};
|
||||
|
||||
GrOp::Owner GrDashOp::MakeDashLineOp(GrRecordingContext* context,
|
||||
GrPaint&& paint,
|
||||
const SkMatrix& viewMatrix,
|
||||
const SkPoint pts[2],
|
||||
AAMode aaMode,
|
||||
const GrStyle& style,
|
||||
const GrUserStencilSettings* stencilSettings) {
|
||||
SkASSERT(GrDashOp::CanDrawDashLine(pts, style, viewMatrix));
|
||||
const SkScalar* intervals = style.dashIntervals();
|
||||
SkScalar phase = style.dashPhase();
|
||||
|
||||
SkPaint::Cap cap = style.strokeRec().getCap();
|
||||
|
||||
DashOp::LineData lineData;
|
||||
lineData.fSrcStrokeWidth = style.strokeRec().getWidth();
|
||||
|
||||
// the phase should be normalized to be [0, sum of all intervals)
|
||||
SkASSERT(phase >= 0 && phase < intervals[0] + intervals[1]);
|
||||
|
||||
// Rotate the src pts so they are aligned horizontally with pts[0].fX < pts[1].fX
|
||||
if (pts[0].fY != pts[1].fY || pts[0].fX > pts[1].fX) {
|
||||
SkMatrix rotMatrix;
|
||||
align_to_x_axis(pts, &rotMatrix, lineData.fPtsRot);
|
||||
if (!rotMatrix.invert(&lineData.fSrcRotInv)) {
|
||||
SkDebugf("Failed to create invertible rotation matrix!\n");
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
lineData.fSrcRotInv.reset();
|
||||
memcpy(lineData.fPtsRot, pts, 2 * sizeof(SkPoint));
|
||||
}
|
||||
|
||||
// Scale corrections of intervals and stroke from view matrix
|
||||
calc_dash_scaling(&lineData.fParallelScale, &lineData.fPerpendicularScale, viewMatrix, pts);
|
||||
if (SkScalarNearlyZero(lineData.fParallelScale) ||
|
||||
SkScalarNearlyZero(lineData.fPerpendicularScale)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkScalar offInterval = intervals[1] * lineData.fParallelScale;
|
||||
SkScalar strokeWidth = lineData.fSrcStrokeWidth * lineData.fPerpendicularScale;
|
||||
|
||||
if (SkPaint::kSquare_Cap == cap && 0 != lineData.fSrcStrokeWidth) {
|
||||
// add cap to on interval and remove from off interval
|
||||
offInterval -= strokeWidth;
|
||||
}
|
||||
|
||||
// TODO we can do a real rect call if not using fulldash(ie no off interval, not using AA)
|
||||
bool fullDash = offInterval > 0.f || aaMode != AAMode::kNone;
|
||||
|
||||
lineData.fViewMatrix = viewMatrix;
|
||||
lineData.fPhase = phase;
|
||||
lineData.fIntervals[0] = intervals[0];
|
||||
lineData.fIntervals[1] = intervals[1];
|
||||
|
||||
return DashOp::Make(context, std::move(paint), lineData, cap, aaMode, fullDash,
|
||||
stencilSettings);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace {
|
||||
/*
|
||||
* This effect will draw a dotted line (defined as a dashed lined with round caps and no on
|
||||
* interval). The radius of the dots is given by the strokeWidth and the spacing by the DashInfo.
|
||||
@ -737,6 +840,7 @@ private:
|
||||
|
||||
using INHERITED = GrGeometryProcessor;
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -870,7 +974,7 @@ GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect);
|
||||
|
||||
#if GR_TEST_UTILS
|
||||
GrGeometryProcessor* DashingCircleEffect::TestCreate(GrProcessorTestData* d) {
|
||||
AAMode aaMode = static_cast<AAMode>(d->fRandom->nextULessThan(kAAModeCnt));
|
||||
AAMode aaMode = static_cast<AAMode>(d->fRandom->nextULessThan(GrDashOp::kAAModeCnt));
|
||||
GrColor color = GrTest::RandomColor(d->fRandom);
|
||||
SkMatrix matrix = GrTest::TestMatrix(d->fRandom);
|
||||
return DashingCircleEffect::Make(d->allocator(),
|
||||
@ -883,6 +987,7 @@ GrGeometryProcessor* DashingCircleEffect::TestCreate(GrProcessorTestData* d) {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace {
|
||||
/*
|
||||
* This effect will draw a dashed line. The width of the dash is given by the strokeWidth and the
|
||||
* length and spacing by the DashInfo. Both of the previous two parameters are in device space.
|
||||
@ -929,6 +1034,7 @@ private:
|
||||
|
||||
using INHERITED = GrGeometryProcessor;
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -1069,11 +1175,11 @@ DashingLineEffect::DashingLineEffect(const SkPMColor4f& color,
|
||||
AAMode aaMode,
|
||||
const SkMatrix& localMatrix,
|
||||
bool usesLocalCoords)
|
||||
: INHERITED(kDashingLineEffect_ClassID)
|
||||
, fColor(color)
|
||||
, fLocalMatrix(localMatrix)
|
||||
, fUsesLocalCoords(usesLocalCoords)
|
||||
, fAAMode(aaMode) {
|
||||
: INHERITED(kDashingLineEffect_ClassID)
|
||||
, fColor(color)
|
||||
, fLocalMatrix(localMatrix)
|
||||
, fUsesLocalCoords(usesLocalCoords)
|
||||
, fAAMode(aaMode) {
|
||||
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
|
||||
fInDashParams = {"inDashParams", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
|
||||
fInRect = {"inRect", kFloat4_GrVertexAttribType, kHalf4_GrSLType};
|
||||
@ -1084,7 +1190,7 @@ GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect);
|
||||
|
||||
#if GR_TEST_UTILS
|
||||
GrGeometryProcessor* DashingLineEffect::TestCreate(GrProcessorTestData* d) {
|
||||
AAMode aaMode = static_cast<AAMode>(d->fRandom->nextULessThan(kAAModeCnt));
|
||||
AAMode aaMode = static_cast<AAMode>(d->fRandom->nextULessThan(GrDashOp::kAAModeCnt));
|
||||
GrColor color = GrTest::RandomColor(d->fRandom);
|
||||
SkMatrix matrix = GrTest::TestMatrix(d->fRandom);
|
||||
return DashingLineEffect::Make(d->allocator(),
|
||||
@ -1097,12 +1203,12 @@ GrGeometryProcessor* DashingLineEffect::TestCreate(GrProcessorTestData* d) {
|
||||
#endif
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GrGeometryProcessor* make_dash_gp(SkArenaAlloc* arena,
|
||||
const SkPMColor4f& color,
|
||||
AAMode aaMode,
|
||||
DashCap cap,
|
||||
const SkMatrix& viewMatrix,
|
||||
bool usesLocalCoords) {
|
||||
static GrGeometryProcessor* make_dash_gp(SkArenaAlloc* arena,
|
||||
const SkPMColor4f& color,
|
||||
AAMode aaMode,
|
||||
DashCap cap,
|
||||
const SkMatrix& viewMatrix,
|
||||
bool usesLocalCoords) {
|
||||
SkMatrix invert;
|
||||
if (usesLocalCoords && !viewMatrix.invert(&invert)) {
|
||||
SkDebugf("Failed to invert\n");
|
||||
@ -1118,19 +1224,15 @@ GrGeometryProcessor* make_dash_gp(SkArenaAlloc* arena,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if GR_TEST_UTILS
|
||||
|
||||
#include "src/gpu/GrDrawOpTest.h"
|
||||
|
||||
GR_DRAW_OP_TEST_DEFINE(DashOpImpl) {
|
||||
GR_DRAW_OP_TEST_DEFINE(DashOp) {
|
||||
SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random);
|
||||
AAMode aaMode;
|
||||
do {
|
||||
aaMode = static_cast<AAMode>(random->nextULessThan(kAAModeCnt));
|
||||
aaMode = static_cast<AAMode>(random->nextULessThan(GrDashOp::kAAModeCnt));
|
||||
} while (AAMode::kCoverageWithMSAA == aaMode && numSamples <= 1);
|
||||
|
||||
// We can only dash either horizontal or vertical lines
|
||||
@ -1196,111 +1298,8 @@ GR_DRAW_OP_TEST_DEFINE(DashOpImpl) {
|
||||
|
||||
GrStyle style(p);
|
||||
|
||||
return skgpu::v1::DashOp::MakeDashLineOp(context, std::move(paint), viewMatrix, pts, aaMode,
|
||||
style, GrGetRandomStencil(random, context));
|
||||
return GrDashOp::MakeDashLineOp(context, std::move(paint), viewMatrix, pts, aaMode, style,
|
||||
GrGetRandomStencil(random, context));
|
||||
}
|
||||
|
||||
#endif // GR_TEST_UTILS
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace skgpu::v1::DashOp {
|
||||
|
||||
GrOp::Owner MakeDashLineOp(GrRecordingContext* context,
|
||||
GrPaint&& paint,
|
||||
const SkMatrix& viewMatrix,
|
||||
const SkPoint pts[2],
|
||||
AAMode aaMode,
|
||||
const GrStyle& style,
|
||||
const GrUserStencilSettings* stencilSettings) {
|
||||
SkASSERT(CanDrawDashLine(pts, style, viewMatrix));
|
||||
const SkScalar* intervals = style.dashIntervals();
|
||||
SkScalar phase = style.dashPhase();
|
||||
|
||||
SkPaint::Cap cap = style.strokeRec().getCap();
|
||||
|
||||
DashOpImpl::LineData lineData;
|
||||
lineData.fSrcStrokeWidth = style.strokeRec().getWidth();
|
||||
|
||||
// the phase should be normalized to be [0, sum of all intervals)
|
||||
SkASSERT(phase >= 0 && phase < intervals[0] + intervals[1]);
|
||||
|
||||
// Rotate the src pts so they are aligned horizontally with pts[0].fX < pts[1].fX
|
||||
if (pts[0].fY != pts[1].fY || pts[0].fX > pts[1].fX) {
|
||||
SkMatrix rotMatrix;
|
||||
align_to_x_axis(pts, &rotMatrix, lineData.fPtsRot);
|
||||
if (!rotMatrix.invert(&lineData.fSrcRotInv)) {
|
||||
SkDebugf("Failed to create invertible rotation matrix!\n");
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
lineData.fSrcRotInv.reset();
|
||||
memcpy(lineData.fPtsRot, pts, 2 * sizeof(SkPoint));
|
||||
}
|
||||
|
||||
// Scale corrections of intervals and stroke from view matrix
|
||||
calc_dash_scaling(&lineData.fParallelScale, &lineData.fPerpendicularScale, viewMatrix, pts);
|
||||
if (SkScalarNearlyZero(lineData.fParallelScale) ||
|
||||
SkScalarNearlyZero(lineData.fPerpendicularScale)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkScalar offInterval = intervals[1] * lineData.fParallelScale;
|
||||
SkScalar strokeWidth = lineData.fSrcStrokeWidth * lineData.fPerpendicularScale;
|
||||
|
||||
if (SkPaint::kSquare_Cap == cap && 0 != lineData.fSrcStrokeWidth) {
|
||||
// add cap to on interval and remove from off interval
|
||||
offInterval -= strokeWidth;
|
||||
}
|
||||
|
||||
// TODO we can do a real rect call if not using fulldash(ie no off interval, not using AA)
|
||||
bool fullDash = offInterval > 0.f || aaMode != AAMode::kNone;
|
||||
|
||||
lineData.fViewMatrix = viewMatrix;
|
||||
lineData.fPhase = phase;
|
||||
lineData.fIntervals[0] = intervals[0];
|
||||
lineData.fIntervals[1] = intervals[1];
|
||||
|
||||
return DashOpImpl::Make(context, std::move(paint), lineData, cap, aaMode, fullDash,
|
||||
stencilSettings);
|
||||
}
|
||||
|
||||
// Returns whether or not the gpu can fast path the dash line effect.
|
||||
bool CanDrawDashLine(const SkPoint pts[2], const GrStyle& style, const SkMatrix& viewMatrix) {
|
||||
// Pts must be either horizontal or vertical in src space
|
||||
if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// May be able to relax this to include skew. As of now cannot do perspective
|
||||
// because of the non uniform scaling of bloating a rect
|
||||
if (!viewMatrix.preservesRightAngles()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!style.isDashed() || 2 != style.dashIntervalCnt()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const SkScalar* intervals = style.dashIntervals();
|
||||
if (0 == intervals[0] && 0 == intervals[1]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SkPaint::Cap cap = style.strokeRec().getCap();
|
||||
if (SkPaint::kRound_Cap == cap) {
|
||||
// Current we don't support round caps unless the on interval is zero
|
||||
if (intervals[0] != 0.f) {
|
||||
return false;
|
||||
}
|
||||
// If the width of the circle caps in greater than the off interval we will pick up unwanted
|
||||
// segments of circles at the start and end of the dash line.
|
||||
if (style.strokeRec().getWidth() > intervals[1]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace skgpu::v1::DashOp
|
||||
#endif
|
@ -5,24 +5,26 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef DashOp_DEFINED
|
||||
#define DashOp_DEFINED
|
||||
#ifndef GrDashOp_DEFINED
|
||||
#define GrDashOp_DEFINED
|
||||
|
||||
#include "include/core/SkPathEffect.h"
|
||||
#include "include/gpu/GrTypes.h"
|
||||
#include "src/gpu/ops/GrOp.h"
|
||||
|
||||
class GrDrawOp;
|
||||
class GrPaint;
|
||||
class GrRecordingContext;
|
||||
class GrStyle;
|
||||
struct GrUserStencilSettings;
|
||||
|
||||
namespace skgpu::v1::DashOp {
|
||||
|
||||
namespace GrDashOp {
|
||||
enum class AAMode {
|
||||
kNone,
|
||||
kCoverage,
|
||||
kCoverageWithMSAA,
|
||||
};
|
||||
static const int kAAModeCnt = static_cast<int>(AAMode::kCoverageWithMSAA) + 1;
|
||||
|
||||
GrOp::Owner MakeDashLineOp(GrRecordingContext*,
|
||||
GrPaint&&,
|
||||
@ -32,7 +34,6 @@ GrOp::Owner MakeDashLineOp(GrRecordingContext*,
|
||||
const GrStyle& style,
|
||||
const GrUserStencilSettings*);
|
||||
bool CanDrawDashLine(const SkPoint pts[2], const GrStyle& style, const SkMatrix& viewMatrix);
|
||||
} // namespace GrDashOp
|
||||
|
||||
} // namespace skgpu::v1::DashOp
|
||||
|
||||
#endif // DashOp_DEFINED
|
||||
#endif
|
@ -24,6 +24,7 @@
|
||||
#include "src/gpu/GrResourceProvider.h"
|
||||
#include "src/gpu/GrTexture.h"
|
||||
#include "src/gpu/geometry/GrRect.h"
|
||||
#include "src/gpu/ops/GrClearOp.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -52,7 +52,7 @@
|
||||
#include "src/gpu/geometry/GrQuad.h"
|
||||
#include "src/gpu/geometry/GrQuadUtils.h"
|
||||
#include "src/gpu/geometry/GrStyledShape.h"
|
||||
#include "src/gpu/ops/ClearOp.h"
|
||||
#include "src/gpu/ops/GrClearOp.h"
|
||||
#include "src/gpu/ops/GrDrawAtlasOp.h"
|
||||
#include "src/gpu/ops/GrDrawOp.h"
|
||||
#include "src/gpu/ops/GrDrawVerticesOp.h"
|
||||
@ -904,7 +904,7 @@ void SurfaceDrawContext::internalStencilClear(const SkIRect* scissor, bool insid
|
||||
GrFillRectOp::MakeNonAARect(fContext, std::move(paint), SkMatrix::I(),
|
||||
SkRect::Make(scissorState.rect()), ss));
|
||||
} else {
|
||||
this->addOp(ClearOp::MakeStencilClip(fContext, scissorState, insideStencilMask));
|
||||
this->addOp(GrClearOp::MakeStencilClip(fContext, scissorState, insideStencilMask));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "src/gpu/GrProxyProvider.h"
|
||||
#include "src/gpu/effects/GrTextureEffect.h"
|
||||
#include "src/gpu/geometry/GrRect.h"
|
||||
#include "src/gpu/ops/ClearOp.h"
|
||||
#include "src/gpu/ops/GrClearOp.h"
|
||||
#include "src/gpu/ops/GrFillRectOp.h"
|
||||
#include "src/gpu/v1/SurfaceDrawContext_v1.h"
|
||||
|
||||
@ -223,7 +223,7 @@ void SurfaceFillContext::internalClear(const SkIRect* scissor,
|
||||
this->addDrawOp(std::move(op));
|
||||
} else {
|
||||
color = this->writeSurfaceView().swizzle().applyTo(color);
|
||||
this->addOp(ClearOp::MakeColor(fContext, scissorState, color));
|
||||
this->addOp(GrClearOp::MakeColor(fContext, scissorState, color));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "src/gpu/GrColor.h"
|
||||
#include "src/gpu/GrDirectContextPriv.h"
|
||||
#include "src/gpu/GrImageInfo.h"
|
||||
#include "src/gpu/ops/ClearOp.h"
|
||||
#include "src/gpu/ops/GrClearOp.h"
|
||||
#include "src/gpu/v1/SurfaceDrawContext_v1.h"
|
||||
#include "tests/Test.h"
|
||||
#include "tools/gpu/GrContextFactory.h"
|
||||
@ -31,11 +31,8 @@
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
using SurfaceDrawContext = skgpu::v1::SurfaceDrawContext;
|
||||
using ClearOp = skgpu::v1::ClearOp;
|
||||
|
||||
static bool check_rect(GrDirectContext* dContext,
|
||||
SurfaceDrawContext* sdc,
|
||||
skgpu::v1::SurfaceDrawContext* sdc,
|
||||
const SkIRect& rect,
|
||||
uint32_t expectedValue,
|
||||
uint32_t* actualValue,
|
||||
@ -68,9 +65,10 @@ static bool check_rect(GrDirectContext* dContext,
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<SurfaceDrawContext> newSDC(GrRecordingContext* rContext, int w, int h) {
|
||||
return SurfaceDrawContext::Make(rContext, GrColorType::kRGBA_8888, nullptr,
|
||||
SkBackingFit::kExact, {w, h}, SkSurfaceProps());
|
||||
std::unique_ptr<skgpu::v1::SurfaceDrawContext> newSDC(GrRecordingContext* rContext, int w, int h) {
|
||||
return skgpu::v1::SurfaceDrawContext::Make(
|
||||
rContext, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {w, h},
|
||||
SkSurfaceProps());
|
||||
}
|
||||
|
||||
static void clear_op_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
|
||||
@ -78,7 +76,7 @@ static void clear_op_test(skiatest::Reporter* reporter, GrDirectContext* dContex
|
||||
static const int kH = 10;
|
||||
|
||||
SkIRect fullRect = SkIRect::MakeWH(kW, kH);
|
||||
std::unique_ptr<SurfaceDrawContext> sdc;
|
||||
std::unique_ptr<skgpu::v1::SurfaceDrawContext> sdc;
|
||||
|
||||
// A rectangle that is inset by one on all sides and the 1-pixel wide rectangles that surround
|
||||
// it.
|
||||
@ -255,7 +253,7 @@ static void clear_op_test(skiatest::Reporter* reporter, GrDirectContext* dContex
|
||||
auto opsTask = sdc->getOpsTask();
|
||||
REPORTER_ASSERT(reporter, opsTask->numOpChains() == 1);
|
||||
|
||||
const ClearOp& clearOp = opsTask->getChain(0)->cast<ClearOp>();
|
||||
const GrClearOp& clearOp = opsTask->getChain(0)->cast<GrClearOp>();
|
||||
|
||||
constexpr std::array<float, 4> kExpected { 0, 0, 0, 1 };
|
||||
REPORTER_ASSERT(reporter, clearOp.color() == kExpected);
|
||||
@ -281,7 +279,7 @@ static void clear_op_test(skiatest::Reporter* reporter, GrDirectContext* dContex
|
||||
auto opsTask = sdc->getOpsTask();
|
||||
REPORTER_ASSERT(reporter, opsTask->numOpChains() == 1);
|
||||
|
||||
const ClearOp& clearOp = opsTask->getChain(0)->cast<ClearOp>();
|
||||
const GrClearOp& clearOp = opsTask->getChain(0)->cast<GrClearOp>();
|
||||
|
||||
constexpr std::array<float, 4> kExpected { 1, 1, 1, 1 };
|
||||
REPORTER_ASSERT(reporter, clearOp.color() == kExpected);
|
||||
|
@ -48,7 +48,7 @@ DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
|
||||
DRAW_OP_TEST_EXTERN(AtlasTextOp);
|
||||
DRAW_OP_TEST_EXTERN(ButtCapDashedCircleOp);
|
||||
DRAW_OP_TEST_EXTERN(CircleOp);
|
||||
DRAW_OP_TEST_EXTERN(DashOpImpl);
|
||||
DRAW_OP_TEST_EXTERN(DashOp);
|
||||
DRAW_OP_TEST_EXTERN(DefaultPathOp);
|
||||
DRAW_OP_TEST_EXTERN(DrawAtlasOp);
|
||||
DRAW_OP_TEST_EXTERN(DrawVerticesOp);
|
||||
@ -79,7 +79,7 @@ void GrDrawRandomOp(SkRandom* random, skgpu::v1::SurfaceDrawContext* sdc, GrPain
|
||||
DRAW_OP_TEST_ENTRY(AtlasTextOp),
|
||||
DRAW_OP_TEST_ENTRY(ButtCapDashedCircleOp),
|
||||
DRAW_OP_TEST_ENTRY(CircleOp),
|
||||
DRAW_OP_TEST_ENTRY(DashOpImpl),
|
||||
DRAW_OP_TEST_ENTRY(DashOp),
|
||||
DRAW_OP_TEST_ENTRY(DefaultPathOp),
|
||||
DRAW_OP_TEST_ENTRY(DrawAtlasOp),
|
||||
DRAW_OP_TEST_ENTRY(DrawVerticesOp),
|
||||
|
Loading…
Reference in New Issue
Block a user