104617139f7f715bdc05a32a58e65e3c208bccff4reed/* 204617139f7f715bdc05a32a58e65e3c208bccff4reed * Copyright 2014 Google Inc. 304617139f7f715bdc05a32a58e65e3c208bccff4reed * 404617139f7f715bdc05a32a58e65e3c208bccff4reed * Use of this source code is governed by a BSD-style license that can be 504617139f7f715bdc05a32a58e65e3c208bccff4reed * found in the LICENSE file. 604617139f7f715bdc05a32a58e65e3c208bccff4reed */ 704617139f7f715bdc05a32a58e65e3c208bccff4reed 804617139f7f715bdc05a32a58e65e3c208bccff4reed#ifndef SkBitmapCache_DEFINED 904617139f7f715bdc05a32a58e65e3c208bccff4reed#define SkBitmapCache_DEFINED 1004617139f7f715bdc05a32a58e65e3c208bccff4reed 11680fb9e8f10d24b5fe35c90338de37c57392f1aareed#include "SkScalar.h" 1214b6aba0997a8b463eae824d770fc5ad1ab89617reed#include "SkBitmap.h" 13680fb9e8f10d24b5fe35c90338de37c57392f1aareed 1430ad5306be25565484a3dd76237984e071b7c4b3reedclass SkResourceCache; 15680fb9e8f10d24b5fe35c90338de37c57392f1aareedclass SkMipMap; 1604617139f7f715bdc05a32a58e65e3c208bccff4reed 1704617139f7f715bdc05a32a58e65e3c208bccff4reedclass SkBitmapCache { 1804617139f7f715bdc05a32a58e65e3c208bccff4reedpublic: 19680fb9e8f10d24b5fe35c90338de37c57392f1aareed /** 208159146699f691b88f60564fc0811a6da3e8693fpiotaixr * Use this allocator for bitmaps, so they can use ashmem when available. 218159146699f691b88f60564fc0811a6da3e8693fpiotaixr * Returns NULL if the ResourceCache has not been initialized with a DiscardableFactory. 2214b6aba0997a8b463eae824d770fc5ad1ab89617reed */ 2314b6aba0997a8b463eae824d770fc5ad1ab89617reed static SkBitmap::Allocator* GetAllocator(); 2414b6aba0997a8b463eae824d770fc5ad1ab89617reed 2514b6aba0997a8b463eae824d770fc5ad1ab89617reed /** 26680fb9e8f10d24b5fe35c90338de37c57392f1aareed * Search based on the src bitmap and inverse scales in X and Y. If found, returns true and 27680fb9e8f10d24b5fe35c90338de37c57392f1aareed * result will be set to the matching bitmap with its pixels already locked. 28680fb9e8f10d24b5fe35c90338de37c57392f1aareed */ 2930ad5306be25565484a3dd76237984e071b7c4b3reed static bool Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, SkBitmap* result, 3030ad5306be25565484a3dd76237984e071b7c4b3reed SkResourceCache* localCache = NULL); 318159146699f691b88f60564fc0811a6da3e8693fpiotaixr 3214b6aba0997a8b463eae824d770fc5ad1ab89617reed /* 3314b6aba0997a8b463eae824d770fc5ad1ab89617reed * result must be marked isImmutable() 3414b6aba0997a8b463eae824d770fc5ad1ab89617reed */ 35680fb9e8f10d24b5fe35c90338de37c57392f1aareed static void Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, 3630ad5306be25565484a3dd76237984e071b7c4b3reed const SkBitmap& result, SkResourceCache* localCache = NULL); 37680fb9e8f10d24b5fe35c90338de37c57392f1aareed 38680fb9e8f10d24b5fe35c90338de37c57392f1aareed /** 3942b0dfeb29e993b7fd247dcecff705d3dd4cf191piotaixr * Search based on the bitmap's genID and subset. If found, returns true and 4042b0dfeb29e993b7fd247dcecff705d3dd4cf191piotaixr * result will be set to the matching bitmap with its pixels already locked. 4142b0dfeb29e993b7fd247dcecff705d3dd4cf191piotaixr */ 4230ad5306be25565484a3dd76237984e071b7c4b3reed static bool Find(uint32_t genID, const SkIRect& subset, SkBitmap* result, 4330ad5306be25565484a3dd76237984e071b7c4b3reed SkResourceCache* localCache = NULL); 4442b0dfeb29e993b7fd247dcecff705d3dd4cf191piotaixr 4542b0dfeb29e993b7fd247dcecff705d3dd4cf191piotaixr /** 4642b0dfeb29e993b7fd247dcecff705d3dd4cf191piotaixr * The width and the height of the provided subset must be the same as the result bitmap ones. 4742b0dfeb29e993b7fd247dcecff705d3dd4cf191piotaixr * result must be marked isImmutable() 4814b6aba0997a8b463eae824d770fc5ad1ab89617reed */ 4930ad5306be25565484a3dd76237984e071b7c4b3reed static bool Add(uint32_t genID, const SkIRect& subset, const SkBitmap& result, 5030ad5306be25565484a3dd76237984e071b7c4b3reed SkResourceCache* localCache = NULL); 5104617139f7f715bdc05a32a58e65e3c208bccff4reed}; 5204617139f7f715bdc05a32a58e65e3c208bccff4reed 5304617139f7f715bdc05a32a58e65e3c208bccff4reedclass SkMipMapCache { 5404617139f7f715bdc05a32a58e65e3c208bccff4reedpublic: 55680fb9e8f10d24b5fe35c90338de37c57392f1aareed static const SkMipMap* FindAndRef(const SkBitmap& src); 56680fb9e8f10d24b5fe35c90338de37c57392f1aareed static void Add(const SkBitmap& src, const SkMipMap* result); 5704617139f7f715bdc05a32a58e65e3c208bccff4reed}; 5804617139f7f715bdc05a32a58e65e3c208bccff4reed 5904617139f7f715bdc05a32a58e65e3c208bccff4reed#endif 60