blob: fca9a8cb8e4a9282426fcd086eaaac02d27c96c1 [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
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 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
17struct 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