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 177eeba2587760a0802fd2b90765b4fd0e5e895375reeduint64_t SkMakeResourceCacheSharedIDForBitmap(uint32_t bitmapGenID); 187eeba2587760a0802fd2b90765b4fd0e5e895375reed 197eeba2587760a0802fd2b90765b4fd0e5e895375reedvoid SkNotifyBitmapGenIDIsStale(uint32_t bitmapGenID); 207eeba2587760a0802fd2b90765b4fd0e5e895375reed 2104617139f7f715bdc05a32a58e65e3c208bccff4reedclass SkBitmapCache { 2204617139f7f715bdc05a32a58e65e3c208bccff4reedpublic: 23680fb9e8f10d24b5fe35c90338de37c57392f1aareed /** 248159146699f691b88f60564fc0811a6da3e8693fpiotaixr * Use this allocator for bitmaps, so they can use ashmem when available. 258159146699f691b88f60564fc0811a6da3e8693fpiotaixr * Returns NULL if the ResourceCache has not been initialized with a DiscardableFactory. 2614b6aba0997a8b463eae824d770fc5ad1ab89617reed */ 2714b6aba0997a8b463eae824d770fc5ad1ab89617reed static SkBitmap::Allocator* GetAllocator(); 2814b6aba0997a8b463eae824d770fc5ad1ab89617reed 2914b6aba0997a8b463eae824d770fc5ad1ab89617reed /** 30680fb9e8f10d24b5fe35c90338de37c57392f1aareed * Search based on the src bitmap and inverse scales in X and Y. If found, returns true and 31680fb9e8f10d24b5fe35c90338de37c57392f1aareed * result will be set to the matching bitmap with its pixels already locked. 32680fb9e8f10d24b5fe35c90338de37c57392f1aareed */ 3330ad5306be25565484a3dd76237984e071b7c4b3reed static bool Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, SkBitmap* result, 3430ad5306be25565484a3dd76237984e071b7c4b3reed SkResourceCache* localCache = NULL); 358159146699f691b88f60564fc0811a6da3e8693fpiotaixr 3614b6aba0997a8b463eae824d770fc5ad1ab89617reed /* 3714b6aba0997a8b463eae824d770fc5ad1ab89617reed * result must be marked isImmutable() 3814b6aba0997a8b463eae824d770fc5ad1ab89617reed */ 39680fb9e8f10d24b5fe35c90338de37c57392f1aareed static void Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, 4030ad5306be25565484a3dd76237984e071b7c4b3reed const SkBitmap& result, SkResourceCache* localCache = NULL); 41680fb9e8f10d24b5fe35c90338de37c57392f1aareed 42680fb9e8f10d24b5fe35c90338de37c57392f1aareed /** 4342b0dfeb29e993b7fd247dcecff705d3dd4cf191piotaixr * Search based on the bitmap's genID and subset. If found, returns true and 4442b0dfeb29e993b7fd247dcecff705d3dd4cf191piotaixr * result will be set to the matching bitmap with its pixels already locked. 4542b0dfeb29e993b7fd247dcecff705d3dd4cf191piotaixr */ 4630ad5306be25565484a3dd76237984e071b7c4b3reed static bool Find(uint32_t genID, const SkIRect& subset, SkBitmap* result, 4730ad5306be25565484a3dd76237984e071b7c4b3reed SkResourceCache* localCache = NULL); 4842b0dfeb29e993b7fd247dcecff705d3dd4cf191piotaixr 4942b0dfeb29e993b7fd247dcecff705d3dd4cf191piotaixr /** 5042b0dfeb29e993b7fd247dcecff705d3dd4cf191piotaixr * The width and the height of the provided subset must be the same as the result bitmap ones. 5142b0dfeb29e993b7fd247dcecff705d3dd4cf191piotaixr * result must be marked isImmutable() 5214b6aba0997a8b463eae824d770fc5ad1ab89617reed */ 5383787d0ff0a2b2f839a4a3ce6dadd033f83fe643reed static bool Add(SkPixelRef*, const SkIRect& subset, const SkBitmap& result, 5430ad5306be25565484a3dd76237984e071b7c4b3reed SkResourceCache* localCache = NULL); 5504617139f7f715bdc05a32a58e65e3c208bccff4reed}; 5604617139f7f715bdc05a32a58e65e3c208bccff4reed 5704617139f7f715bdc05a32a58e65e3c208bccff4reedclass SkMipMapCache { 5804617139f7f715bdc05a32a58e65e3c208bccff4reedpublic: 599d93c2ebb31bf996905532446644f242339a774ereed static const SkMipMap* FindAndRef(const SkBitmap& src, SkResourceCache* localCache = NULL); 609d93c2ebb31bf996905532446644f242339a774ereed static const SkMipMap* AddAndRef(const SkBitmap& src, SkResourceCache* localCache = NULL); 6104617139f7f715bdc05a32a58e65e3c208bccff4reed}; 6204617139f7f715bdc05a32a58e65e3c208bccff4reed 6304617139f7f715bdc05a32a58e65e3c208bccff4reed#endif 64