1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/gpu/GrGlyph.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,78 @@ 1.4 +/* 1.5 + * Copyright 2010 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef GrGlyph_DEFINED 1.12 +#define GrGlyph_DEFINED 1.13 + 1.14 +#include "GrRect.h" 1.15 +#include "SkPath.h" 1.16 + 1.17 +class GrPlot; 1.18 + 1.19 +/* Need this to be quad-state: 1.20 + - complete w/ image 1.21 + - just metrics 1.22 + - failed to get image, but has metrics 1.23 + - failed to get metrics 1.24 + */ 1.25 +struct GrGlyph { 1.26 + typedef uint32_t PackedID; 1.27 + 1.28 + GrPlot* fPlot; 1.29 + SkPath* fPath; 1.30 + PackedID fPackedID; 1.31 + GrIRect16 fBounds; 1.32 + GrIPoint16 fAtlasLocation; 1.33 + 1.34 + void init(GrGlyph::PackedID packed, const SkIRect& bounds) { 1.35 + fPlot = NULL; 1.36 + fPath = NULL; 1.37 + fPackedID = packed; 1.38 + fBounds.set(bounds); 1.39 + fAtlasLocation.set(0, 0); 1.40 + } 1.41 + 1.42 + void free() { 1.43 + if (fPath) { 1.44 + delete fPath; 1.45 + fPath = NULL; 1.46 + } 1.47 + } 1.48 + 1.49 + int width() const { return fBounds.width(); } 1.50 + int height() const { return fBounds.height(); } 1.51 + bool isEmpty() const { return fBounds.isEmpty(); } 1.52 + uint16_t glyphID() const { return UnpackID(fPackedID); } 1.53 + 1.54 + /////////////////////////////////////////////////////////////////////////// 1.55 + 1.56 + static inline unsigned ExtractSubPixelBitsFromFixed(GrFixed pos) { 1.57 + // two most significant fraction bits from fixed-point 1.58 + return (pos >> 14) & 3; 1.59 + } 1.60 + 1.61 + static inline PackedID Pack(uint16_t glyphID, GrFixed x, GrFixed y) { 1.62 + x = ExtractSubPixelBitsFromFixed(x); 1.63 + y = ExtractSubPixelBitsFromFixed(y); 1.64 + return (x << 18) | (y << 16) | glyphID; 1.65 + } 1.66 + 1.67 + static inline GrFixed UnpackFixedX(PackedID packed) { 1.68 + return ((packed >> 18) & 3) << 14; 1.69 + } 1.70 + 1.71 + static inline GrFixed UnpackFixedY(PackedID packed) { 1.72 + return ((packed >> 16) & 3) << 14; 1.73 + } 1.74 + 1.75 + static inline uint16_t UnpackID(PackedID packed) { 1.76 + return (uint16_t)packed; 1.77 + } 1.78 +}; 1.79 + 1.80 + 1.81 +#endif