1 :
2 : /*
3 : * Copyright 2006 The Android Open Source Project
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 SkGlobals_DEFINED
11 : #define SkGlobals_DEFINED
12 :
13 : #include "SkThread.h"
14 :
15 : class SkGlobals {
16 : public:
17 : class Rec {
18 : public:
19 : virtual ~Rec();
20 : private:
21 : Rec* fNext;
22 : uint32_t fTag;
23 :
24 : friend class SkGlobals;
25 : };
26 :
27 : /** Look for a matching Rec for the specified tag. If one is found, return it.
28 : If one is not found, if create_proc is null, return null, else
29 : call the proc, and if it returns a Rec, add it to the global list
30 : and return it.
31 :
32 : create_proc can NOT call back into SkGlobals::Find (it would deadlock)
33 : */
34 : static Rec* Find(uint32_t tag, Rec* (*create_proc)());
35 : /** Helper for Find, when you want to assert that the Rec is already in the list
36 : */
37 : static Rec* Get(uint32_t tag)
38 : {
39 : Rec* rec = SkGlobals::Find(tag, NULL);
40 : SkASSERT(rec);
41 : return rec;
42 : }
43 :
44 : // used by porting layer
45 2951 : struct BootStrap {
46 : SkMutex fMutex;
47 : Rec* fHead;
48 : };
49 :
50 : private:
51 : static void Init();
52 : static void Term();
53 : friend class SkGraphics;
54 :
55 : // This last function is implemented in the porting layer
56 : static BootStrap& GetBootStrap();
57 : };
58 :
59 : #endif
60 :
|