blob: 3b217b97805a3281f7d5e1218a0af72c93406411 [file] [log] [blame]
joshualitt1acabf32015-12-10 09:10:10 -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
8#ifndef GrDistanceFieldAdjustTable_DEFINED
9#define GrDistanceFieldAdjustTable_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkRefCnt.h"
12#include "include/core/SkScalar.h"
joshualitt1acabf32015-12-10 09:10:10 -080013
14// Distance field text needs this table to compute a value for use in the fragment shader.
Herb Derby26cbe512018-05-24 14:39:01 -040015// Because the GrTextContext can go out of scope before the final flush, this needs to be
joshualitt1acabf32015-12-10 09:10:10 -080016// refcnted and malloced
Mike Klein408ef212018-10-30 15:23:00 +000017struct GrDistanceFieldAdjustTable : public SkNVRefCnt<GrDistanceFieldAdjustTable> {
brianosman0586f5c2016-04-12 12:48:21 -070018 GrDistanceFieldAdjustTable() { this->buildDistanceAdjustTables(); }
19 ~GrDistanceFieldAdjustTable() {
20 delete[] fTable;
brianosmanb461d342016-04-13 13:10:14 -070021 delete[] fGammaCorrectTable;
brianosman0586f5c2016-04-12 12:48:21 -070022 }
joshualitt1acabf32015-12-10 09:10:10 -080023
brianosmanb461d342016-04-13 13:10:14 -070024 const SkScalar& getAdjustment(int i, bool useGammaCorrectTable) const {
25 return useGammaCorrectTable ? fGammaCorrectTable[i] : fTable[i];
joshualitt1acabf32015-12-10 09:10:10 -080026 }
27
28private:
brianosman0586f5c2016-04-12 12:48:21 -070029 void buildDistanceAdjustTables();
joshualitt1acabf32015-12-10 09:10:10 -080030
31 SkScalar* fTable;
brianosmanb461d342016-04-13 13:10:14 -070032 SkScalar* fGammaCorrectTable;
joshualitt1acabf32015-12-10 09:10:10 -080033};
34
35#endif