Home | History | Annotate | Download | only in gpu
      1 
      2 /*
      3  * Copyright 2010 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 
     11 #ifndef GrGlyph_DEFINED
     12 #define GrGlyph_DEFINED
     13 
     14 #include "GrPath.h"
     15 #include "GrRect.h"
     16 
     17 class GrAtlas;
     18 
     19 /*  Need this to be quad-state:
     20     - complete w/ image
     21     - just metrics
     22     - failed to get image, but has metrics
     23     - failed to get metrics
     24  */
     25 struct GrGlyph {
     26     typedef uint32_t PackedID;
     27 
     28     GrAtlas*    fAtlas;
     29     GrPath*     fPath;
     30     PackedID    fPackedID;
     31     GrIRect16   fBounds;
     32     GrIPoint16  fAtlasLocation;
     33 
     34     void init(GrGlyph::PackedID packed, const GrIRect& bounds) {
     35         fAtlas = NULL;
     36         fPath = NULL;
     37         fPackedID = packed;
     38         fBounds.set(bounds);
     39         fAtlasLocation.set(0, 0);
     40     }
     41 
     42     void free() {
     43         if (fPath) {
     44             delete fPath;
     45             fPath = NULL;
     46         }
     47     }
     48 
     49     int width() const { return fBounds.width(); }
     50     int height() const { return fBounds.height(); }
     51     bool isEmpty() const { return fBounds.isEmpty(); }
     52     uint16_t glyphID() const { return UnpackID(fPackedID); }
     53 
     54     ///////////////////////////////////////////////////////////////////////////
     55 
     56     static inline unsigned ExtractSubPixelBitsFromFixed(GrFixed pos) {
     57         // two most significant fraction bits from fixed-point
     58         return (pos >> 14) & 3;
     59     }
     60 
     61     static inline PackedID Pack(uint16_t glyphID, GrFixed x, GrFixed y) {
     62         x = ExtractSubPixelBitsFromFixed(x);
     63         y = ExtractSubPixelBitsFromFixed(y);
     64         return (x << 18) | (y << 16) | glyphID;
     65     }
     66 
     67     static inline GrFixed UnpackFixedX(PackedID packed) {
     68         return ((packed >> 18) & 3) << 14;
     69     }
     70 
     71     static inline GrFixed UnpackFixedY(PackedID packed) {
     72         return ((packed >> 16) & 3) << 14;
     73     }
     74 
     75     static inline uint16_t UnpackID(PackedID packed) {
     76         return (uint16_t)packed;
     77     }
     78 };
     79 
     80 
     81 #endif
     82 
     83