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
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
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 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
|
|
|
|
2017-06-01 18:45:44 +00:00
|
|
|
/*
|
|
|
|
* Returns the maximum point size for text that may be cached.
|
|
|
|
*
|
|
|
|
* Sizes above this will be drawn directly from the font's outline.
|
|
|
|
* Setting this to a large value may speed up drawing larger text (repeatedly),
|
|
|
|
* but could cause the cache to purge other sizes more often.
|
|
|
|
*
|
|
|
|
* This value is a hint to the font engine, and the actual limit may be different due to
|
|
|
|
* implementation specific details.
|
|
|
|
*/
|
|
|
|
static int GetFontCachePointSizeLimit();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the maximum point size for text that may be cached, returning the previous value.
|
|
|
|
*
|
|
|
|
* Sizes above this will be drawn directly from the font's outline.
|
|
|
|
* Setting this to a large value may speed up drawing larger text (repeatedly),
|
|
|
|
* but could cause the cache to purge other sizes more often.
|
|
|
|
*
|
|
|
|
* This value is a hint to the font engine, and the actual limit may be different due to
|
|
|
|
* implementation specific details.
|
|
|
|
*/
|
|
|
|
static int SetFontCachePointSizeLimit(int maxPointSize);
|
|
|
|
|
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);
|
|
|
|
|
2016-02-22 14:19:54 +00:00
|
|
|
/**
|
|
|
|
* Free as much globally cached memory as possible. This will purge all private caches in Skia,
|
|
|
|
* including font and image caches.
|
|
|
|
*
|
|
|
|
* If there are caches associated with GPU context, those will not be affected by this call.
|
|
|
|
*/
|
|
|
|
static void PurgeAllCaches();
|
|
|
|
|
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
|
|
|
|
2017-02-15 20:14:16 +00:00
|
|
|
typedef std::unique_ptr<SkImageGenerator>
|
|
|
|
(*ImageGeneratorFromEncodedDataFactory)(sk_sp<SkData>);
|
2015-07-09 18:47:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2017-02-15 20:14:16 +00:00
|
|
|
static ImageGeneratorFromEncodedDataFactory
|
|
|
|
SetImageGeneratorFromEncodedDataFactory(ImageGeneratorFromEncodedDataFactory);
|
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
|