Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Unified Diff: tests/DrawBitmapRectTest.cpp

Issue 103033002: Big Cleanup: SkBitmapFactory, SkLazyPixelRef, SkImageCache (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase one last time Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/DiscardableMemoryPool.cpp ('k') | tools/LazyDecodeBitmap.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/DrawBitmapRectTest.cpp
diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp
index 4c6d634eb0bb7d5810b9611df762e2598f3f2710..9289e11ea8f6a6a9737275fab19dc4304d0e4b9f 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));
« no previous file with comments | « tests/DiscardableMemoryPool.cpp ('k') | tools/LazyDecodeBitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698