2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkGraphics_DEFINED
|
|
|
|
#define SkGraphics_DEFINED
|
|
|
|
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
2015-07-09 18:47:36 +00:00
|
|
|
class SkData;
|
|
|
|
class SkImageGenerator;
|
2015-08-27 16:23:54 +00:00
|
|
|
class SkTraceMemoryDump;
|
2015-07-09 18:47:36 +00:00
|
|
|
|
2012-04-23 13:43:30 +00:00
|
|
|
class SK_API SkGraphics {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2011-12-15 14:16:43 +00:00
|
|
|
/**
|
|
|
|
* Call this at process initialization time if your environment does not
|
2015-07-30 14:30:16 +00:00
|
|
|
* permit static global initializers that execute code.
|
|
|
|
* Init() is thread-safe and idempotent.
|
2011-12-15 14:16:43 +00:00
|
|
|
*/
|
2009-03-07 03:39:23 +00:00
|
|
|
static void Init();
|
2011-12-15 14:16:43 +00:00
|
|
|
|
2015-09-09 14:35:42 +00:00
|
|
|
// We're in the middle of cleaning this up.
|
|
|
|
static void Term() {}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-11-08 13:48:32 +00:00
|
|
|
/**
|
|
|
|
* Return the version numbers for the library. If the parameter is not
|
|
|
|
* null, it is set to the version number.
|
|
|
|
*/
|
|
|
|
static void GetVersion(int32_t* major, int32_t* minor, int32_t* patch);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the max number of bytes that should be used by the font cache.
|
|
|
|
* If the cache needs to allocate more, it will purge previous entries.
|
|
|
|
* This max can be changed by calling SetFontCacheLimit().
|
2010-04-13 13:22:54 +00:00
|
|
|
*/
|
2011-11-08 13:48:32 +00:00
|
|
|
static size_t GetFontCacheLimit();
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-11-08 13:48:32 +00:00
|
|
|
/**
|
|
|
|
* Specify the max number of bytes that should be used by the font cache.
|
|
|
|
* If the cache needs to allocate more, it will purge previous entries.
|
|
|
|
*
|
|
|
|
* This function returns the previous setting, as if GetFontCacheLimit()
|
|
|
|
* had be called before the new limit was set.
|
|
|
|
*/
|
|
|
|
static size_t SetFontCacheLimit(size_t bytes);
|
2010-04-13 13:22:54 +00:00
|
|
|
|
2012-07-30 13:08:01 +00:00
|
|
|
/**
|
|
|
|
* Return the number of bytes currently used by the font cache.
|
|
|
|
*/
|
|
|
|
static size_t GetFontCacheUsed();
|
|
|
|
|
2013-09-26 19:28:27 +00:00
|
|
|
/**
|
|
|
|
* Return the number of entries in the font cache.
|
|
|
|
* A cache "entry" is associated with each typeface + pointSize + matrix.
|
|
|
|
*/
|
|
|
|
static int GetFontCacheCountUsed();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the current limit to the number of entries in the font cache.
|
|
|
|
* A cache "entry" is associated with each typeface + pointSize + matrix.
|
|
|
|
*/
|
|
|
|
static int GetFontCacheCountLimit();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the limit to the number of entries in the font cache, and return
|
|
|
|
* the previous value. If this new value is lower than the previous,
|
|
|
|
* it will automatically try to purge entries to meet the new limit.
|
|
|
|
*/
|
|
|
|
static int SetFontCacheCountLimit(int count);
|
2013-09-27 07:01:29 +00:00
|
|
|
|
2011-11-08 20:03:48 +00:00
|
|
|
/**
|
|
|
|
* For debugging purposes, this will attempt to purge the font cache. It
|
|
|
|
* does not change the limit, but will cause subsequent font measures and
|
|
|
|
* draws to be recreated, since they will no longer be in the cache.
|
|
|
|
*/
|
|
|
|
static void PurgeFontCache();
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2014-07-17 13:58:01 +00:00
|
|
|
/**
|
2015-03-16 17:26:13 +00:00
|
|
|
* Scaling bitmaps with the kHigh_SkFilterQuality setting is
|
2014-07-17 13:58:01 +00:00
|
|
|
* expensive, so the result is saved in the global Scaled Image
|
|
|
|
* Cache.
|
|
|
|
*
|
|
|
|
* This function returns the memory usage of the Scaled Image Cache.
|
|
|
|
*/
|
2014-08-28 20:35:23 +00:00
|
|
|
static size_t GetResourceCacheTotalBytesUsed();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These functions get/set the memory usage limit for the resource cache, used for temporary
|
|
|
|
* bitmaps and other resources. Entries are purged from the cache when the memory useage
|
|
|
|
* exceeds this limit.
|
|
|
|
*/
|
|
|
|
static size_t GetResourceCacheTotalByteLimit();
|
|
|
|
static size_t SetResourceCacheTotalByteLimit(size_t newLimit);
|
|
|
|
|
2014-09-11 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* For debugging purposes, this will attempt to purge the resource cache. It
|
|
|
|
* does not change the limit.
|
|
|
|
*/
|
|
|
|
static void PurgeResourceCache();
|
|
|
|
|
2014-07-17 13:58:01 +00:00
|
|
|
/**
|
2014-08-28 20:35:23 +00:00
|
|
|
* When the cachable entry is very lage (e.g. a large scaled bitmap), adding it to the cache
|
|
|
|
* can cause most/all of the existing entries to be purged. To avoid the, the client can set
|
|
|
|
* a limit for a single allocation. If a cacheable entry would have been cached, but its size
|
|
|
|
* exceeds this limit, then we do not attempt to cache it at all.
|
|
|
|
*
|
|
|
|
* Zero is the default value, meaning we always attempt to cache entries.
|
2014-07-17 13:58:01 +00:00
|
|
|
*/
|
2014-08-28 20:35:23 +00:00
|
|
|
static size_t GetResourceCacheSingleAllocationByteLimit();
|
|
|
|
static size_t SetResourceCacheSingleAllocationByteLimit(size_t newLimit);
|
2014-07-17 13:58:01 +00:00
|
|
|
|
2015-08-27 16:23:54 +00:00
|
|
|
/**
|
|
|
|
* Dumps memory usage of caches using the SkTraceMemoryDump interface. See SkTraceMemoryDump
|
|
|
|
* for usage of this method.
|
|
|
|
*/
|
|
|
|
static void DumpMemoryStatistics(SkTraceMemoryDump* dump);
|
|
|
|
|
2011-11-21 20:42:14 +00:00
|
|
|
/**
|
|
|
|
* Applications with command line options may pass optional state, such
|
|
|
|
* as cache sizes, here, for instance:
|
|
|
|
* font-cache-limit=12345678
|
|
|
|
*
|
|
|
|
* The flags format is name=value[;name=value...] with no spaces.
|
|
|
|
* This format is subject to change.
|
|
|
|
*/
|
|
|
|
static void SetFlags(const char* flags);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-17 13:38:03 +00:00
|
|
|
/**
|
|
|
|
* Return the max number of bytes that should be used by the thread-local
|
|
|
|
* font cache.
|
|
|
|
* If the cache needs to allocate more, it will purge previous entries.
|
|
|
|
* This max can be changed by calling SetFontCacheLimit().
|
|
|
|
*
|
|
|
|
* If this thread has never called SetTLSFontCacheLimit, or has called it
|
|
|
|
* with 0, then this thread is using the shared font cache. In that case,
|
|
|
|
* this function will always return 0, and the caller may want to call
|
|
|
|
* GetFontCacheLimit.
|
|
|
|
*/
|
|
|
|
static size_t GetTLSFontCacheLimit();
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-17 13:38:03 +00:00
|
|
|
/**
|
|
|
|
* Specify the max number of bytes that should be used by the thread-local
|
2012-05-17 13:50:36 +00:00
|
|
|
* font cache. If this value is 0, then this thread will use the shared
|
|
|
|
* global font cache.
|
2012-05-17 13:38:03 +00:00
|
|
|
*/
|
2012-05-17 13:50:36 +00:00
|
|
|
static void SetTLSFontCacheLimit(size_t bytes);
|
2015-07-09 18:47:36 +00:00
|
|
|
|
|
|
|
typedef SkImageGenerator* (*ImageGeneratorFromEncodedFactory)(SkData*);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To instantiate images from encoded data, first looks at this runtime function-ptr. If it
|
|
|
|
* exists, it is called to create an SkImageGenerator from SkData. If there is no function-ptr
|
|
|
|
* or there is, but it returns NULL, then skia will call its internal default implementation.
|
2015-07-09 21:08:49 +00:00
|
|
|
*
|
|
|
|
* Returns the previous factory (which could be NULL).
|
2015-07-09 18:47:36 +00:00
|
|
|
*/
|
2015-07-09 21:08:49 +00:00
|
|
|
static ImageGeneratorFromEncodedFactory
|
|
|
|
SetImageGeneratorFromEncodedFactory(ImageGeneratorFromEncodedFactory);
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
2009-06-21 00:49:18 +00:00
|
|
|
class SkAutoGraphics {
|
|
|
|
public:
|
|
|
|
SkAutoGraphics() {
|
|
|
|
SkGraphics::Init();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#endif
|