blob: e6e08dcd21789f20e2e8ca9dd4d76c7c723d7123 [file] [log] [blame]
joshualitta751c972015-11-20 13:37:32 -08001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Brian Salomon344ec422016-12-15 10:58:41 -05008#ifndef GrAtlasTextOp_DEFINED
9#define GrAtlasTextOp_DEFINED
joshualitta751c972015-11-20 13:37:32 -080010
Brian Salomon89527432016-12-16 09:52:16 -050011#include "ops/GrMeshDrawOp.h"
Herb Derby26cbe512018-05-24 14:39:01 -040012#include "text/GrTextContext.h"
joshualitte8042922015-12-11 06:11:21 -080013#include "text/GrDistanceFieldAdjustTable.h"
Robert Phillipsc4039ea2018-03-01 11:36:45 -050014#include "text/GrGlyphCache.h"
joshualitta751c972015-11-20 13:37:32 -080015
Brian Salomoncbcb0a12017-11-19 13:20:13 -050016class SkAtlasTextTarget;
Robert Phillips7c525e62018-06-12 10:11:12 -040017class GrContext;
Brian Salomoncbcb0a12017-11-19 13:20:13 -050018
Brian Salomon44acb5b2017-07-18 19:59:24 -040019class GrAtlasTextOp final : public GrMeshDrawOp {
joshualitta751c972015-11-20 13:37:32 -080020public:
Brian Salomon25a88092016-12-01 09:36:50 -050021 DEFINE_OP_CLASS_ID
joshualitta751c972015-11-20 13:37:32 -080022
Brian Salomonf8334782017-01-03 09:42:58 -050023 ~GrAtlasTextOp() override {
24 for (int i = 0; i < fGeoCount; i++) {
25 fGeoData[i].fBlob->unref();
26 }
27 }
28
Herb Derby86240592018-05-24 16:12:31 -040029 static const int kVerticesPerGlyph = GrTextBlob::kVerticesPerGlyph;
joshualitta751c972015-11-20 13:37:32 -080030 static const int kIndicesPerGlyph = 6;
31
Herb Derby86240592018-05-24 16:12:31 -040032 typedef GrTextBlob Blob;
joshualitta751c972015-11-20 13:37:32 -080033 struct Geometry {
joshualitt8e0ef292016-02-19 14:13:03 -080034 SkMatrix fViewMatrix;
Jim Van Verth58c3cce2017-10-19 15:50:24 -040035 SkIRect fClipRect;
36 Blob* fBlob;
joshualitt8e0ef292016-02-19 14:13:03 -080037 SkScalar fX;
38 SkScalar fY;
Jim Van Verth56c37142017-10-31 14:44:25 -040039 uint16_t fRun;
40 uint16_t fSubRun;
Jim Van Verth58c3cce2017-10-19 15:50:24 -040041 GrColor fColor;
joshualitta751c972015-11-20 13:37:32 -080042 };
43
Robert Phillips7c525e62018-06-12 10:11:12 -040044 static std::unique_ptr<GrAtlasTextOp> MakeBitmap(GrContext* context,
45 GrPaint&& paint,
46 GrMaskFormat maskFormat,
47 int glyphCount,
48 bool needsTransform);
joshualitta751c972015-11-20 13:37:32 -080049
Brian Salomonf8334782017-01-03 09:42:58 -050050 static std::unique_ptr<GrAtlasTextOp> MakeDistanceField(
Robert Phillips7c525e62018-06-12 10:11:12 -040051 GrContext* context,
52 GrPaint&& paint,
53 int glyphCount,
54 const GrDistanceFieldAdjustTable* distanceAdjustTable,
55 bool useGammaCorrectDistanceTable,
56 SkColor luminanceColor,
57 const SkSurfaceProps& props,
58 bool isAntiAliased,
59 bool useLCD);
joshualitta751c972015-11-20 13:37:32 -080060
Brian Salomon344ec422016-12-15 10:58:41 -050061 // To avoid even the initial copy of the struct, we have a getter for the first item which
62 // is used to seed the op with its initial geometry. After seeding, the client should call
63 // init() so the op can initialize itself
joshualitta751c972015-11-20 13:37:32 -080064 Geometry& geometry() { return fGeoData[0]; }
65
Brian Salomon5c6ac642017-12-19 11:09:32 -050066 /** Called after this->geometry() has been configured. */
67 void init();
joshualitta751c972015-11-20 13:37:32 -080068
Brian Salomon344ec422016-12-15 10:58:41 -050069 const char* name() const override { return "AtlasTextOp"; }
joshualitta751c972015-11-20 13:37:32 -080070
Robert Phillipse4fda6c2018-02-21 12:10:41 -050071 void visitProxies(const VisitProxyFunc& func) const override;
Robert Phillipsb493eeb2017-09-13 13:10:52 -040072
joshualitta751c972015-11-20 13:37:32 -080073 SkString dumpInfo() const override;
74
Brian Salomon44acb5b2017-07-18 19:59:24 -040075 FixedFunctionFlags fixedFunctionFlags() const override;
76
Brian Osman532b3f92018-07-11 10:02:07 -040077 RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override;
Brian Salomon44acb5b2017-07-18 19:59:24 -040078
Brian Salomoncbcb0a12017-11-19 13:20:13 -050079 enum MaskType {
80 kGrayscaleCoverageMask_MaskType,
81 kLCDCoverageMask_MaskType,
82 kColorBitmapMask_MaskType,
83 kAliasedDistanceField_MaskType,
84 kGrayscaleDistanceField_MaskType,
85 kLCDDistanceField_MaskType,
86 kLCDBGRDistanceField_MaskType,
87 };
88
89 MaskType maskType() const { return fMaskType; }
90
Brian Salomon778a2c92017-11-27 12:18:04 -050091 void finalizeForTextTarget(uint32_t color, const GrCaps&);
92 void executeForTextTarget(SkAtlasTextTarget*);
Brian Salomoncbcb0a12017-11-19 13:20:13 -050093
joshualitta751c972015-11-20 13:37:32 -080094private:
Robert Phillips7c525e62018-06-12 10:11:12 -040095 friend class GrOpMemoryPool; // for ctor
96
Jim Van Verthc8a65e32017-10-25 14:25:27 -040097 // The minimum number of Geometry we will try to allocate.
Jim Van Verth56c37142017-10-31 14:44:25 -040098 static constexpr auto kMinGeometryAllocated = 12;
Jim Van Verthc8a65e32017-10-25 14:25:27 -040099
Robert Phillips5a66efb2018-03-07 15:13:18 -0500100 GrAtlasTextOp(GrPaint&& paint)
Brian Salomon44acb5b2017-07-18 19:59:24 -0400101 : INHERITED(ClassID())
Jim Van Verthc8a65e32017-10-25 14:25:27 -0400102 , fGeoDataAllocSize(kMinGeometryAllocated)
Brian Salomon44acb5b2017-07-18 19:59:24 -0400103 , fProcessors(std::move(paint)) {}
joshualitta751c972015-11-20 13:37:32 -0800104
105 struct FlushInfo {
Brian Salomon344ec422016-12-15 10:58:41 -0500106 sk_sp<const GrBuffer> fVertexBuffer;
107 sk_sp<const GrBuffer> fIndexBuffer;
Hal Canary144caf52016-11-07 17:57:18 -0500108 sk_sp<GrGeometryProcessor> fGeometryProcessor;
Brian Salomon44acb5b2017-07-18 19:59:24 -0400109 const GrPipeline* fPipeline;
Brian Salomon7eae3e02018-08-07 14:02:38 +0000110 GrPipeline::FixedDynamicState* fFixedDynamicState;
Brian Salomon344ec422016-12-15 10:58:41 -0500111 int fGlyphsToFlush;
112 int fVertexOffset;
joshualitta751c972015-11-20 13:37:32 -0800113 };
114
Brian Salomon91326c32017-08-09 16:02:19 -0400115 void onPrepareDraws(Target*) override;
joshualitta751c972015-11-20 13:37:32 -0800116
joshualitta751c972015-11-20 13:37:32 -0800117 GrMaskFormat maskFormat() const {
118 switch (fMaskType) {
119 case kLCDCoverageMask_MaskType:
120 return kA565_GrMaskFormat;
121 case kColorBitmapMask_MaskType:
122 return kARGB_GrMaskFormat;
123 case kGrayscaleCoverageMask_MaskType:
Jim Van Verth90e89b32017-07-06 16:36:55 -0400124 case kAliasedDistanceField_MaskType:
joshualitta751c972015-11-20 13:37:32 -0800125 case kGrayscaleDistanceField_MaskType:
126 case kLCDDistanceField_MaskType:
Jim Van Verth90e89b32017-07-06 16:36:55 -0400127 case kLCDBGRDistanceField_MaskType:
joshualitta751c972015-11-20 13:37:32 -0800128 return kA8_GrMaskFormat;
129 }
Brian Salomon344ec422016-12-15 10:58:41 -0500130 return kA8_GrMaskFormat; // suppress warning
joshualitta751c972015-11-20 13:37:32 -0800131 }
132
133 bool usesDistanceFields() const {
Jim Van Verth90e89b32017-07-06 16:36:55 -0400134 return kAliasedDistanceField_MaskType == fMaskType ||
135 kGrayscaleDistanceField_MaskType == fMaskType ||
136 kLCDDistanceField_MaskType == fMaskType ||
137 kLCDBGRDistanceField_MaskType == fMaskType;
joshualitta751c972015-11-20 13:37:32 -0800138 }
139
140 bool isLCD() const {
Jim Van Verth90e89b32017-07-06 16:36:55 -0400141 return kLCDCoverageMask_MaskType == fMaskType ||
142 kLCDDistanceField_MaskType == fMaskType ||
143 kLCDBGRDistanceField_MaskType == fMaskType;
joshualitta751c972015-11-20 13:37:32 -0800144 }
145
Brian Salomone5b399e2017-07-19 13:50:54 -0400146 inline void flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) const;
joshualitta751c972015-11-20 13:37:32 -0800147
Brian Osman09068252018-01-03 09:57:29 -0500148 GrColor color() const { SkASSERT(fGeoCount > 0); return fGeoData[0].fColor; }
Brian Salomon344ec422016-12-15 10:58:41 -0500149 bool usesLocalCoords() const { return fUsesLocalCoords; }
150 int numGlyphs() const { return fNumGlyphs; }
joshualitta751c972015-11-20 13:37:32 -0800151
Brian Salomon7eae3e02018-08-07 14:02:38 +0000152 CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override;
joshualitta751c972015-11-20 13:37:32 -0800153
Jim Van Verthcbeae032018-05-16 14:54:41 -0400154 sk_sp<GrGeometryProcessor> setupDfProcessor(const sk_sp<GrTextureProxy>* proxies,
155 unsigned int numActiveProxies) const;
joshualitta751c972015-11-20 13:37:32 -0800156
Brian Salomon44acb5b2017-07-18 19:59:24 -0400157 SkAutoSTMalloc<kMinGeometryAllocated, Geometry> fGeoData;
Jim Van Verthc8a65e32017-10-25 14:25:27 -0400158 int fGeoDataAllocSize;
Brian Salomon44acb5b2017-07-18 19:59:24 -0400159 GrProcessorSet fProcessors;
Jim Van Verthcf838c72018-03-05 14:40:36 -0500160 struct {
161 uint32_t fUsesLocalCoords : 1;
162 uint32_t fCanCombineOnTouchOrOverlap : 1;
163 uint32_t fUseGammaCorrectDistanceTable : 1;
Jim Van Verthb515ae72018-05-23 16:44:55 -0400164 uint32_t fNeedsGlyphTransform : 1;
Jim Van Verthcf838c72018-03-05 14:40:36 -0500165 };
Brian Salomon44acb5b2017-07-18 19:59:24 -0400166 int fGeoCount;
167 int fNumGlyphs;
168 MaskType fMaskType;
joshualitta751c972015-11-20 13:37:32 -0800169 // Distance field properties
Hal Canary144caf52016-11-07 17:57:18 -0500170 sk_sp<const GrDistanceFieldAdjustTable> fDistanceAdjustTable;
Jim Van Verthbc2cdd12017-06-08 11:14:35 -0400171 SkColor fLuminanceColor;
Brian Salomon5c6ac642017-12-19 11:09:32 -0500172 uint32_t fDFGPFlags = 0;
joshualitta751c972015-11-20 13:37:32 -0800173
Brian Salomon44acb5b2017-07-18 19:59:24 -0400174 typedef GrMeshDrawOp INHERITED;
joshualitta751c972015-11-20 13:37:32 -0800175};
176
joshualitta751c972015-11-20 13:37:32 -0800177#endif