1 /* 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 8 #ifndef GrDistanceFieldAdjustTable_DEFINED 9 #define GrDistanceFieldAdjustTable_DEFINED 10 11 #include "SkRefCnt.h" 12 #include "SkScalar.h" 13 14 // Distance field text needs this table to compute a value for use in the fragment shader. 15 // Because the GrTextContext can go out of scope before the final flush, this needs to be 16 // refcnted and malloced 17 struct GrDistanceFieldAdjustTable : public SkNVRefCnt<GrDistanceFieldAdjustTable> { GrDistanceFieldAdjustTableGrDistanceFieldAdjustTable18 GrDistanceFieldAdjustTable() { this->buildDistanceAdjustTables(); } ~GrDistanceFieldAdjustTableGrDistanceFieldAdjustTable19 ~GrDistanceFieldAdjustTable() { 20 delete[] fTable; 21 delete[] fGammaCorrectTable; 22 } 23 getAdjustmentGrDistanceFieldAdjustTable24 const SkScalar& getAdjustment(int i, bool useGammaCorrectTable) const { 25 return useGammaCorrectTable ? fGammaCorrectTable[i] : fTable[i]; 26 } 27 28 private: 29 void buildDistanceAdjustTables(); 30 31 SkScalar* fTable; 32 SkScalar* fGammaCorrectTable; 33 }; 34 35 #endif 36