1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SkGlobals_DEFINED 18 #define SkGlobals_DEFINED 19 20 #include "SkThread.h" 21 22 class SkGlobals { 23 public: 24 class Rec { 25 public: 26 virtual ~Rec(); 27 private: 28 Rec* fNext; 29 uint32_t fTag; 30 31 friend class SkGlobals; 32 }; 33 34 /** Look for a matching Rec for the specified tag. If one is found, return it. 35 If one is not found, if create_proc is null, return null, else 36 call the proc, and if it returns a Rec, add it to the global list 37 and return it. 38 39 create_proc can NOT call back into SkGlobals::Find (it would deadlock) 40 */ 41 static Rec* Find(uint32_t tag, Rec* (*create_proc)()); 42 /** Helper for Find, when you want to assert that the Rec is already in the list 43 */ Get(uint32_t tag)44 static Rec* Get(uint32_t tag) 45 { 46 Rec* rec = SkGlobals::Find(tag, NULL); 47 SkASSERT(rec); 48 return rec; 49 } 50 51 // used by porting layer 52 struct BootStrap { 53 SkMutex fMutex; 54 Rec* fHead; 55 }; 56 57 private: 58 static void Init(); 59 static void Term(); 60 friend class SkGraphics; 61 62 // This last function is implemented in the porting layer 63 static BootStrap& GetBootStrap(); 64 }; 65 66 #endif 67 68