aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/DrawBitmapRectTest.cpp
diff options
context:
space:
mode:
authorGravatar halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-05 18:31:42 +0000
committerGravatar halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-05 18:31:42 +0000
commit2c7c7ee47d75e7815ea8db05e924ab55958cb402 (patch)
treee6b7221c8f6a6d3b9d548c923499f3cf23f79634 /tests/DrawBitmapRectTest.cpp
parent3e0446ccbfbeadd0d02d417cb68e950d6c92f8e1 (diff)
Big Cleanup: SkBitmapFactory, SkLazyPixelRef, SkImageCache
Removed SkBitmapFactory since no clients were using it. New cache selection mechanism can simply pass a SkDiscardableMemory::Factory into the SkDiscardablePixelRef if non-default SkDiscardableMemory should be used. Removed BitmapFactoryTest. SkDiscardableMemory::Factory interface. Android will need this functionality in the future inside their BitmapFactory. Removed SkLazyPixelRef, since it's functionality is now subsumed into SkDiscardablePixelRef. Removed LazyPixelRef test. Modified SkDiscardablePixelRef to optionally allow it to use a SkDiscardableMemory::Factory. This tiny change makes it a replacement for SkLazyPixelRef. This functioanlity is also necessary for moving Android over to SkDiscardablePixelRef from SkImageRef in a later CL. Added a test for this. SkDecodingImageGenerator::Install can optionally pass a factory in to SkDiscardablePixelRef. Removed SkImageCache, SkLruImageCache, and SkPurgeableImageCache. This functionality can be handled much more cleanly by SkDiscardableMemory. New SkDiscardableMemoryPool class to replace SkLruImageCache. In a later CL, we will replace SkImageRef_GlobalPool (used by android) as well. This is a concrete implementation of SkDiscardableMemory::Factory. Added a test for this. modified gm/factory.cpp to remove dependnce on SkBitmapFactory + SkLruImageCache. Now uses SkDecodingImageGenerator + SkDiscardablePixelRef + SkDiscardableMemoryPool. SkImageDecoder::Target replaces SkBitmapFactory::Target. The DecodeMemoryToTarget function may disappear in the future. Moved SkLazyCachingPixelRef::DecodeProc replaces SkBitmapFactory::DecodeProc. This is a short term change, since another CL changes SkLazyCachingPixelRef to use SkImageGenerator instead of DecodeProc. Modified DrawBitmapRectTest to use SkDiscardablePixelRef instead of SkLazyPixelRef. tools/LazyDecodeBitmap.cpp now uses SkDecodingImageGenerator + SkDiscardablePixelRef instead of a SkBitmapFactory. bench_pictures uses the Global SkDiscardableMemoryPool instead of a global gLruImageCache. R=reed@google.com, scroggo@google.com Review URL: https://codereview.chromium.org/103033002 git-svn-id: http://skia.googlecode.com/svn/trunk@12515 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/DrawBitmapRectTest.cpp')
-rw-r--r--tests/DrawBitmapRectTest.cpp44
1 files changed, 25 insertions, 19 deletions
diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp
index 4c6d634eb0..9289e11ea8 100644
--- a/tests/DrawBitmapRectTest.cpp
+++ b/tests/DrawBitmapRectTest.cpp
@@ -9,41 +9,47 @@
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkData.h"
+#include "SkDiscardableMemoryPool.h"
+#include "SkDiscardablePixelRef.h"
#include "SkPaint.h"
#include "SkShader.h"
#include "SkSurface.h"
#include "SkRandom.h"
#include "SkMatrixUtils.h"
-#include "SkLazyPixelRef.h"
-#include "SkLruImageCache.h"
-
+namespace {
// A BitmapFactory that always fails when asked to return pixels.
-static bool FailureDecoder(const void* data, size_t length, SkImageInfo* info,
- const SkBitmapFactory::Target* target) {
- if (info) {
- info->fWidth = info->fHeight = 100;
- info->fColorType = kRGBA_8888_SkColorType;
+class FailureImageGenerator : public SkImageGenerator {
+public:
+ FailureImageGenerator() { }
+ virtual ~FailureImageGenerator() { }
+ virtual bool getInfo(SkImageInfo* info) {
+ info->fWidth = 100;
+ info->fHeight = 100;
+ info->fColorType = kPMColor_SkColorType;
info->fAlphaType = kPremul_SkAlphaType;
+ return true;
}
- // this will deliberately return false if they are asking us to decode
- // into pixels.
- return NULL == target;
-}
+ virtual bool getPixels(const SkImageInfo& info,
+ void* pixels,
+ size_t rowBytes) SK_OVERRIDE {
+ // this will deliberately return false if they are asking us
+ // to decode into pixels.
+ return false;
+ }
+};
+} // namespace
// crbug.com/295895
// Crashing in skia when a pixelref fails in lockPixels
//
static void test_faulty_pixelref(skiatest::Reporter* reporter) {
// need a cache, but don't expect to use it, so the budget is not critical
- SkLruImageCache cache(10 * 1000);
- // construct a garbage data represent "bad" encoded data.
- SkAutoDataUnref data(SkData::NewFromMalloc(malloc(1000), 1000));
- SkAutoTUnref<SkPixelRef> pr(new SkLazyPixelRef(data, FailureDecoder, &cache));
-
+ SkAutoTUnref<SkDiscardableMemoryPool> pool(SkNEW_ARGS(SkDiscardableMemoryPool,
+ (10 * 1000, NULL)));
SkBitmap bm;
- bm.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
- bm.setPixelRef(pr);
+ bool installSuccess = SkDiscardablePixelRef::Install(SkNEW(FailureImageGenerator), &bm, pool);
+ REPORTER_ASSERT(reporter, installSuccess);
// now our bitmap has a pixelref, but we know it will fail to lock
SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(200, 200));