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 SkGraphics_DEFINED 18 #define SkGraphics_DEFINED 19 20 #include "SkTypes.h" 21 22 class SkGraphics { 23 public: 24 static void Init(); 25 static void Term(); 26 27 /** Return the (approximate) number of bytes used by the font cache. 28 */ 29 static size_t GetFontCacheUsed(); 30 31 /** Attempt to purge the font cache until <= the specified amount remains 32 in the cache. Specifying 0 will attempt to purge the entire cache. 33 Returns true if some amount was purged from the font cache. 34 */ 35 static bool SetFontCacheUsed(size_t usageInBytes); 36 37 private: 38 /** This is automatically called by SkGraphics::Init(), and must be 39 implemented by the host OS. This allows the host OS to register a callback 40 with the C++ runtime to call SkGraphics::FreeCaches() 41 */ 42 static void InstallNewHandler(); 43 }; 44 45 class SkAutoGraphics { 46 public: SkAutoGraphics()47 SkAutoGraphics() { 48 SkGraphics::Init(); 49 } ~SkAutoGraphics()50 ~SkAutoGraphics() { 51 SkGraphics::Term(); 52 } 53 }; 54 55 #endif 56 57