f8d7d27313
The new pixel ref behaves similarly to SkImageRef, with some key differences: It does not depend on the images project. It requires an SkImageCache, which handles allocation and caching of the pixel memory. It takes a function signature for decoding which decodes into already allocated pixel memory rather than into an SkBitmap. Add two implementations of SkImageCache: SkLruImageCache and SkAshmemImageCache. Replace SkSerializationHelpers::DecodeBitmap with SkPicture::InstallPixelRefProc, and update sites that referenced it. SkBitmapFactory now sets the pixel ref to a new object of the new class SkLazyPixelRef, provided it has an SkImageCache for caching. Provide an option to do lazy decodes in render_pictures and bench_pictures. SkPicture: Eliminate the default parameters in the constructor. If a proc for decoding bitmaps is installed, use it to decode any encoded data in subpictures. When parsing deserializing subpictures, check for success. When serializing subpictures, pass the picture's bitmap encoder to the subpicture's call to serialize. Update BitmapFactoryTest to test its new behavior. BUG=https://code.google.com/p/skia/issues/detail?id=1008 BUG=https://code.google.com/p/skia/issues/detail?id=1009 Review URL: https://codereview.appspot.com/7060052 git-svn-id: http://skia.googlecode.com/svn/trunk@7835 2bbb7eff-a529-9590-31e7-b0007b416f81
74 lines
1.7 KiB
C++
74 lines
1.7 KiB
C++
/*
|
|
* Copyright 2013 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#ifndef SkAshmemImageCache_DEFINED
|
|
#define SkAshmemImageCache_DEFINED
|
|
|
|
#include "SkImageCache.h"
|
|
#include "SkTDArray.h"
|
|
#include "SkTypes.h"
|
|
|
|
class SkAshmemImageCache : public SkImageCache {
|
|
|
|
public:
|
|
/**
|
|
* Get a pointer to the single global instance of SkAshmemImageCache.
|
|
*/
|
|
static SkAshmemImageCache* GetAshmemImageCache();
|
|
|
|
virtual void* allocAndPinCache(size_t bytes, intptr_t* ID) SK_OVERRIDE;
|
|
virtual void* pinCache(intptr_t ID) SK_OVERRIDE;
|
|
virtual void releaseCache(intptr_t ID) SK_OVERRIDE;
|
|
virtual void throwAwayCache(intptr_t ID) SK_OVERRIDE;
|
|
|
|
#ifdef SK_DEBUG
|
|
SkImageCache::CacheStatus getCacheStatus(intptr_t ID) const SK_OVERRIDE;
|
|
|
|
virtual ~SkAshmemImageCache();
|
|
#endif
|
|
|
|
private:
|
|
struct AshmemRec {
|
|
int fFD;
|
|
void* fAddr;
|
|
size_t fSize;
|
|
#ifdef SK_DEBUG
|
|
bool fPinned;
|
|
|
|
static int Compare(const AshmemRec*, const AshmemRec*);
|
|
#endif
|
|
};
|
|
|
|
/**
|
|
* Constructor is private. The correct way to get this cache is through
|
|
* GetAshmemImageCache, so that all callers can get the single global.
|
|
*/
|
|
SkAshmemImageCache();
|
|
|
|
#ifdef SK_DEBUG
|
|
// Stores a list of AshmemRecs to track deletion.
|
|
SkTDArray<AshmemRec*> fRecs;
|
|
|
|
/**
|
|
* Debug only function to add an AshmemRec to the list.
|
|
*/
|
|
void appendRec(AshmemRec*);
|
|
|
|
/**
|
|
* Return the index of AshmemRec.
|
|
*/
|
|
int findRec(const AshmemRec*) const;
|
|
#endif
|
|
|
|
/**
|
|
* Deletes AshmemRec. In debug, also removes from the list.
|
|
*/
|
|
void removeRec(AshmemRec*);
|
|
};
|
|
#endif // SkAshmemImageCache_DEFINED
|
|
|