joshualitt | 1acabf3 | 2015-12-10 09:10:10 -0800 | [diff] [blame] | 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. |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 15 | // Because the GrTextContext can go out of scope before the final flush, this needs to be |
joshualitt | 1acabf3 | 2015-12-10 09:10:10 -0800 | [diff] [blame] | 16 | // refcnted and malloced |
Mike Klein | 408ef21 | 2018-10-30 15:23:00 +0000 | [diff] [blame^] | 17 | struct GrDistanceFieldAdjustTable : public SkNVRefCnt<GrDistanceFieldAdjustTable> { |
brianosman | 0586f5c | 2016-04-12 12:48:21 -0700 | [diff] [blame] | 18 | GrDistanceFieldAdjustTable() { this->buildDistanceAdjustTables(); } |
| 19 | ~GrDistanceFieldAdjustTable() { |
| 20 | delete[] fTable; |
brianosman | b461d34 | 2016-04-13 13:10:14 -0700 | [diff] [blame] | 21 | delete[] fGammaCorrectTable; |
brianosman | 0586f5c | 2016-04-12 12:48:21 -0700 | [diff] [blame] | 22 | } |
joshualitt | 1acabf3 | 2015-12-10 09:10:10 -0800 | [diff] [blame] | 23 | |
brianosman | b461d34 | 2016-04-13 13:10:14 -0700 | [diff] [blame] | 24 | const SkScalar& getAdjustment(int i, bool useGammaCorrectTable) const { |
| 25 | return useGammaCorrectTable ? fGammaCorrectTable[i] : fTable[i]; |
joshualitt | 1acabf3 | 2015-12-10 09:10:10 -0800 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | private: |
brianosman | 0586f5c | 2016-04-12 12:48:21 -0700 | [diff] [blame] | 29 | void buildDistanceAdjustTables(); |
joshualitt | 1acabf3 | 2015-12-10 09:10:10 -0800 | [diff] [blame] | 30 | |
| 31 | SkScalar* fTable; |
brianosman | b461d34 | 2016-04-13 13:10:14 -0700 | [diff] [blame] | 32 | SkScalar* fGammaCorrectTable; |
joshualitt | 1acabf3 | 2015-12-10 09:10:10 -0800 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | #endif |