};
SkTileGridFactory factory(info);
SkPictureRecorder recorder;
- pic->draw(recorder.beginRecording(pic->width(), pic->height(), &factory));
+ pic->draw(recorder.beginRecording(pic->cullRect().width(),
+ pic->cullRect().height(),
+ &factory));
pic.reset(recorder.endRecording());
}
fGpuDevice = SkGpuDevice::Create(curRenderTarget);
fCanvas = new SkCanvas(fGpuDevice);
}
- fDebugger->resize(w, h);
+ fDebugger->setWindowSize(w, h);
draw();
}
SkSafeUnref(fDevice);
fDevice = new SkBitmapDevice(fBitmap);
fCanvas = new SkCanvas(fDevice);
- fDebugger->resize(event->size().width(), event->size().height());
+ fDebugger->setWindowSize(event->size().width(), event->size().height());
this->update();
}
SkDebugger::SkDebugger() {
// Create this some other dynamic way?
- fDebugCanvas = new SkDebugCanvas(100, 100);
+ fDebugCanvas = new SkDebugCanvas(0, 0);
fPicture = NULL;
- fPictureWidth = 0;
- fPictureHeight = 0;
fIndex = 0;
}
}
void SkDebugger::loadPicture(SkPicture* picture) {
- fPictureWidth = picture->width();
- fPictureHeight = picture->height();
+ SkRefCnt_SafeAssign(fPicture, picture);
+
delete fDebugCanvas;
- fDebugCanvas = new SkDebugCanvas(fPictureWidth, fPictureHeight);
- fDebugCanvas->setBounds(fPictureWidth, fPictureHeight);
+ fDebugCanvas = new SkDebugCanvas(SkScalarCeilToInt(this->pictureCull().width()),
+ SkScalarCeilToInt(this->pictureCull().height()));
fDebugCanvas->setPicture(picture);
picture->draw(fDebugCanvas);
fDebugCanvas->setPicture(NULL);
fIndex = fDebugCanvas->getSize() - 1;
- SkRefCnt_SafeAssign(fPicture, picture);
}
SkPicture* SkDebugger::copyPicture() {
// We can't just call clone here since we want to removed the "deleted"
// commands. Playing back will strip those out.
SkPictureRecorder recorder;
- SkCanvas* canvas = recorder.beginRecording(fPictureWidth, fPictureHeight, NULL, 0);
+ SkCanvas* canvas = recorder.beginRecording(this->pictureCull().width(),
+ this->pictureCull().height());
bool vizMode = fDebugCanvas->getMegaVizMode();
fDebugCanvas->setMegaVizMode(false);
totalStr.append("<br/>");
overview->insert(0, totalStr);
+ overview->append("<br/>SkPicture L: ");
+ overview->appendScalar(this->pictureCull().fLeft);
+ overview->append(" T: ");
+ overview->appendScalar(this->pictureCull().fTop);
+ overview->append(" R: ");
+ overview->appendScalar(this->pictureCull().fRight);
+ overview->append(" B: ");
+ overview->appendScalar(this->pictureCull().fBottom);
overview->append("<br/>");
- overview->append("SkPicture Width: ");
- overview->appendS32(pictureWidth());
- overview->append("px<br/>");
- overview->append("SkPicture Height: ");
- overview->appendS32(pictureHeight());
- overview->append("px");
}
void SkDebugger::getClipStackText(SkString* clipStack) {
fDebugCanvas->toggleFilter(on);
}
- void resize(int width, int height) {
- fDebugCanvas->setBounds(width, height);
- }
+ void setWindowSize(int width, int height) { fDebugCanvas->setWindowSize(width, height); }
void loadPicture(SkPicture* picture);
return fDebugCanvas->getCurrentClip();
}
- int pictureHeight() {
- return fPictureHeight;
- }
-
- int pictureWidth() {
- return fPictureWidth;
+ SkRect pictureCull() const {
+ return NULL == fPicture ? SkRect::MakeEmpty() : fPicture->cullRect();
}
int index() {
SkDebugCanvas* fDebugCanvas;
SkPicture* fPicture;
- int fPictureWidth;
- int fPictureHeight;
int fIndex;
};
fGM->draw(pdf.canvas());
pdfData.reset(pdf.end());
} else {
- SinglePagePDF pdf(SkIntToScalar(fPicture->width()), SkIntToScalar(fPicture->height()));
+ SinglePagePDF pdf(fPicture->cullRect().width(), fPicture->cullRect().height());
fPicture->draw(pdf.canvas());
pdfData.reset(pdf.end());
}
: CpuTask(r, tr), fPicture(SkRef(pic)), fName(FileToTaskName(filename)) {}
void SKPTask::draw() {
- const int width = SkTMin(fPicture->width(), FLAGS_skpMaxWidth),
- height = SkTMin(fPicture->height(), FLAGS_skpMaxHeight);
+ const int width = SkTMin(SkScalarCeilToInt(fPicture->cullRect().width()), FLAGS_skpMaxWidth),
+ height = SkTMin(SkScalarCeilToInt(fPicture->cullRect().height()), FLAGS_skpMaxHeight);
SkBitmap bitmap;
AllocatePixels(kN32_SkColorType, width, height, &bitmap);
DrawPicture(*fPicture, &bitmap);
}
SkPicture* RecordPicture(skiagm::GM* gm, SkBBHFactory* factory, bool skr) {
- const int w = gm->getISize().width(),
- h = gm->getISize().height();
+ const SkScalar w = SkIntToScalar(gm->getISize().width()),
+ h = SkIntToScalar(gm->getISize().height());
SkPictureRecorder recorder;
SkCanvas* canvas = skr ? recorder.EXPERIMENTAL_beginRecording(w, h, factory)
SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&stream));
PictureHeader header;
- SkRandom rand(picture->width() * picture->height());
- SkScalar r = rand.nextRangeScalar(0, picture->width()),
- b = rand.nextRangeScalar(0, picture->height()),
+ SkRandom rand(picture->cullRect().width() * picture->cullRect().height());
+ SkScalar r = rand.nextRangeScalar(0, picture->cullRect().width()),
+ b = rand.nextRangeScalar(0, picture->cullRect().height()),
l = rand.nextRangeScalar(0, r),
t = rand.nextRangeScalar(0, b);
header.clip.setLTRB(l,t,r,b);
SkISize onISize() { return SkISize::Make(100, 100); }
virtual void onDraw(SkCanvas* canvas) {
- int offset = 35000;
- int extents = 1000;
+ static const SkScalar kOffset = 35000.0f;
+ static const SkScalar kExtents = 1000.0f;
SkPictureRecorder recorder;
// We record a picture of huge vertical extents in which we clear the canvas to red, create
// a 'extents' by 'extents' round rect clip at a vertical offset of 'offset', then draw
// green into that.
- SkCanvas* rec = recorder.beginRecording(100, offset + extents, NULL, 0);
- rec->drawColor(0xffff0000);
+ SkCanvas* rec = recorder.beginRecording(kExtents, kOffset + kExtents, NULL, 0);
+ rec->drawColor(SK_ColorRED);
rec->save();
- SkRect r = {
- SkIntToScalar(-extents),
- SkIntToScalar(offset - extents),
- SkIntToScalar(extents),
- SkIntToScalar(offset + extents)
- };
+ SkRect r = SkRect::MakeXYWH(-kExtents, kOffset - kExtents, 2 * kExtents, 2 * kExtents);
SkPath p;
p.addRoundRect(r, 5, 5);
rec->clipPath(p, SkRegion::kIntersect_Op, true);
- rec->drawColor(0xff00ff00);
+ rec->drawColor(SK_ColorGREEN);
rec->restore();
SkAutoTUnref<SkPicture> pict(recorder.endRecording());
// Next we play that picture into another picture of the same size.
- pict->draw(recorder.beginRecording(100, offset + extents, NULL, 0));
+ pict->draw(recorder.beginRecording(pict->cullRect().width(),
+ pict->cullRect().height(),
+ NULL, 0));
SkAutoTUnref<SkPicture> pict2(recorder.endRecording());
// Finally we play the part of that second picture that should be green into the canvas.
canvas->save();
- canvas->translate(SkIntToScalar(extents / 2),
- SkIntToScalar(-(offset - extents / 2)));
+ canvas->translate(kExtents / 2, -(kOffset - kExtents / 2));
pict2->draw(canvas);
canvas->restore();
static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags,
SkScalar scale = SK_Scalar1) {
- int width = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().width()), scale));
- int height = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().height()), scale));
+ SkScalar width = SkScalarMul(SkIntToScalar(gm->getISize().width()), scale);
+ SkScalar height = SkScalarMul(SkIntToScalar(gm->getISize().height()), scale);
SkAutoTDelete<SkBBHFactory> factory;
if (kTileGrid_BbhType == bbhType) {
SkPictureRecorder recorder;
- SkCanvas* canvas = recorder.beginRecording(kPicWidth, kPicHeight);
+ SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth),
+ SkIntToScalar(kPicHeight));
SkScalar xPos, yPos = 0;
static void rect_clip(SkCanvas* canvas, const SkPicture* pictures[2]) {
canvas->drawPicture(pictures[0]);
- SkRect rect = SkRect::MakeWH(SkIntToScalar(kPicWidth), SkIntToScalar(kPicHeight));
+ SkRect rect = pictures[0]->cullRect();
rect.inset(kInset, kInset);
canvas->clipRect(rect);
static void rrect_clip(SkCanvas* canvas, const SkPicture* pictures[2]) {
canvas->drawPicture(pictures[0]);
- SkRect rect = SkRect::MakeWH(SkIntToScalar(kPicWidth), SkIntToScalar(kPicHeight));
+ SkRect rect = pictures[0]->cullRect();
rect.inset(kInset, kInset);
SkRRect rrect;
{
SkPictureRecorder recorder;
- SkCanvas* pictureCanvas = recorder.beginRecording(kPicWidth, kPicHeight);
+ SkCanvas* pictureCanvas = recorder.beginRecording(SkIntToScalar(kPicWidth),
+ SkIntToScalar(kPicHeight));
(*pfGen)(pictureCanvas, pictures);
fPictures[1] = make_picture(SK_ColorGRAY);
}
- virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE{
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkMultiPictureDraw mpd;
SkTArray<ComposeStep> composeSteps;
}
}
- virtual SkISize onISize() SK_OVERRIDE{ return SkISize::Make(kPicWidth, kPicHeight); }
+ virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(kPicWidth, kPicHeight); }
- virtual SkString onShortName() SK_OVERRIDE{
+ virtual SkString onShortName() SK_OVERRIDE {
static const char* gContentNames[] = {
"noclip", "rectclip", "rrectclip", "pathclip", "invpathclip"
};
// heavy-weight operation since we are drawing the picture into a debug canvas
// to extract the commands.
static bool check_pattern(SkPicture& input, const SkTDArray<DrawType> &pattern) {
- SkDebugCanvas debugCanvas(input.width(), input.height());
- debugCanvas.setBounds(input.width(), input.height());
+ SkDebugCanvas debugCanvas(SkScalarCeilToInt(input.cullRect().width()),
+ SkScalarCeilToInt(input.cullRect().height()));
input.draw(&debugCanvas);
if (pattern.count() != debugCanvas.getSize()) {
};
SkTDArray<DrawType> prePattern, postPattern;
- int xPos = 0, yPos = 0;
+ SkScalar xPos = 0, yPos = 0;
for (size_t i = 0; i < SK_ARRAY_COUNT(gOpts); ++i) {
SkAutoTUnref<SkPicture> pre((*gOpts[i])(&prePattern, &postPattern, fCheckerboard));
}
canvas->save();
- canvas->translate(SkIntToScalar(xPos), SkIntToScalar(yPos));
+ canvas->translate(xPos, yPos);
pre->draw(canvas);
- xPos += pre->width();
+ xPos += pre->cullRect().width();
canvas->restore();
// re-render the 'pre' picture and thus 'apply' the optimization
SkPictureRecorder recorder;
SkCanvas* recordCanvas =
- recorder.DEPRECATED_beginRecording(pre->width(), pre->height(), NULL, 0);
+ recorder.DEPRECATED_beginRecording(pre->cullRect().width(),
+ pre->cullRect().height(),
+ NULL, 0);
pre->draw(recordCanvas);
}
canvas->save();
- canvas->translate(SkIntToScalar(xPos), SkIntToScalar(yPos));
+ canvas->translate(xPos, yPos);
post->draw(canvas);
- xPos += post->width();
+ xPos += post->cullRect().width();
canvas->restore();
if (xPos >= kWidth) {
// start a new line
xPos = 0;
- yPos += post->height();
+ yPos += post->cullRect().height();
}
// TODO: we could also render the pre and post pictures to bitmaps
// Build the picture.
SkPictureRecorder recorder;
- SkCanvas* pictureCanvas = recorder.beginRecording(SkScalarRoundToInt(tileSize),
- SkScalarRoundToInt(tileSize),
- NULL, 0);
+ SkCanvas* pictureCanvas = recorder.beginRecording(tileSize, tileSize, NULL, 0);
this->drawTile(pictureCanvas);
fPicture.reset(recorder.endRecording());
// Build a reference bitmap.
- fBitmap.allocN32Pixels(SkScalarRoundToInt(tileSize), SkScalarRoundToInt(tileSize));
+ fBitmap.allocN32Pixels(SkScalarCeilToInt(tileSize), SkScalarCeilToInt(tileSize));
fBitmap.eraseColor(SK_ColorTRANSPARENT);
SkCanvas bitmapCanvas(fBitmap);
this->drawTile(&bitmapCanvas);
public:
PictureShaderTileGM() {
SkPictureRecorder recorder;
- SkCanvas* pictureCanvas = recorder.beginRecording(SkScalarCeilToInt(kPictureSize),
- SkScalarCeilToInt(kPictureSize),
- NULL, 0);
+ SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPictureSize, NULL, 0);
drawScene(pictureCanvas, kPictureSize);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
# Transitional, for deprecated SkCanvas::SaveFlags methods.
'SK_ATTR_DEPRECATED=SK_NOTHING_ARG1',
'SK_SUPPORT_LEGACY_DEFAULT_PICTURE_CTOR',
+ 'SK_LEGACY_PICTURE_SIZE_API',
],
},
}
'SK_IGNORE_ETC1_SUPPORT',
'SK_IGNORE_GPU_DITHER',
'SK_SUPPORT_LEGACY_IMAGECACHE_NAME',
+ 'SK_LEGACY_PICTURE_SIZE_API',
],
},
}
*/
void draw(SkCanvas* canvas, SkDrawPictureCallback* = NULL) const;
- /** Return the width of the picture's recording canvas. This
- value reflects what was passed to setSize(), and does not necessarily
- reflect the bounds of what has been recorded into the picture.
- @return the width of the picture's recording canvas
- */
- int width() const { return fWidth; }
+#ifdef SK_LEGACY_PICTURE_SIZE_API
+ int width() const { return SkScalarCeilToInt(fCullWidth); }
+ int height() const { return SkScalarCeilToInt(fCullHeight); }
+#endif
- /** Return the height of the picture's recording canvas. This
- value reflects what was passed to setSize(), and does not necessarily
- reflect the bounds of what has been recorded into the picture.
- @return the height of the picture's recording canvas
+ /** Return the cull rect used when creating this picture: { 0, 0, cullWidth, cullHeight }.
+ It does not necessarily reflect the bounds of what has been recorded into the picture.
+ @return the cull rect used to create this picture
*/
- int height() const { return fHeight; }
+ const SkRect cullRect() const { return SkRect::MakeWH(fCullWidth, fCullHeight); }
/** Return a non-zero, unique value representing the picture. This call is
only valid when not recording. Between a beginRecording/endRecording
If false is returned, SkPictInfo is unmodified.
*/
static bool InternalOnly_StreamIsSKP(SkStream*, SkPictInfo*);
- static bool InternalOnly_BufferIsSKP(SkReadBuffer&, SkPictInfo*);
+ static bool InternalOnly_BufferIsSKP(SkReadBuffer*, SkPictInfo*);
/** Return true if the picture is suitable for rendering on the GPU.
*/
// V32: Removed SkPaintOptionsAndroid from SkPaint
// V33: Serialize only public API of effects.
// V34: Add SkTextBlob serialization.
+ // V35: Store SkRect (rather then width & height) in header
// Note: If the picture version needs to be increased then please follow the
// steps to generate new SKPs in (only accessible to Googlers): http://goo.gl/qATVcw
// Only SKPs within the min/current picture version range (inclusive) can be read.
static const uint32_t MIN_PICTURE_VERSION = 19;
- static const uint32_t CURRENT_PICTURE_VERSION = 34;
+ static const uint32_t CURRENT_PICTURE_VERSION = 35;
mutable uint32_t fUniqueID;
// TODO: make SkPictureData const when clone method goes away
SkAutoTDelete<SkPictureData> fData;
- int fWidth, fHeight;
+ const SkScalar fCullWidth;
+ const SkScalar fCullHeight;
mutable SkAutoTUnref<const AccelData> fAccelData;
mutable SkTDArray<DeletionListener*> fDeletionListeners; // pointers are refed
// Create a new SkPicture from an existing SkPictureData. The new picture
// takes ownership of 'data'.
- SkPicture(SkPictureData* data, int width, int height);
+ SkPicture(SkPictureData* data, SkScalar width, SkScalar height);
- SkPicture(int width, int height, const SkPictureRecord& record, bool deepCopyOps);
+ SkPicture(SkScalar width, SkScalar height, const SkPictureRecord& record, bool deepCopyOps);
// An OperationList encapsulates a set of operation offsets into the picture byte
// stream along with the CTMs needed for those operation.
typedef SkRefCnt INHERITED;
// Takes ownership of the SkRecord, refs the (optional) BBH.
- SkPicture(int width, int height, SkRecord*, SkBBoxHierarchy*);
+ SkPicture(SkScalar width, SkScalar height, SkRecord*, SkBBoxHierarchy*);
// Return as a new SkPicture that's backed by SkRecord.
static SkPicture* Forwardport(const SkPicture&);
SkPictureRecorder();
~SkPictureRecorder();
+#ifdef SK_LEGACY_PICTURE_SIZE_API
+ SkCanvas* beginRecording(int width, int height,
+ SkBBHFactory* bbhFactory = NULL,
+ uint32_t recordFlags = 0) {
+ return this->beginRecording(SkIntToScalar(width), SkIntToScalar(height),
+ bbhFactory, recordFlags);
+ }
+#endif
+
/** Returns the canvas that records the drawing commands.
- @param width the base width for the picture, as if the recording
- canvas' bitmap had this width.
- @param height the base width for the picture, as if the recording
- canvas' bitmap had this height.
+ @param width the width of the cull rect used when recording this picture.
+ @param height the height of the cull rect used when recording this picture.
@param bbhFactory factory to create desired acceleration structure
@param recordFlags optional flags that control recording.
@return the canvas.
*/
- SkCanvas* beginRecording(int width, int height,
+ SkCanvas* beginRecording(SkScalar width, SkScalar height,
SkBBHFactory* bbhFactory = NULL,
uint32_t recordFlags = 0);
// then we use EXPERIMENTAL_beginRecording().
// Old slower backend.
- SkCanvas* DEPRECATED_beginRecording(int width, int height,
+ SkCanvas* DEPRECATED_beginRecording(SkScalar width, SkScalar height,
SkBBHFactory* bbhFactory = NULL,
uint32_t recordFlags = 0);
// New faster backend.
- SkCanvas* EXPERIMENTAL_beginRecording(int width, int height,
+ SkCanvas* EXPERIMENTAL_beginRecording(SkScalar width, SkScalar height,
SkBBHFactory* bbhFactory = NULL);
/** Returns the recording canvas if one is active, or NULL if recording is
friend class SkPictureRecorderReplayTester; // for unit testing
void partialReplay(SkCanvas* canvas) const;
- int fWidth;
- int fHeight;
-
+ SkScalar fCullWidth;
+ SkScalar fCullHeight;
SkAutoTUnref<SkBBoxHierarchy> fBBH;
// One of these two canvases will be non-NULL.
{
SkRTreeFactory factory;
SkPictureRecorder recorder;
- SkCanvas* recordingCanvas = recorder.beginRecording(kBitmapSize, kBitmapSize, &factory, 0);
+ SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(kBitmapSize),
+ SkIntToScalar(kBitmapSize),
+ &factory, 0);
drawSomething(recordingCanvas);
SkAutoTUnref<SkPicture> pict(recorder.endRecording());
filter = SkPictureImageFilter::Create(pict.get(), make_rect());
if (SkImageDecoder::DecodeFile(path, &bm)) {
bm.setImmutable();
SkPictureRecorder recorder;
- SkCanvas* can = recorder.beginRecording(bm.width(), bm.height(), NULL, 0);
+ SkCanvas* can = recorder.beginRecording(SkIntToScalar(bm.width()),
+ SkIntToScalar(bm.height()),
+ NULL, 0);
can->drawBitmap(bm, 0, 0, NULL);
pic.reset(recorder.endRecording());
} else {
}
if (false) {
- SkSurface* surf = SkSurface::NewRasterPMColor(pic->width(), pic->height());
+ SkSurface* surf = SkSurface::NewRasterPMColor(SkScalarCeilToInt(pic->cullRect().width()),
+ SkScalarCeilToInt(pic->cullRect().height()));
surf->getCanvas()->drawPicture(pic);
surf->unref();
}
if (false) { // re-record
SkPictureRecorder recorder;
- pic->draw(recorder.beginRecording(pic->width(), pic->height(), NULL, 0));
+ pic->draw(recorder.beginRecording(pic->cullRect().width(),
+ pic->cullRect().height(),
+ NULL, 0));
SkAutoTUnref<SkPicture> p2(recorder.endRecording());
SkString path2(path);
}
SkPictureRecorder recorder;
- pic->draw(recorder.beginRecording(pic->width(), pic->height(), factory.get(), 0));
+ pic->draw(recorder.beginRecording(pic->cullRect().width(),
+ pic->cullRect().height(),
+ factory.get(), 0));
return recorder.endRecording();
}
void SkBBoxRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
const SkPaint* paint) {
- SkRect bounds = SkRect::MakeWH(SkIntToScalar(picture->width()),
- SkIntToScalar(picture->height()));
+ SkRect bounds = picture->cullRect();
// todo: wonder if we should allow passing an optional matrix to transformBounds so we don't
// end up transforming the rect twice.
if (matrix) {
}
}
- SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->width(), picture->height());
+ SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect());
picture->draw(this);
}
///////////////////////////////////////////////////////////////////////////////
SkAutoCanvasMatrixPaint::SkAutoCanvasMatrixPaint(SkCanvas* canvas, const SkMatrix* matrix,
- const SkPaint* paint, int width, int height)
+ const SkPaint* paint, const SkRect& bounds)
: fCanvas(canvas)
, fSaveCount(canvas->getSaveCount())
{
if (NULL != paint) {
- SkRect bounds = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
+ SkRect newBounds = bounds;
if (matrix) {
- matrix->mapRect(&bounds);
+ matrix->mapRect(&newBounds);
}
- canvas->saveLayer(&bounds, paint);
+ canvas->saveLayer(&newBounds, paint);
} else if (NULL != matrix) {
canvas->save();
}
class SkAutoCanvasMatrixPaint : SkNoncopyable {
public:
- SkAutoCanvasMatrixPaint(SkCanvas*, const SkMatrix*, const SkPaint*, int width, int height);
+ SkAutoCanvasMatrixPaint(SkCanvas*, const SkMatrix*, const SkPaint*, const SkRect& bounds);
~SkAutoCanvasMatrixPaint();
private:
#endif
// fRecord OK
-SkPicture::SkPicture(int width, int height,
+SkPicture::SkPicture(SkScalar width, SkScalar height,
const SkPictureRecord& record,
bool deepCopyOps)
- : fWidth(width)
- , fHeight(height)
+ : fCullWidth(width)
+ , fCullHeight(height)
, fAnalysis() {
this->needsNewGenID();
// Create an SkPictureData-backed SkPicture from an SkRecord.
// This for compatibility with serialization code only. This is not cheap.
-static SkPicture* backport(const SkRecord& src, int width, int height) {
+static SkPicture* backport(const SkRecord& src, const SkRect& cullRect) {
SkPictureRecorder recorder;
SkRecordDraw(src,
- recorder.DEPRECATED_beginRecording(width, height), NULL/*bbh*/, NULL/*callback*/);
+ recorder.DEPRECATED_beginRecording(cullRect.width(), cullRect.height()),
+ NULL/*bbh*/, NULL/*callback*/);
return recorder.endRecording();
}
// If the query contains the whole picture, don't bother with the BBH.
SkRect clipBounds = { 0, 0, 0, 0 };
(void)canvas->getClipBounds(&clipBounds);
- const bool useBBH = !clipBounds.contains(SkRect::MakeWH(this->width(), this->height()));
+ const bool useBBH = !clipBounds.contains(this->cullRect());
if (NULL != fData.get()) {
SkPicturePlayback playback(this);
// Check magic bytes.
SkPictInfo info;
SkASSERT(sizeof(kMagic) == sizeof(info.fMagic));
- if (!stream->read(&info, sizeof(info)) || !IsValidPictInfo(info)) {
+
+ if (!stream->read(&info.fMagic, sizeof(kMagic))) {
+ return false;
+ }
+
+ info.fVersion = stream->readU32();
+
+#ifndef V35_COMPATIBILITY_CODE
+ if (info.fVersion < 35) {
+ info.fCullRect.fLeft = 0;
+ info.fCullRect.fTop = 0;
+ info.fCullRect.fRight = SkIntToScalar(stream->readU32());
+ info.fCullRect.fBottom = SkIntToScalar(stream->readU32());
+ } else {
+#endif
+ info.fCullRect.fLeft = stream->readScalar();
+ info.fCullRect.fTop = stream->readScalar();
+ info.fCullRect.fRight = stream->readScalar();
+ info.fCullRect.fBottom = stream->readScalar();
+#ifndef V35_COMPATIBILITY_CODE
+ }
+#endif
+
+ info.fFlags = stream->readU32();
+
+ if (!IsValidPictInfo(info)) {
return false;
}
}
// fRecord OK
-bool SkPicture::InternalOnly_BufferIsSKP(SkReadBuffer& buffer, SkPictInfo* pInfo) {
+bool SkPicture::InternalOnly_BufferIsSKP(SkReadBuffer* buffer, SkPictInfo* pInfo) {
// Check magic bytes.
SkPictInfo info;
SkASSERT(sizeof(kMagic) == sizeof(info.fMagic));
- if (!buffer.readByteArray(&info, sizeof(info)) || !IsValidPictInfo(info)) {
+
+ if (!buffer->readByteArray(&info.fMagic, sizeof(kMagic))) {
+ return false;
+ }
+
+ info.fVersion = buffer->readUInt();
+
+#ifndef V35_COMPATIBILITY_CODE
+ if (info.fVersion < 35) {
+ info.fCullRect.fLeft = 0;
+ info.fCullRect.fTop = 0;
+ info.fCullRect.fRight = SkIntToScalar(buffer->readUInt());
+ info.fCullRect.fBottom = SkIntToScalar(buffer->readUInt());
+ } else {
+#endif
+ buffer->readRect(&info.fCullRect);
+#ifndef V35_COMPATIBILITY_CODE
+ }
+#endif
+
+ info.fFlags = buffer->readUInt();
+
+ if (!IsValidPictInfo(info)) {
return false;
}
}
// fRecord OK
-SkPicture::SkPicture(SkPictureData* data, int width, int height)
+SkPicture::SkPicture(SkPictureData* data, SkScalar width, SkScalar height)
: fData(data)
- , fWidth(width)
- , fHeight(height)
+ , fCullWidth(width)
+ , fCullHeight(height)
, fAnalysis() {
this->needsNewGenID();
}
SkPicture* SkPicture::Forwardport(const SkPicture& src) {
SkAutoTDelete<SkRecord> record(SkNEW(SkRecord));
- SkRecorder canvas(record.get(), src.width(), src.height());
+ SkRecorder canvas(record.get(), src.cullRect().width(), src.cullRect().height());
src.draw(&canvas);
- return SkNEW_ARGS(SkPicture, (src.width(), src.height(), record.detach(), NULL/*bbh*/));
+ return SkNEW_ARGS(SkPicture, (src.cullRect().width(), src.cullRect().height(),
+ record.detach(), NULL/*bbh*/));
}
// fRecord OK
if (NULL == data) {
return NULL;
}
- const SkPicture src(data, info.fWidth, info.fHeight);
+ const SkPicture src(data, info.fCullRect.width(), info.fCullRect.height());
return Forwardport(src);
}
SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) {
SkPictInfo info;
- if (!InternalOnly_BufferIsSKP(buffer, &info)) {
+ if (!InternalOnly_BufferIsSKP(&buffer, &info)) {
return NULL;
}
if (NULL == data) {
return NULL;
}
- const SkPicture src(data, info.fWidth, info.fHeight);
+ const SkPicture src(data, info.fCullRect.width(), info.fCullRect.height());
return Forwardport(src);
}
// Set picture info after magic bytes in the header
info->fVersion = CURRENT_PICTURE_VERSION;
- info->fWidth = fWidth;
- info->fHeight = fHeight;
+ info->fCullRect = this->cullRect();
info->fFlags = SkPictInfo::kCrossProcess_Flag;
// TODO: remove this flag, since we're always float (now)
info->fFlags |= SkPictInfo::kScalarIsFloat_Flag;
// If we're a new-format picture, backport to old format for serialization.
SkAutoTDelete<SkPicture> oldFormat;
if (NULL == data && NULL != fRecord.get()) {
- oldFormat.reset(backport(*fRecord, fWidth, fHeight));
+ oldFormat.reset(backport(*fRecord, this->cullRect()));
data = oldFormat->fData.get();
SkASSERT(NULL != data);
}
SkPictInfo info;
this->createHeader(&info);
+ SkASSERT(sizeof(SkPictInfo) == 32);
stream->write(&info, sizeof(info));
if (NULL != data) {
// If we're a new-format picture, backport to old format for serialization.
SkAutoTDelete<SkPicture> oldFormat;
if (NULL == data && NULL != fRecord.get()) {
- oldFormat.reset(backport(*fRecord, fWidth, fHeight));
+ oldFormat.reset(backport(*fRecord, this->cullRect()));
data = oldFormat->fData.get();
SkASSERT(NULL != data);
}
SkPictInfo info;
this->createHeader(&info);
- buffer.writeByteArray(&info, sizeof(info));
+ buffer.writeByteArray(&info.fMagic, sizeof(info.fMagic));
+ buffer.writeUInt(info.fVersion);
+ buffer.writeRect(info.fCullRect);
+ buffer.writeUInt(info.fFlags);
if (NULL != data) {
buffer.writeBool(true);
}
// fRecord OK
-SkPicture::SkPicture(int width, int height, SkRecord* record, SkBBoxHierarchy* bbh)
- : fWidth(width)
- , fHeight(height)
+SkPicture::SkPicture(SkScalar width, SkScalar height, SkRecord* record, SkBBoxHierarchy* bbh)
+ : fCullWidth(width)
+ , fCullHeight(height)
, fRecord(record)
, fBBH(SkSafeRef(bbh))
, fAnalysis(*record) {
char fMagic[8];
uint32_t fVersion;
- uint32_t fWidth;
- uint32_t fHeight;
+ SkRect fCullRect;
uint32_t fFlags;
};
SkPictureRecorder::~SkPictureRecorder() {}
-SkCanvas* SkPictureRecorder::beginRecording(int width, int height,
+SkCanvas* SkPictureRecorder::beginRecording(SkScalar width, SkScalar height,
SkBBHFactory* bbhFactory /* = NULL */,
uint32_t recordFlags /* = 0 */) {
#ifdef SK_PICTURE_USE_SK_RECORD
#endif
}
-SkCanvas* SkPictureRecorder::DEPRECATED_beginRecording(int width, int height,
+SkCanvas* SkPictureRecorder::DEPRECATED_beginRecording(SkScalar width, SkScalar height,
SkBBHFactory* bbhFactory /* = NULL */,
uint32_t recordFlags /* = 0 */) {
- fWidth = width;
- fHeight = height;
+ fCullWidth = width;
+ fCullHeight = height;
const SkISize size = SkISize::Make(width, height);
return this->getRecordingCanvas();
}
-SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(int width, int height,
+SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(SkScalar width, SkScalar height,
SkBBHFactory* bbhFactory /* = NULL */) {
- fWidth = width;
- fHeight = height;
+ fCullWidth = width;
+ fCullHeight = height;
if (NULL != bbhFactory) {
fBBH.reset((*bbhFactory)(width, height));
SkPicture* picture = NULL;
if (NULL != fRecord.get()) {
- picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, fRecord.detach(), fBBH.get()));
+ picture = SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight,
+ fRecord.detach(), fBBH.get()));
}
if (NULL != fPictureRecord.get()) {
fPictureRecord->endRecording();
const bool deepCopyOps = false;
- picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, *fPictureRecord.get(), deepCopyOps));
+ picture = SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight,
+ *fPictureRecord.get(), deepCopyOps));
}
return picture;
if (NULL != fPictureRecord.get()) {
const bool deepCopyOps = true;
- SkPicture picture(fWidth, fHeight, *fPictureRecord.get(), deepCopyOps);
+ SkPicture picture(fCullWidth, fCullHeight,
+ *fPictureRecord.get(), deepCopyOps);
picture.draw(canvas);
}
}
const SkMatrix* localMatrix, const SkRect* tile)
: INHERITED(localMatrix)
, fPicture(SkRef(picture))
+ , fTile(NULL != tile ? *tile : picture->cullRect())
, fTmx(tmx)
, fTmy(tmy) {
- fTile = tile ? *tile : SkRect::MakeWH(SkIntToScalar(picture->width()),
- SkIntToScalar(picture->height()));
}
#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
SkPictureShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx, TileMode tmy,
const SkMatrix* localMatrix, const SkRect* tile) {
- if (!picture || 0 == picture->width() || 0 == picture->height()
- || (NULL != tile && tile->isEmpty())) {
+ if (!picture || picture->cullRect().isEmpty() || (NULL != tile && tile->isEmpty())) {
return NULL;
}
return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy, localMatrix, tile));
}
SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatrix* localM) const {
- SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0);
+ SkASSERT(fPicture && !fPicture->cullRect().isEmpty());
SkMatrix m;
m.setConcat(matrix, this->getLocalMatrix());
"clamp", "repeat", "mirror"
};
- str->appendf("PictureShader: [%d:%d] ",
- fPicture ? fPicture->width() : 0,
- fPicture ? fPicture->height() : 0);
+ str->appendf("PictureShader: [%f:%f:%f:%f] ",
+ fPicture ? fPicture->cullRect().fLeft : 0,
+ fPicture ? fPicture->cullRect().fTop : 0,
+ fPicture ? fPicture->cullRect().fRight : 0,
+ fPicture ? fPicture->cullRect().fBottom : 0);
str->appendf("(%s, %s)", gTileModeName[fTmx], gTileModeName[fTmy]);
}
Bounds bounds(const DrawPicture& op) const {
- SkRect dst = SkRect::MakeWH(op.picture->width(), op.picture->height());
+ SkRect dst = op.picture->cullRect();
if (op.matrix) {
op.matrix->mapRect(&dst);
}
#include "SkValidationUtils.h"
SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, uint32_t uniqueID)
- : INHERITED(0, 0, NULL, uniqueID),
- fPicture(picture),
- fCropRect(SkRect::MakeWH(picture ? SkIntToScalar(picture->width()) : 0,
- picture ? SkIntToScalar(picture->height()) : 0)) {
- SkSafeRef(fPicture);
+ : INHERITED(0, 0, NULL, uniqueID)
+ , fPicture(SkSafeRef(picture))
+ , fCropRect(NULL != picture ? picture->cullRect() : SkRect::MakeEmpty()) {
}
SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, const SkRect& cropRect,
uint32_t uniqueID)
- : INHERITED(0, 0, NULL, uniqueID),
- fPicture(picture),
- fCropRect(cropRect) {
- SkSafeRef(fPicture);
+ : INHERITED(0, 0, NULL, uniqueID)
+ , fPicture(SkSafeRef(picture))
+ , fCropRect(cropRect) {
}
SkPictureImageFilter::~SkPictureImageFilter() {
CollectLayers(const SkPicture* pict, GrAccelData* accelData)
: fPictureID(pict->uniqueID())
, fCTM(&SkMatrix::I())
- , fCurrentClipBounds(SkIRect::MakeXYWH(0, 0, pict->width(), pict->height()))
, fSaveLayersInStack(0)
, fAccelData(accelData) {
+ pict->cullRect().roundOut(&fCurrentClipBounds);
+
if (NULL == pict->fRecord.get()) {
return;
}
// GPUOptimize is only intended to be called within the context of SkGpuDevice's
// EXPERIMENTAL_optimize method.
const GrAccelData* GPUOptimize(const SkPicture* pict) {
- if (NULL == pict || 0 == pict->width() || 0 == pict->height()) {
+ if (NULL == pict || pict->cullRect().isEmpty()) {
return NULL;
}
void SkDumpCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
const SkPaint* paint) {
- this->dump(kDrawPicture_Verb, NULL, "drawPicture(%p) %d:%d", picture,
- picture->width(), picture->height());
+ this->dump(kDrawPicture_Verb, NULL, "drawPicture(%p) %f:%f:%f:%f", picture,
+ picture->cullRect().fLeft, picture->cullRect().fTop,
+ picture->cullRect().fRight, picture->cullRect().fBottom);
fNestLevel += 1;
this->INHERITED::onDrawPicture(picture, matrix, paint);
fNestLevel -= 1;
- this->dump(kDrawPicture_Verb, NULL, "endPicture(%p) %d:%d", &picture,
- picture->width(), picture->height());
+ this->dump(kDrawPicture_Verb, NULL, "endPicture(%p) %f:%f:%f:%f", &picture,
+ picture->cullRect().fLeft, picture->cullRect().fTop,
+ picture->cullRect().fRight, picture->cullRect().fBottom);
}
void SkDumpCanvas::drawVertices(VertexMode vmode, int vertexCount,
void SkPictureUtils::GatherPixelRefsAndRects(SkPicture* pict,
SkPictureUtils::SkPixelRefContainer* prCont) {
- if (0 == pict->width() || 0 == pict->height()) {
+ if (pict->cullRect().isEmpty()) {
return ;
}
- SkGatherPixelRefsAndRectsDevice device(pict->width(), pict->height(), prCont);
+ SkGatherPixelRefsAndRectsDevice device(SkScalarCeilToInt(pict->cullRect().width()),
+ SkScalarCeilToInt(pict->cullRect().height()),
+ prCont);
SkNoSaveLayerCanvas canvas(&device);
- canvas.clipRect(SkRect::MakeWH(SkIntToScalar(pict->width()),
- SkIntToScalar(pict->height())),
- SkRegion::kIntersect_Op, false);
+ canvas.clipRect(pict->cullRect(), SkRegion::kIntersect_Op, false);
canvas.drawPicture(pict);
}
}
// this test also handles if either area or pict's width/height are empty
- if (!SkRect::Intersects(area,
- SkRect::MakeWH(SkIntToScalar(pict->width()),
- SkIntToScalar(pict->height())))) {
+ if (!SkRect::Intersects(area, pict->cullRect())) {
return NULL;
}
SkTDArray<SkPixelRef*> array;
PixelRefSet prset(&array);
- GatherPixelRefDevice device(pict->width(), pict->height(), &prset);
+ GatherPixelRefDevice device(SkScalarCeilToInt(pict->cullRect().width()),
+ SkScalarCeilToInt(pict->cullRect().height()),
+ &prset);
SkNoSaveLayerCanvas canvas(&device);
canvas.clipRect(area, SkRegion::kIntersect_Op, false);
#include "SkDevice.h"
#include "SkXfermode.h"
-SkDebugCanvas::SkDebugCanvas(int width, int height)
- : INHERITED(width, height)
+SkDebugCanvas::SkDebugCanvas(int windowWidth, int windowHeight)
+ : INHERITED(windowWidth, windowHeight)
, fPicture(NULL)
- , fWidth(width)
- , fHeight(height)
+ , fWindowSize(SkISize::Make(windowWidth, windowHeight))
, fFilter(false)
, fMegaVizMode(false)
, fIndex(0)
SkCanvas canvas(bitmap);
canvas.translate(SkIntToScalar(-x), SkIntToScalar(-y));
- applyUserTransform(&canvas);
+ this->applyUserTransform(&canvas);
int layer = 0;
SkColor prev = bitmap.getColor(0,0);
}
canvas->clear(SK_ColorTRANSPARENT);
canvas->resetMatrix();
- SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth),
- SkIntToScalar(fHeight));
- canvas->clipRect(rect, SkRegion::kReplace_Op );
- applyUserTransform(canvas);
+ SkRect rect = SkRect::MakeWH(SkIntToScalar(fWindowSize.fWidth),
+ SkIntToScalar(fWindowSize.fHeight));
+ canvas->clipRect(rect, SkRegion::kReplace_Op);
+ this->applyUserTransform(canvas);
fOutstandingSaveCount = 0;
}
for (; i <= index; i++) {
if (i == index && fFilter) {
- SkPaint p;
- p.setColor(0xAAFFFFFF);
- canvas->save();
- canvas->resetMatrix();
- SkRect mask;
- mask.set(SkIntToScalar(0), SkIntToScalar(0),
- SkIntToScalar(fWidth), SkIntToScalar(fHeight));
- canvas->clipRect(mask, SkRegion::kReplace_Op, false);
- canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0),
- SkIntToScalar(fWidth), SkIntToScalar(fHeight), p);
- canvas->restore();
+ canvas->clear(0xAAFFFFFF);
}
if (fCommandVector[i]->isVisible()) {
}
if (fMegaVizMode) {
- SkRect r = SkRect::MakeWH(SkIntToScalar(fWidth), SkIntToScalar(fHeight));
+ SkRect r = SkRect::MakeWH(SkIntToScalar(fWindowSize.fWidth),
+ SkIntToScalar(fWindowSize.fHeight));
r.outset(SK_Scalar1, SK_Scalar1);
canvas->save();
// nuke the CTM
- canvas->setMatrix(SkMatrix::I());
+ canvas->resetMatrix();
// turn off clipping
canvas->clipRect(r, SkRegion::kReplace_Op);
*/
void toggleCommand(int index, bool toggle);
- void setBounds(int width, int height) {
- fWidth = width;
- fHeight = height;
- }
+ void setWindowSize(int width, int height) { fWindowSize.set(width, height); }
void setUserMatrix(SkMatrix matrix) {
fUserMatrix = matrix;
private:
SkTDArray<SkDrawCommand*> fCommandVector;
SkPicture* fPicture;
- int fWidth;
- int fHeight;
+ SkISize fWindowSize;
bool fFilter;
bool fMegaVizMode;
int fIndex;
}
SkString* temp = new SkString;
- temp->appendf("SkPicture: W: %d H: %d", picture->width(), picture->height());
+ temp->appendf("SkPicture: L: %f T: %f R: %f B: %f",
+ picture->cullRect().fLeft, picture->cullRect().fTop,
+ picture->cullRect().fRight, picture->cullRect().fBottom);
fInfo.push(temp);
if (NULL != matrix) {
fInfo.push(SkObjectParser::MatrixToString(*matrix));
canvas->clear(0xFFFFFFFF);
canvas->save();
- SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture->width()),
- SkIntToScalar(fPicture->height()));
- xlate_and_scale_to_bounds(canvas, bounds);
+ xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
canvas->drawPicture(fPicture.get());
skiatest::Reporter*,
CanvasTestStep*) {
SkPictureRecorder recorder;
- SkCanvas* testCanvas = recorder.beginRecording(kWidth, kHeight, NULL, 0);
+ SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntToScalar(kHeight),
+ NULL, 0);
testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1));
testCanvas->clipRect(kTestRect);
testCanvas->drawRect(kTestRect, kTestPaint);
testStep->setAssertMessageFormat(kPictureDrawAssertMessageFormat);
SkPictureRecorder referenceRecorder;
SkCanvas* referenceCanvas =
- referenceRecorder.DEPRECATED_beginRecording(kWidth, kHeight, NULL, recordFlags);
+ referenceRecorder.DEPRECATED_beginRecording(SkIntToScalar(kWidth),
+ SkIntToScalar(kHeight),
+ NULL, recordFlags);
testStep->draw(referenceCanvas, reporter);
SkPictureRecorder testRecorder;
SkCanvas* testCanvas =
- testRecorder.DEPRECATED_beginRecording(kWidth, kHeight, NULL, recordFlags);
+ testRecorder.DEPRECATED_beginRecording(SkIntToScalar(kWidth),
+ SkIntToScalar(kHeight),
+ NULL, recordFlags);
testStep->draw(testCanvas, reporter);
testStep->setAssertMessageFormat(kPictureSecondDrawAssertMessageFormat);
testStep->draw(testCanvas, reporter);
}
}
-static void drawSaveLayerPicture(int width, int height, int tileSize, SkBBHFactory* factory, SkBitmap* result) {
+static void draw_saveLayer_picture(int width, int height, int tileSize,
+ SkBBHFactory* factory, SkBitmap* result) {
SkMatrix matrix;
matrix.setTranslate(SkIntToScalar(50), 0);
paint.setImageFilter(imageFilter.get());
SkPictureRecorder recorder;
SkRect bounds = SkRect::Make(SkIRect::MakeXYWH(0, 0, 50, 50));
- SkCanvas* recordingCanvas = recorder.beginRecording(width, height, factory, 0);
+ SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(width),
+ SkIntToScalar(height),
+ factory, 0);
recordingCanvas->translate(-55, 0);
recordingCanvas->saveLayer(&bounds, &paint);
recordingCanvas->restore();
SkBitmap result1, result2;
SkRTreeFactory factory;
- drawSaveLayerPicture(width, height, tileSize, &factory, &result1);
- drawSaveLayerPicture(width, height, tileSize, NULL, &result2);
+ draw_saveLayer_picture(width, height, tileSize, &factory, &result1);
+ draw_saveLayer_picture(width, height, tileSize, NULL, &result2);
for (int y = 0; y < height; y++) {
int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), result1.rowBytes());
REPORTER_ASSERT(reporter, bounds == expectedBounds);
}
-static void drawBlurredRect(SkCanvas* canvas) {
+static void draw_blurred_rect(SkCanvas* canvas) {
SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8), 0));
SkPaint filterPaint;
filterPaint.setColor(SK_ColorWHITE);
canvas->restore();
}
-static void drawPictureClipped(SkCanvas* canvas, const SkRect& clipRect, const SkPicture* picture) {
+static void draw_picture_clipped(SkCanvas* canvas, const SkRect& clipRect, const SkPicture* picture) {
canvas->save();
canvas->clipRect(clipRect);
canvas->drawPicture(picture);
SkPictureRecorder recorder1, recorder2;
// The only difference between these two pictures is that one has RTree aceleration.
- SkCanvas* recordingCanvas1 = recorder1.beginRecording(width, height, NULL, 0);
- SkCanvas* recordingCanvas2 = recorder2.beginRecording(width, height, &factory, 0);
- drawBlurredRect(recordingCanvas1);
- drawBlurredRect(recordingCanvas2);
+ SkCanvas* recordingCanvas1 = recorder1.beginRecording(SkIntToScalar(width),
+ SkIntToScalar(height),
+ NULL, 0);
+ SkCanvas* recordingCanvas2 = recorder2.beginRecording(SkIntToScalar(width),
+ SkIntToScalar(height),
+ &factory, 0);
+ draw_blurred_rect(recordingCanvas1);
+ draw_blurred_rect(recordingCanvas2);
SkAutoTUnref<SkPicture> picture1(recorder1.endRecording());
SkAutoTUnref<SkPicture> picture2(recorder2.endRecording());
for (int y = 0; y < height; y += tileSize) {
for (int x = 0; x < width; x += tileSize) {
SkRect tileRect = SkRect::Make(SkIRect::MakeXYWH(x, y, tileSize, tileSize));
- drawPictureClipped(&canvas1, tileRect, picture1);
- drawPictureClipped(&canvas2, tileRect, picture2);
+ draw_picture_clipped(&canvas1, tileRect, picture1);
+ draw_picture_clipped(&canvas2, tileRect, picture2);
}
}
for (int y = 0; y < height; y++) {
static SkMSec timePict(SkPicture* pic, SkCanvas* canvas) {
canvas->save();
- int pWidth = pic->width();
- int pHeight = pic->height();
- const int maxDimension = 1000;
+ SkScalar pWidth = pic->cullRect().width();
+ SkScalar pHeight = pic->cullRect().height();
+ const SkScalar maxDimension = 1000.0f;
const int slices = 3;
- int xInterval = SkTMax(pWidth - maxDimension, 0) / (slices - 1);
- int yInterval = SkTMax(pHeight - maxDimension, 0) / (slices - 1);
- SkRect rect = {0, 0, SkIntToScalar(SkTMin(maxDimension, pWidth)),
- SkIntToScalar(SkTMin(maxDimension, pHeight))};
+ SkScalar xInterval = SkTMax(pWidth - maxDimension, 0.0f) / (slices - 1);
+ SkScalar yInterval = SkTMax(pHeight - maxDimension, 0.0f) / (slices - 1);
+ SkRect rect = {0, 0, SkTMin(maxDimension, pWidth), SkTMin(maxDimension, pHeight) };
canvas->clipRect(rect);
SkMSec start = SkTime::GetMSecs();
for (int x = 0; x < slices; ++x) {
for (int y = 0; y < slices; ++y) {
pic->draw(canvas);
- canvas->translate(0, SkIntToScalar(yInterval));
+ canvas->translate(0, yInterval);
}
- canvas->translate(SkIntToScalar(xInterval), SkIntToScalar(-yInterval * slices));
+ canvas->translate(xInterval, -yInterval * slices);
}
SkMSec end = SkTime::GetMSecs();
canvas->restore();
SkDebugf("unable to decode %s\n", fFilename);
goto finish;
}
- int width = pic->width();
- int height = pic->height();
+ SkScalar width = pic->cullRect().width();
+ SkScalar height = pic->cullRect().height();
SkBitmap oldBitmap, opBitmap;
fScale = 1;
while (width / fScale > 32767 || height / fScale > 32767) {
++fScale;
}
do {
- int dimX = (width + fScale - 1) / fScale;
- int dimY = (height + fScale - 1) / fScale;
+ int dimX = SkScalarCeilToInt(width / fScale);
+ int dimY = SkScalarCeilToInt(height / fScale);
if (oldBitmap.allocN32Pixels(dimX, dimY) &&
opBitmap.allocN32Pixels(dimX, dimY)) {
break;
SkDebugf("-%d-", fScale);
} while (++fScale < 256);
if (fScale >= 256) {
- SkDebugf("unable to allocate bitmap for %s (w=%d h=%d)\n", fFilename,
+ SkDebugf("unable to allocate bitmap for %s (w=%f h=%f)\n", fFilename,
width, height);
goto finish;
}
{
SkPictureRecorder recorder;
- SkCanvas* c = recorder.beginRecording(kWidth, kHeight);
+ SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), SkIntToScalar(kHeight));
c->saveLayer(NULL, NULL);
c->restore();
{
SkPictureRecorder recorder;
- SkCanvas* c = recorder.beginRecording(kWidth, kHeight);
+ SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth),
+ SkIntToScalar(kHeight));
// 1)
c->saveLayer(NULL, NULL); // layer #0
c->restore();
void check_save_state(skiatest::Reporter* reporter, SkPicture* picture,
unsigned int numSaves, unsigned int numSaveLayers,
unsigned int numRestores) {
- SaveCountingCanvas canvas(picture->width(), picture->height());
+ SaveCountingCanvas canvas(SkScalarCeilToInt(picture->cullRect().width()),
+ SkScalarCeilToInt(picture->cullRect().height()));
picture->draw(&canvas);
static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) {
SkPictureRecorder recorder;
- SkCanvas* canvas = recorder.beginRecording(bitmap.width(), bitmap.height());
+ SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()),
+ SkIntToScalar(bitmap.height()));
canvas->drawBitmap(bitmap, 0, 0);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
static SkBitmap draw_picture(SkPicture& picture) {
SkBitmap bitmap;
- bitmap.allocN32Pixels(picture.width(), picture.height());
+ bitmap.allocN32Pixels(SkScalarCeilToInt(picture.cullRect().width()),
+ SkScalarCeilToInt(picture.cullRect().height()));
SkCanvas canvas(bitmap);
picture.draw(&canvas);
return bitmap;
// Paint some text.
SkPictureRecorder recorder;
SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize);
- SkCanvas* canvas = recorder.beginRecording(canvasRect.width(), canvasRect.height(), NULL, 0);
+ SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width()),
+ SkIntToScalar(canvasRect.height()),
+ NULL, 0);
canvas->drawColor(SK_ColorWHITE);
canvas->drawText("A", 1, 24, 32, paint);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
return success;
}
-static bool drawSomething(SkCanvas* canvas) {
+static bool draw_something(SkCanvas* canvas) {
SkPaint paint;
SkBitmap bitmap;
bool success = make_checkerboard_bitmap(bitmap);
// Test simple SkPicture serialization
{
SkPictureRecorder recorder;
- bool didDraw = drawSomething(recorder.beginRecording(kBitmapSize, kBitmapSize, NULL, 0));
+ bool didDraw = draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize),
+ SkIntToScalar(kBitmapSize),
+ NULL, 0));
REPORTER_ASSERT(reporter, didDraw);
SkAutoTUnref<SkPicture> pict(recorder.endRecording());
int PictureRenderer::getViewWidth() {
SkASSERT(fPicture != NULL);
- int width = SkScalarCeilToInt(fPicture->width() * fScaleFactor);
+ int width = SkScalarCeilToInt(fPicture->cullRect().width() * fScaleFactor);
if (fViewport.width() > 0) {
width = SkMin32(width, fViewport.width());
}
int PictureRenderer::getViewHeight() {
SkASSERT(fPicture != NULL);
- int height = SkScalarCeilToInt(fPicture->height() * fScaleFactor);
+ int height = SkScalarCeilToInt(fPicture->cullRect().height() * fScaleFactor);
if (fViewport.height() > 0) {
height = SkMin32(height, fViewport.height());
}
if (kNone_BBoxHierarchyType != fBBoxHierarchyType && NULL != fPicture) {
SkAutoTDelete<SkBBHFactory> factory(this->getFactory());
SkPictureRecorder recorder;
- SkCanvas* canvas = recorder.beginRecording(fPicture->width(), fPicture->height(),
+ SkCanvas* canvas = recorder.beginRecording(fPicture->cullRect().width(),
+ fPicture->cullRect().height(),
factory.get(),
this->recordFlags());
fPicture->draw(canvas);
bool RecordPictureRenderer::render(SkBitmap** out) {
SkAutoTDelete<SkBBHFactory> factory(this->getFactory());
SkPictureRecorder recorder;
- SkCanvas* canvas = recorder.beginRecording(this->getViewWidth(), this->getViewHeight(),
+ SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(this->getViewWidth()),
+ SkIntToScalar(this->getViewHeight()),
factory.get(),
this->recordFlags());
this->scaleToScaleFactor(canvas);
fCanvas->flush();
if (NULL != out) {
*out = SkNEW(SkBitmap);
- setup_bitmap(*out, fPicture->width(), fPicture->height());
+ setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()),
+ SkScalarCeilToInt(fPicture->cullRect().height()));
fCanvas->readPixels(*out, 0, 0);
}
if (fEnableWrites) {
fCanvas->flush();
if (NULL != out) {
*out = SkNEW(SkBitmap);
- setup_bitmap(*out, fPicture->width(), fPicture->height());
+ setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()),
+ SkScalarCeilToInt(fPicture->cullRect().height()));
fCanvas->readPixels(*out, 0, 0);
}
if (fEnableWrites) {
this->buildBBoxHierarchy();
if (fTileWidthPercentage > 0) {
- fTileWidth = sk_float_ceil2int(float(fTileWidthPercentage * fPicture->width() / 100));
+ fTileWidth = SkScalarCeilToInt(float(fTileWidthPercentage * fPicture->cullRect().width() / 100));
}
if (fTileHeightPercentage > 0) {
- fTileHeight = sk_float_ceil2int(float(fTileHeightPercentage * fPicture->height() / 100));
+ fTileHeight = SkScalarCeilToInt(float(fTileHeightPercentage * fPicture->cullRect().height() / 100));
}
if (fTileMinPowerOf2Width > 0) {
SkBitmap bitmap;
if (out){
*out = SkNEW(SkBitmap);
- setup_bitmap(*out, fPicture->width(), fPicture->height());
+ setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()),
+ SkScalarCeilToInt(fPicture->cullRect().height()));
setup_bitmap(&bitmap, fTileWidth, fTileHeight);
}
bool success = true;
void PlaybackCreationRenderer::setup() {
SkAutoTDelete<SkBBHFactory> factory(this->getFactory());
fRecorder.reset(SkNEW(SkPictureRecorder));
- SkCanvas* canvas = fRecorder->beginRecording(this->getViewWidth(), this->getViewHeight(),
+ SkCanvas* canvas = fRecorder->beginRecording(SkIntToScalar(this->getViewWidth()),
+ SkIntToScalar(this->getViewHeight()),
factory.get(),
this->recordFlags());
this->scaleToScaleFactor(canvas);
#endif
virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE {
- SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture->width()),
- SkIntToScalar(fPicture->height()));
+ SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture->cullRect().width()),
+ SkIntToScalar(fPicture->cullRect().height()));
SkData* data = SkPictureUtils::GatherPixelRefs(fPicture, bounds);
SkSafeUnref(data);
// Because the GPU preprocessing step relies on the in-memory picture
// statistics we need to rerecord the picture here
SkPictureRecorder recorder;
- picture->draw(recorder.beginRecording(picture->width(), picture->height(), NULL, 0));
+ picture->draw(recorder.beginRecording(picture->cullRect().width(),
+ picture->cullRect().height(),
+ NULL, 0));
picture.reset(recorder.endRecording());
}
SkString filename = SkOSPath::Basename(inputPath.c_str());
- gWriter.bench(filename.c_str(), picture->width(), picture->height());
+ gWriter.bench(filename.c_str(),
+ SkScalarCeilToInt(picture->cullRect().width()),
+ SkScalarCeilToInt(picture->cullRect().height()));
benchmark.run(picture);
SkTileGridFactory factory(info);
SkPictureRecorder recorder;
- src.draw(skr ? recorder.EXPERIMENTAL_beginRecording(src.width(), src.height(), &factory)
- : recorder. DEPRECATED_beginRecording(src.width(), src.height(), &factory));
+ src.draw(skr ? recorder.EXPERIMENTAL_beginRecording(src.cullRect().width(),
+ src.cullRect().height(),
+ &factory)
+ : recorder. DEPRECATED_beginRecording(src.cullRect().width(),
+ src.cullRect().height(),
+ &factory));
return recorder.endRecording();
}
static void bench(SkPMColor* scratch, const SkPicture& src, const char* name) {
SkAutoTUnref<const SkPicture> picture(rerecord(src, FLAGS_skr));
- SkAutoTDelete<SkCanvas> canvas(SkCanvas::NewRasterDirectN32(src.width(),
- src.height(),
- scratch,
- src.width() * sizeof(SkPMColor)));
+ SkAutoTDelete<SkCanvas> canvas(
+ SkCanvas::NewRasterDirectN32(SkScalarCeilToInt(src.cullRect().width()),
+ SkScalarCeilToInt(src.cullRect().height()),
+ scratch,
+ SkScalarCeilToInt(src.cullRect().width()) * sizeof(SkPMColor)));
canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLAGS_tile)));
// Draw once to warm any caches. The first sample otherwise can be very noisy.
continue;
}
- if (src->width() * src->height() > kMaxArea) {
- SkDebugf("%s (%dx%d) is larger than hardcoded scratch bitmap (%dpx).\n",
- path.c_str(), src->width(), src->height(), kMaxArea);
+ if (SkScalarCeilToInt(src->cullRect().width()) *
+ SkScalarCeilToInt(src->cullRect().height()) > kMaxArea) {
+ SkDebugf("%s (%f,%f,%f,%f) is larger than hardcoded scratch bitmap (%dpx).\n",
+ path.c_str(),
+ src->cullRect().fLeft, src->cullRect().fTop,
+ src->cullRect().fRight, src->cullRect().fBottom,
+ kMaxArea);
failed = true;
continue;
}
static void rerecord(const SkPicture& src, SkBBHFactory* bbhFactory) {
SkPictureRecorder recorder;
if (FLAGS_skr) {
- src.draw(recorder.EXPERIMENTAL_beginRecording(src.width(), src.height(), bbhFactory));
+ src.draw(recorder.EXPERIMENTAL_beginRecording(src.cullRect().width(),
+ src.cullRect().height(),
+ bbhFactory));
} else {
- src.draw(recorder. DEPRECATED_beginRecording(src.width(), src.height(), bbhFactory));
+ src.draw(recorder. DEPRECATED_beginRecording(src.cullRect().width(),
+ src.cullRect().height(),
+ bbhFactory));
}
SkAutoTUnref<SkPicture> pic(recorder.endRecording());
}
SkDebugf("Could not read %s as an SkPicture.\n", FLAGS_skps[i]);
exit(1);
}
- const int w = src->width(), h = src->height();
+ const int w = SkScalarCeilToInt(src->cullRect().width());
+ const int h = SkScalarCeilToInt(src->cullRect().height());
SkRecord record;
SkRecorder canvas(&record, w, h);
memset(localCount, 0, sizeof(localCount));
- SkDebugCanvas debugCanvas(inPicture->width(), inPicture->height());
- debugCanvas.setBounds(inPicture->width(), inPicture->height());
+ SkDebugCanvas debugCanvas(SkScalarCeilToInt(inPicture->cullRect().width()),
+ SkScalarCeilToInt(inPicture->cullRect().height()));
inPicture->draw(&debugCanvas);
// delete the initial save and restore since replaying the commands will
if (!outFile.isEmpty()) {
SkPictureRecorder recorder;
- SkCanvas* canvas = recorder.beginRecording(inPicture->width(), inPicture->height(), NULL, 0);
+ SkCanvas* canvas = recorder.beginRecording(inPicture->cullRect().width(),
+ inPicture->cullRect().height(),
+ NULL, 0);
debugCanvas.draw(canvas);
SkAutoTUnref<SkPicture> outPicture(recorder.endRecording());
// The SkPicture tracking information is only generated during recording
// an isn't serialized. Replay the picture to regenerated the tracking data.
SkPictureRecorder recorder;
- picture->draw(recorder.beginRecording(picture->width(), picture->height(), NULL, 0));
+ picture->draw(recorder.beginRecording(picture->cullRect().width(),
+ picture->cullRect().height(),
+ NULL, 0));
SkAutoTUnref<SkPicture> recorded(recorder.endRecording());
if (recorded->suitableForGpuRasterization(NULL)) {
SkAutoTUnref<SkPicture> pic(load_picture(path));
if (pic.get()) {
SkAutoTUnref<SkLuaCanvas> canvas(
- new SkLuaCanvas(pic->width(), pic->height(),
+ new SkLuaCanvas(SkScalarCeilToInt(pic->cullRect().width()),
+ SkScalarCeilToInt(pic->cullRect().height()),
L.get(), gAccumulateFunc));
call_canvas(L.get(), canvas.get(), path, gStartCanvasFunc);
SkDebugf("Could not create SkPicture: %s\n", path);
return NULL;
}
- printf("picture size:[%d %d]\n", pic->width(), pic->height());
+ printf("picture cullRect: [%f %f %f %f]\n",
+ pic->cullRect().fLeft, pic->cullRect().fTop,
+ pic->cullRect().fRight, pic->cullRect().fBottom);
return pic;
}
SkPicture::EncodeBitmap encoder) {
SkAutoTUnref<SkDocument> pdfDocument(
SkDocument::CreatePDF(output, NULL, encoder));
- SkCanvas* canvas = pdfDocument->beginPage(
- SkIntToScalar(picture->width()),
- SkIntToScalar(picture->height()));
+ SkCanvas* canvas = pdfDocument->beginPage(picture->cullRect().width(),
+ picture->cullRect().height());
canvas->drawPicture(picture);
canvas->flush();
return pdfDocument->close();
++failures;
continue;
}
- SkDebugf("[%-4i %6i] %-*s", picture->width(), picture->height(),
- maximumPathLength, basename.c_str());
+ SkDebugf("[%f,%f,%f,%f] %-*s",
+ picture->cullRect().fLeft, picture->cullRect().fTop,
+ picture->cullRect().fRight, picture->cullRect().fBottom,
+ maximumPathLength, basename.c_str());
SkAutoTDelete<SkWStream> stream(open_stream(outputDir, files[i]));
if (!stream.get()) {
// Because the GPU preprocessing step relies on the in-memory picture
// statistics we need to rerecord the picture here
SkPictureRecorder recorder;
- picture->draw(recorder.beginRecording(picture->width(), picture->height(), NULL, 0));
+ picture->draw(recorder.beginRecording(picture->cullRect().width(),
+ picture->cullRect().height(),
+ NULL, 0));
picture.reset(recorder.endRecording());
}
while (FLAGS_bench_record) {
SkPictureRecorder recorder;
- picture->draw(recorder.beginRecording(picture->width(), picture->height(), NULL, 0));
+ picture->draw(recorder.beginRecording(picture->cullRect().width(),
+ picture->cullRect().height(),
+ NULL, 0));
SkAutoTUnref<SkPicture> other(recorder.endRecording());
}
- SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(),
+ SkDebugf("drawing... [%f %f %f %f] %s\n",
+ picture->cullRect().fLeft, picture->cullRect().fTop,
+ picture->cullRect().fRight, picture->cullRect().fBottom,
inputPath.c_str());
renderer.init(picture, &writePathString, &mismatchPathString, &inputFilename,
DEFINE_string2(input, i, "", "skp on which to report");
DEFINE_bool2(version, v, true, "version");
-DEFINE_bool2(width, w, true, "width");
-DEFINE_bool2(height, h, true, "height");
+DEFINE_bool2(cullRect, c, true, "cullRect");
DEFINE_bool2(flags, f, true, "flags");
DEFINE_bool2(tags, t, true, "tags");
DEFINE_bool2(quiet, q, false, "quiet");
if (FLAGS_version && !FLAGS_quiet) {
SkDebugf("Version: %d\n", info.fVersion);
}
- if (FLAGS_width && !FLAGS_quiet) {
- SkDebugf("Width: %d\n", info.fWidth);
- }
- if (FLAGS_height && !FLAGS_quiet) {
- SkDebugf("Height: %d\n", info.fHeight);
+ if (FLAGS_cullRect && !FLAGS_quiet) {
+ SkDebugf("Cull Rect: %f,%f,%f,%f\n",
+ info.fCullRect.fLeft, info.fCullRect.fTop,
+ info.fCullRect.fRight, info.fCullRect.fBottom);
}
if (FLAGS_flags && !FLAGS_quiet) {
SkDebugf("Flags: 0x%x\n", info.fFlags);
DEFINE_int32(width, 300, "Width of canvas to create.");
DEFINE_string(writePath, "", "Filepath to write the SKP into.");
-static void skpmaker(int width, int height, int border, SkColor color,
+// Create a 'width' by 'height' skp with a 'border'-wide black border around
+// a 'color' rectangle.
+static void make_skp(SkScalar width, SkScalar height, SkScalar border, SkColor color,
const char *writePath) {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(width, height, NULL, 0);
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
paint.setColor(SK_ColorBLACK);
- canvas->drawRectCoords(0, 0, SkIntToScalar(width), SkIntToScalar(height), paint);
+ SkRect r = SkRect::MakeWH(width, height);
+ canvas->drawRect(r, paint);
paint.setColor(color);
- canvas->drawRectCoords(SkIntToScalar(border), SkIntToScalar(border),
- SkIntToScalar(width - border*2), SkIntToScalar(height - border*2),
- paint);
+ r.inset(border, border);
+ canvas->drawRect(r, paint);
SkAutoTUnref<SkPicture> pict(recorder.endRecording());
SkFILEWStream stream(writePath);
pict->serialize(&stream);
}
SkColor color = SkColorSetRGB(FLAGS_red, FLAGS_green, FLAGS_blue);
- skpmaker(FLAGS_width, FLAGS_height, FLAGS_border, color, FLAGS_writePath[0]);
+ make_skp(SkIntToScalar(FLAGS_width),
+ SkIntToScalar(FLAGS_height),
+ SkIntToScalar(FLAGS_border),
+ color, FLAGS_writePath[0]);
return 0;
}