use imageref_globalpool in samplepicture, to test flattening bitmaps
git-svn-id: http://skia.googlecode.com/svn/trunk@422 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
d03337c736
commit
c6ddc110c0
@ -21,6 +21,21 @@
|
||||
#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);
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user