remove picture-backed surfaces
BUG=skia: R=robertphillips@google.com, mtklein@google.com Author: reed@google.com Review URL: https://codereview.chromium.org/233943002 git-svn-id: http://skia.googlecode.com/svn/trunk@14159 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
c4b21e6c03
commit
cae54f1f21
14
gm/image.cpp
14
gm/image.cpp
@ -153,11 +153,12 @@ protected:
|
||||
|
||||
static const char* kLabel8 = "Pre-Alloc Img";
|
||||
static const char* kLabel9 = "New Alloc Img";
|
||||
static const char* kLabel10 = "SkPicture";
|
||||
static const char* kLabel11 = "Null Paint";
|
||||
static const char* kLabel12 = "GPU";
|
||||
static const char* kLabel10 = "Null Paint";
|
||||
static const char* kLabel11 = "GPU";
|
||||
|
||||
SkPaint textPaint;
|
||||
textPaint.setAntiAlias(true);
|
||||
textPaint.setTextSize(8);
|
||||
|
||||
canvas->drawText(kLabel1, strlen(kLabel1), 10, 60, textPaint);
|
||||
canvas->drawText(kLabel2, strlen(kLabel2), 10, 140, textPaint);
|
||||
@ -171,7 +172,6 @@ protected:
|
||||
canvas->drawText(kLabel9, strlen(kLabel9), 160, 10, textPaint);
|
||||
canvas->drawText(kLabel10, strlen(kLabel10), 250, 10, textPaint);
|
||||
canvas->drawText(kLabel11, strlen(kLabel11), 320, 10, textPaint);
|
||||
canvas->drawText(kLabel12, strlen(kLabel12), 410, 10, textPaint);
|
||||
|
||||
canvas->translate(80, 20);
|
||||
|
||||
@ -181,8 +181,6 @@ protected:
|
||||
SkImageInfo info = SkImageInfo::MakeN32Premul(W, H);
|
||||
SkAutoTUnref<SkSurface> surf0(SkSurface::NewRasterDirect(info, fBuffer, RB));
|
||||
SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info));
|
||||
SkAutoTUnref<SkSurface> surf2(SkSurface::NewPicture(info.fWidth, info.fHeight));
|
||||
SkAutoTUnref<SkSurface> surf3(SkSurface::NewPicture(info.fWidth, info.fHeight));
|
||||
#if SK_SUPPORT_GPU
|
||||
GrContext* ctx = canvas->getGrContext();
|
||||
|
||||
@ -192,10 +190,6 @@ protected:
|
||||
test_surface(canvas, surf0, true);
|
||||
canvas->translate(80, 0);
|
||||
test_surface(canvas, surf1, true);
|
||||
canvas->translate(80, 0);
|
||||
test_surface(canvas, surf2, true);
|
||||
canvas->translate(80, 0);
|
||||
test_surface(canvas, surf3, false);
|
||||
#if SK_SUPPORT_GPU
|
||||
if (NULL != ctx) {
|
||||
canvas->translate(80, 0);
|
||||
|
@ -209,12 +209,10 @@
|
||||
'<(skia_src_path)/image/SkImagePriv.cpp',
|
||||
'<(skia_src_path)/image/SkImage_Codec.cpp',
|
||||
# '<(skia_src_path)/image/SkImage_Gpu.cpp',
|
||||
'<(skia_src_path)/image/SkImage_Picture.cpp',
|
||||
'<(skia_src_path)/image/SkImage_Raster.cpp',
|
||||
'<(skia_src_path)/image/SkSurface.cpp',
|
||||
'<(skia_src_path)/image/SkSurface_Base.h',
|
||||
# '<(skia_src_path)/image/SkSurface_Gpu.cpp',
|
||||
'<(skia_src_path)/image/SkSurface_Picture.cpp',
|
||||
'<(skia_src_path)/image/SkSurface_Raster.cpp',
|
||||
|
||||
'<(skia_src_path)/pipe/SkGPipeRead.cpp',
|
||||
|
@ -189,7 +189,8 @@ public:
|
||||
|
||||
/**
|
||||
* Create a new surface matching the specified info, one that attempts to
|
||||
* be maximally compatible when used with this canvas.
|
||||
* be maximally compatible when used with this canvas. If there is no matching Surface type,
|
||||
* NULL is returned.
|
||||
*/
|
||||
SkSurface* newSurface(const SkImageInfo&);
|
||||
|
||||
|
@ -55,13 +55,6 @@ public:
|
||||
return NewRaster(SkImageInfo::MakeN32Premul(width, height));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new surface whose contents will be recorded into a picture.
|
||||
* When this surface is drawn into another canvas, its contents will be
|
||||
* "replayed" into that canvas.
|
||||
*/
|
||||
static SkSurface* NewPicture(int width, int height);
|
||||
|
||||
/**
|
||||
* Return a new surface using the specified render target.
|
||||
*/
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "SkDevice.h"
|
||||
#include "SkOffsetTable.h"
|
||||
#include "SkPictureStateTree.h"
|
||||
#include "SkSurface.h"
|
||||
|
||||
#define HEAP_BLOCK_SIZE 4096
|
||||
|
||||
@ -1571,7 +1570,7 @@ void SkPictureRecord::onPopCull() {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info) {
|
||||
return SkSurface::NewPicture(info.fWidth, info.fHeight);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SkPictureRecord::trackBitmapUse(int bitmapID, size_t offset) {
|
||||
|
@ -11,8 +11,6 @@
|
||||
#include "SkBitmap.h"
|
||||
#include "SkImage.h"
|
||||
|
||||
class SkPicture;
|
||||
|
||||
extern SkBitmap::Config SkImageInfoToBitmapConfig(const SkImageInfo&);
|
||||
|
||||
// Call this if you explicitly want to use/share this pixelRef in the image
|
||||
@ -31,18 +29,6 @@ extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*,
|
||||
*/
|
||||
extern SkImage* SkNewImageFromBitmap(const SkBitmap&, bool canSharePixelRef);
|
||||
|
||||
extern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*,
|
||||
SkScalar x, SkScalar y, const SkPaint*);
|
||||
|
||||
extern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*,
|
||||
const SkRect*, const SkRect&, const SkPaint*);
|
||||
|
||||
/**
|
||||
* Return an SkImage whose contents are those of the specified picture. Note:
|
||||
* The picture itself is unmodified, and may continue to be used for recording
|
||||
*/
|
||||
extern SkImage* SkNewImageFromPicture(const SkPicture*);
|
||||
|
||||
static inline size_t SkImageMinRowBytes(const SkImageInfo& info) {
|
||||
return SkAlign4(info.minRowBytes());
|
||||
}
|
||||
@ -52,9 +38,6 @@ static inline size_t SkImageMinRowBytes(const SkImageInfo& info) {
|
||||
// in which case the surface may need to perform a copy-on-write.
|
||||
extern SkPixelRef* SkBitmapImageGetPixelRef(SkImage* rasterImage);
|
||||
|
||||
// Given an image created with NewPicture, return its SkPicture.
|
||||
extern SkPicture* SkPictureImageGetPicture(SkImage* pictureImage);
|
||||
|
||||
// Given an image created with NewTexture, return its GrTexture. This
|
||||
// may be called to see if the surface and the image share the same GrTexture,
|
||||
// in which case the surface may need to perform a copy-on-write.
|
||||
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkImage_Base.h"
|
||||
#include "SkImagePriv.h"
|
||||
#include "SkPicture.h"
|
||||
|
||||
class SkImage_Picture : public SkImage_Base {
|
||||
public:
|
||||
SkImage_Picture(SkPicture*);
|
||||
virtual ~SkImage_Picture();
|
||||
|
||||
virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE;
|
||||
virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE;
|
||||
|
||||
SkPicture* getPicture() { return fPicture; }
|
||||
|
||||
private:
|
||||
SkPicture* fPicture;
|
||||
|
||||
typedef SkImage_Base INHERITED;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkImage_Picture::SkImage_Picture(SkPicture* pict) : INHERITED(pict->width(), pict->height()) {
|
||||
pict->endRecording();
|
||||
pict->ref();
|
||||
fPicture = pict;
|
||||
}
|
||||
|
||||
SkImage_Picture::~SkImage_Picture() {
|
||||
fPicture->unref();
|
||||
}
|
||||
|
||||
void SkImage_Picture::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
|
||||
const SkPaint* paint) {
|
||||
SkImagePrivDrawPicture(canvas, fPicture, x, y, paint);
|
||||
}
|
||||
|
||||
void SkImage_Picture::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst,
|
||||
const SkPaint* paint) {
|
||||
SkImagePrivDrawPicture(canvas, fPicture, src, dst, paint);
|
||||
}
|
||||
|
||||
SkImage* SkNewImageFromPicture(const SkPicture* srcPicture) {
|
||||
/**
|
||||
* We want to snapshot the playback status of the picture, w/o affecting
|
||||
* its ability to continue recording (if needed).
|
||||
*
|
||||
* Optimally this will shared as much data/buffers as it can with
|
||||
* srcPicture, and srcPicture will perform a copy-on-write as needed if it
|
||||
* needs to mutate them later on.
|
||||
*/
|
||||
SkAutoTUnref<SkPicture> playback(SkNEW_ARGS(SkPicture, (*srcPicture)));
|
||||
|
||||
return SkNEW_ARGS(SkImage_Picture, (playback));
|
||||
}
|
||||
|
||||
SkPicture* SkPictureImageGetPicture(SkImage* pictureImage) {
|
||||
return static_cast<SkImage_Picture*>(pictureImage)->getPicture();
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkSurface_Base.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkImagePriv.h"
|
||||
#include "SkPicture.h"
|
||||
|
||||
/**
|
||||
* What does it mean to ask for more than one canvas from a picture?
|
||||
* How do we return an Image and then "continue" recording?
|
||||
*/
|
||||
class SkSurface_Picture : public SkSurface_Base {
|
||||
public:
|
||||
SkSurface_Picture(int width, int height);
|
||||
virtual ~SkSurface_Picture();
|
||||
|
||||
virtual SkCanvas* onNewCanvas() SK_OVERRIDE;
|
||||
virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE;
|
||||
virtual SkImage* onNewImageSnapshot() SK_OVERRIDE;
|
||||
virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y,
|
||||
const SkPaint*) SK_OVERRIDE;
|
||||
virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE;
|
||||
virtual void onDiscard() SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
SkPicture* fPicture;
|
||||
|
||||
typedef SkSurface_Base INHERITED;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkSurface_Picture::SkSurface_Picture(int width, int height) : INHERITED(width, height) {
|
||||
fPicture = NULL;
|
||||
}
|
||||
|
||||
SkSurface_Picture::~SkSurface_Picture() {
|
||||
SkSafeUnref(fPicture);
|
||||
}
|
||||
|
||||
SkCanvas* SkSurface_Picture::onNewCanvas() {
|
||||
if (!fPicture) {
|
||||
fPicture = SkNEW(SkPicture);
|
||||
}
|
||||
SkCanvas* canvas = fPicture->beginRecording(this->width(), this->height());
|
||||
canvas->ref(); // our caller will call unref()
|
||||
return canvas;
|
||||
}
|
||||
|
||||
SkSurface* SkSurface_Picture::onNewSurface(const SkImageInfo& info) {
|
||||
return SkSurface::NewPicture(info.fWidth, info.fHeight);
|
||||
}
|
||||
|
||||
SkImage* SkSurface_Picture::onNewImageSnapshot() {
|
||||
if (fPicture) {
|
||||
return SkNewImageFromPicture(fPicture);
|
||||
} else {
|
||||
SkImageInfo info;
|
||||
info.fWidth = info.fHeight = 0;
|
||||
info.fColorType = kN32_SkColorType;
|
||||
info.fAlphaType = kOpaque_SkAlphaType;
|
||||
return SkImage::NewRasterCopy(info, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void SkSurface_Picture::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
|
||||
const SkPaint* paint) {
|
||||
if (!fPicture) {
|
||||
return;
|
||||
}
|
||||
SkImagePrivDrawPicture(canvas, fPicture, x, y, paint);
|
||||
}
|
||||
|
||||
void SkSurface_Picture::onCopyOnWrite(ContentChangeMode mode) {
|
||||
// We always spawn a copy of the recording picture when we
|
||||
// are asked for a snapshot, so we never need to do anything here.
|
||||
if (kDiscard_ContentChangeMode == mode) {
|
||||
this->SkSurface_Picture::onDiscard();
|
||||
}
|
||||
}
|
||||
|
||||
void SkSurface_Picture::onDiscard() {
|
||||
if (NULL != fPicture) {
|
||||
fPicture->beginRecording(this->width(), this->height());
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
SkSurface* SkSurface::NewPicture(int width, int height) {
|
||||
if ((width | height) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return SkNEW_ARGS(SkSurface_Picture, (width, height));
|
||||
}
|
@ -25,7 +25,6 @@ enum SurfaceType {
|
||||
kRasterDirect_SurfaceType,
|
||||
kGpu_SurfaceType,
|
||||
kGpuScratch_SurfaceType,
|
||||
kPicture_SurfaceType
|
||||
};
|
||||
|
||||
static const int gSurfaceSize = 10;
|
||||
@ -56,8 +55,6 @@ static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context,
|
||||
return context ? SkSurface::NewScratchRenderTarget(context, info) : NULL;
|
||||
#endif
|
||||
break;
|
||||
case kPicture_SurfaceType:
|
||||
return SkSurface::NewPicture(info.fWidth, info.fHeight);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -66,7 +63,6 @@ enum ImageType {
|
||||
kRasterCopy_ImageType,
|
||||
kRasterData_ImageType,
|
||||
kGpu_ImageType,
|
||||
kPicture_ImageType,
|
||||
kCodec_ImageType,
|
||||
};
|
||||
|
||||
@ -103,12 +99,6 @@ static SkImage* createImage(ImageType imageType, GrContext* context,
|
||||
return SkImage::NewRasterData(info, data, rowBytes);
|
||||
case kGpu_ImageType:
|
||||
return NULL; // TODO
|
||||
case kPicture_ImageType: {
|
||||
SkAutoTUnref<SkSurface> surf(SkSurface::NewPicture(info.fWidth,
|
||||
info.fHeight));
|
||||
surf->getCanvas()->drawColor(SK_ColorRED);
|
||||
return surf->newImageSnapshot();
|
||||
}
|
||||
case kCodec_ImageType: {
|
||||
SkBitmap bitmap;
|
||||
bitmap.installPixels(info, addr, rowBytes, NULL, NULL);
|
||||
@ -130,7 +120,6 @@ static void test_imagepeek(skiatest::Reporter* reporter) {
|
||||
{ kRasterCopy_ImageType, true },
|
||||
{ kRasterData_ImageType, true },
|
||||
{ kGpu_ImageType, false },
|
||||
{ kPicture_ImageType, false },
|
||||
{ kCodec_ImageType, false },
|
||||
};
|
||||
|
||||
@ -172,7 +161,6 @@ static void test_canvaspeek(skiatest::Reporter* reporter,
|
||||
{ kGpu_SurfaceType, false },
|
||||
{ kGpuScratch_SurfaceType, false },
|
||||
#endif
|
||||
{ kPicture_SurfaceType, false },
|
||||
};
|
||||
|
||||
const SkColor color = SK_ColorRED;
|
||||
@ -421,9 +409,7 @@ DEF_GPUTEST(Surface, reporter, factory) {
|
||||
test_image(reporter);
|
||||
|
||||
TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL);
|
||||
TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL);
|
||||
TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL);
|
||||
TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL);
|
||||
TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard_ContentChangeMode);
|
||||
TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ContentChangeMode);
|
||||
|
||||
@ -432,7 +418,6 @@ DEF_GPUTEST(Surface, reporter, factory) {
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
TestGetTexture(reporter, kRaster_SurfaceType, NULL);
|
||||
TestGetTexture(reporter, kPicture_SurfaceType, NULL);
|
||||
if (NULL != factory) {
|
||||
GrContext* context = factory->get(GrContextFactory::kNative_GLContextType);
|
||||
if (NULL != context) {
|
||||
|
Loading…
Reference in New Issue
Block a user