use imageref_globalpool in samplepicture, to test flattening bitmaps
authorreed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 10 Nov 2009 15:54:55 +0000 (15:54 +0000)
committerreed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 10 Nov 2009 15:54:55 +0000 (15:54 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@422 2bbb7eff-a529-9590-31e7-b0007b416f81

samplecode/SamplePicture.cpp
src/images/SkImageRef.cpp

index 8ebb566e56d1ac11eba651c6966777a6aa1f30c8..4ca5b2a7d6a19f98daf4024f7e3aea5a5c5d8785 100644 (file)
 #include "SkStream.h"
 #include "SkXMLParser.h"
 
+#include "SkImageRef_GlobalPool.h"
+
+static SkBitmap load_bitmap() {
+    SkStream* stream = new SkFILEStream("/skimages/sesame_street_ensemble-hp.jpg");
+    SkAutoUnref aur(stream);
+    
+    SkBitmap bm;
+    if (SkImageDecoder::DecodeStream(stream, &bm, SkBitmap::kNo_Config,
+                                     SkImageDecoder::kDecodeBounds_Mode)) {
+        SkPixelRef* pr = new SkImageRef_GlobalPool(stream, bm.config(), 1);
+        bm.setPixelRef(pr)->unref();
+    }
+    return bm;
+}
+
 static void drawCircle(SkCanvas* canvas, int r, SkColor color) {
     SkPaint paint;
     paint.setAntiAlias(true);
@@ -31,13 +46,20 @@ static void drawCircle(SkCanvas* canvas, int r, SkColor color) {
 }
 
 class PictureView : public SkView {
+    SkBitmap fBitmap;
 public:
        PictureView() {
+        SkImageRef_GlobalPool::SetRAMBudget(16 * 1024);
+
+        fBitmap = load_bitmap();
+
         fPicture = new SkPicture;
         SkCanvas* canvas = fPicture->beginRecording(100, 100);
         SkPaint paint;
         paint.setAntiAlias(true);
         
+        canvas->drawBitmap(fBitmap, 0, 0, NULL);
+
         drawCircle(canvas, 50, SK_ColorBLACK);
         fSubPicture = new SkPicture;
         canvas->drawPicture(*fSubPicture);
@@ -75,7 +97,12 @@ protected:
     
     void drawSomething(SkCanvas* canvas) {
         SkPaint paint;
-        
+
+        canvas->save();
+        canvas->scale(0.5f, 0.5f);
+        canvas->drawBitmap(fBitmap, 0, 0, NULL);
+        canvas->restore();
+
         paint.setAntiAlias(true);
     
         paint.setColor(SK_ColorRED);
index 7ef5f404183b0ffb66acfefe4b596a9214e4d611..60e01c672bdfa5b86f8b2e513761036e88c850eb 100644 (file)
@@ -6,6 +6,8 @@
 #include "SkTemplates.h"
 #include "SkThread.h"
 
+//#define DUMP_IMAGEREF_LIFECYCLE
+
 // can't be static, as SkImageRef_Pool needs to see it
 SkMutex gImageRefMutex;
 
@@ -160,6 +162,8 @@ SkImageRef::SkImageRef(SkFlattenableReadBuffer& buffer)
         : INHERITED(buffer, &gImageRefMutex), fErrorInDecoding(false) {
     fConfig = (SkBitmap::Config)buffer.readU8();
     fSampleSize = buffer.readU8();
+    fDoDither = buffer.readBool();
+
     size_t length = buffer.readU32();
     fStream = SkNEW_ARGS(SkMemoryStream, (length));
     buffer.read((void*)fStream->getMemoryBase(), length);
@@ -173,6 +177,7 @@ void SkImageRef::flatten(SkFlattenableWriteBuffer& buffer) const {
 
     buffer.write8(fConfig);
     buffer.write8(fSampleSize);
+    buffer.writeBool(fDoDither);
     size_t length = fStream->getLength();
     buffer.write32(length);
     fStream->rewind();