Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / include / core / SkColorTable.h
1
2 /*
3  * Copyright 2012 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 #ifndef SkColorTable_DEFINED
11 #define SkColorTable_DEFINED
12
13 #include "SkColor.h"
14 #include "SkFlattenable.h"
15 #include "SkImageInfo.h"
16
17 /** \class SkColorTable
18
19     SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by
20     8-bit bitmaps, where the bitmap bytes are interpreted as indices into the colortable.
21 */
22 class SK_API SkColorTable : public SkRefCnt {
23 public:
24     SK_DECLARE_INST_COUNT(SkColorTable)
25
26     /** Makes a deep copy of colors.
27      */
28     SkColorTable(const SkColorTable& src);
29     SkColorTable(const SkPMColor colors[], int count);
30     virtual ~SkColorTable();
31
32     /** Returns the number of colors in the table.
33     */
34     int count() const { return fCount; }
35
36     /** Returns the specified color from the table. In the debug build, this asserts that
37         the index is in range (0 <= index < count).
38     */
39     SkPMColor operator[](int index) const {
40         SkASSERT(fColors != NULL && (unsigned)index < (unsigned)fCount);
41         return fColors[index];
42     }
43
44     /**
45      *  Return the array of colors for reading. This must be balanced by a call
46      *  to unlockColors().
47      */
48     const SkPMColor* lockColors() {
49         SkDEBUGCODE(sk_atomic_inc(&fColorLockCount);)
50         return fColors;
51     }
52
53     /**
54      *  Balancing call to lockColors().
55      */
56     void unlockColors();
57
58     /** Similar to lockColors(), lock16BitCache() returns the array of
59         RGB16 colors that mirror the 32bit colors. However, this function
60         will return null if kColorsAreOpaque_Flag is not set.
61         Also, unlike lockColors(), the returned array here cannot be modified.
62     */
63     const uint16_t* lock16BitCache();
64     /** Balancing call to lock16BitCache().
65     */
66     void unlock16BitCache() {
67         SkASSERT(f16BitCacheLockCount > 0);
68         SkDEBUGCODE(f16BitCacheLockCount -= 1);
69     }
70
71     explicit SkColorTable(SkReadBuffer&);
72     void writeToBuffer(SkWriteBuffer&) const;
73
74 private:
75     SkPMColor*  fColors;
76     uint16_t*   f16BitCache;
77     int         fCount;
78     SkDEBUGCODE(int fColorLockCount;)
79     SkDEBUGCODE(int f16BitCacheLockCount;)
80
81     void init(const SkPMColor* colors, int count);
82
83     void inval16BitCache();
84
85     typedef SkRefCnt INHERITED;
86 };
87
88 #endif