2012-06-04 12:05:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-01-13 14:53:55 +00:00
|
|
|
|
2012-06-04 12:05:43 +00:00
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "SkDumpCanvas.h"
|
|
|
|
#include "SkView.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkImageDecoder.h"
|
2012-12-10 14:12:55 +00:00
|
|
|
#include "SkOSFile.h"
|
2012-06-04 12:05:43 +00:00
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkPicture.h"
|
Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
#include "SkQuadTreePicture.h"
|
2012-06-04 12:05:43 +00:00
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
2013-12-10 21:51:06 +00:00
|
|
|
#include "SkTileGridPicture.h"
|
2012-06-04 12:05:43 +00:00
|
|
|
#include "SkUtils.h"
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkTime.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
#include "SkXfermode.h"
|
|
|
|
|
|
|
|
#include "SkStream.h"
|
2013-09-17 20:03:43 +00:00
|
|
|
#include "SkSurface.h"
|
2012-06-04 12:05:43 +00:00
|
|
|
#include "SkXMLParser.h"
|
|
|
|
|
|
|
|
class PictFileView : public SampleView {
|
2013-12-10 21:51:06 +00:00
|
|
|
public:
|
|
|
|
PictFileView(const char name[] = NULL)
|
|
|
|
: fFilename(name)
|
|
|
|
, fBBox(kNo_BBoxType)
|
|
|
|
, fTileSize(SkSize::Make(0, 0)) {
|
2013-12-10 22:25:53 +00:00
|
|
|
for (int i = 0; i < kBBoxTypeCount; ++i) {
|
2013-12-10 21:51:06 +00:00
|
|
|
fPictures[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~PictFileView() {
|
2013-12-10 22:25:53 +00:00
|
|
|
for (int i = 0; i < kBBoxTypeCount; ++i) {
|
2013-12-10 21:51:06 +00:00
|
|
|
SkSafeUnref(fPictures[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onTileSizeChanged(const SkSize &tileSize) SK_OVERRIDE {
|
|
|
|
if (tileSize != fTileSize) {
|
|
|
|
fTileSize = tileSize;
|
|
|
|
SkSafeSetNull(fPictures[kTileGrid_BBoxType]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// overrides from SkEventSink
|
|
|
|
virtual bool onQuery(SkEvent* evt) SK_OVERRIDE {
|
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
|
|
|
SkString name("P:");
|
|
|
|
const char* basename = strrchr(fFilename.c_str(), SkPATH_SEPARATOR);
|
|
|
|
name.append(basename ? basename+1: fFilename.c_str());
|
Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
switch (fBBox) {
|
|
|
|
case kNo_BBoxType:
|
|
|
|
// No name appended
|
|
|
|
break;
|
|
|
|
case kRTree_BBoxType:
|
|
|
|
name.append(" <bbox: R>");
|
|
|
|
break;
|
|
|
|
case kQuadTree_BBoxType:
|
|
|
|
name.append(" <bbox: Q>");
|
|
|
|
break;
|
|
|
|
case kTileGrid_BBoxType:
|
|
|
|
name.append(" <bbox: T>");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
break;
|
2013-12-10 21:51:06 +00:00
|
|
|
}
|
|
|
|
SampleCode::TitleR(evt, name.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool onEvent(const SkEvent& evt) SK_OVERRIDE {
|
|
|
|
if (evt.isType("PictFileView::toggleBBox")) {
|
|
|
|
fBBox = (BBoxType)((fBBox + 1) % kBBoxTypeCount);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onEvent(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
|
2014-02-03 19:40:32 +00:00
|
|
|
SkASSERT(static_cast<int>(fBBox) < kBBoxTypeCount);
|
2013-12-10 21:51:06 +00:00
|
|
|
SkPicture** picture = fPictures + fBBox;
|
|
|
|
|
|
|
|
if (!*picture) {
|
|
|
|
*picture = LoadPicture(fFilename.c_str(), fBBox);
|
|
|
|
}
|
|
|
|
if (*picture) {
|
|
|
|
canvas->drawPicture(**picture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum BBoxType {
|
|
|
|
kNo_BBoxType,
|
Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
kQuadTree_BBoxType,
|
2013-12-10 21:51:06 +00:00
|
|
|
kRTree_BBoxType,
|
|
|
|
kTileGrid_BBoxType,
|
|
|
|
|
|
|
|
kLast_BBoxType = kTileGrid_BBoxType
|
|
|
|
};
|
2013-12-10 22:12:40 +00:00
|
|
|
static const int kBBoxTypeCount = kLast_BBoxType + 1;
|
2013-12-10 21:51:06 +00:00
|
|
|
|
2012-06-04 12:05:43 +00:00
|
|
|
SkString fFilename;
|
2013-12-10 21:51:06 +00:00
|
|
|
SkPicture* fPictures[kBBoxTypeCount];
|
|
|
|
BBoxType fBBox;
|
|
|
|
SkSize fTileSize;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2013-12-10 21:51:06 +00:00
|
|
|
SkPicture* LoadPicture(const char path[], BBoxType bbox) {
|
2012-08-03 13:39:57 +00:00
|
|
|
SkPicture* pic = NULL;
|
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
if (SkImageDecoder::DecodeFile(path, &bm)) {
|
|
|
|
bm.setImmutable();
|
|
|
|
pic = SkNEW(SkPicture);
|
|
|
|
SkCanvas* can = pic->beginRecording(bm.width(), bm.height());
|
|
|
|
can->drawBitmap(bm, 0, 0, NULL);
|
|
|
|
pic->endRecording();
|
|
|
|
} else {
|
|
|
|
SkFILEStream stream(path);
|
|
|
|
if (stream.isValid()) {
|
2013-06-28 21:32:00 +00:00
|
|
|
pic = SkPicture::CreateFromStream(&stream);
|
2013-06-25 20:42:37 +00:00
|
|
|
} else {
|
|
|
|
SkDebugf("coun't load picture at \"path\"\n", path);
|
2012-08-03 13:39:57 +00:00
|
|
|
}
|
2012-08-31 17:14:46 +00:00
|
|
|
|
2013-09-17 20:03:43 +00:00
|
|
|
if (false) {
|
|
|
|
SkSurface* surf = SkSurface::NewRasterPMColor(pic->width(), pic->height());
|
|
|
|
surf->getCanvas()->drawPicture(*pic);
|
|
|
|
surf->unref();
|
|
|
|
}
|
2012-08-31 13:32:47 +00:00
|
|
|
if (false) { // re-record
|
|
|
|
SkPicture p2;
|
|
|
|
pic->draw(p2.beginRecording(pic->width(), pic->height()));
|
|
|
|
p2.endRecording();
|
2012-08-31 17:14:46 +00:00
|
|
|
|
2012-08-31 13:32:47 +00:00
|
|
|
SkString path2(path);
|
|
|
|
path2.append(".new.skp");
|
|
|
|
SkFILEWStream writer(path2.c_str());
|
|
|
|
p2.serialize(&writer);
|
|
|
|
}
|
2012-08-03 13:39:57 +00:00
|
|
|
}
|
2012-12-10 14:12:55 +00:00
|
|
|
|
2013-12-10 21:51:06 +00:00
|
|
|
if (!pic) {
|
|
|
|
return NULL;
|
2012-12-10 14:12:55 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2013-12-10 21:51:06 +00:00
|
|
|
SkPicture* bboxPicture = NULL;
|
|
|
|
switch (bbox) {
|
|
|
|
case kNo_BBoxType:
|
|
|
|
// no bbox playback necessary
|
|
|
|
break;
|
|
|
|
case kRTree_BBoxType:
|
|
|
|
bboxPicture = SkNEW(SkPicture);
|
|
|
|
break;
|
Initial QuadTree implementation
In an effort to find a faster bounding box hierarchy than the R-Tree, a QuadTree has been implemented here.
For now, the QuadTree construction is generally faster than the R-Tree and the queries are a bit slower, so overall, SKP local tests showed QuadTree performance similar to the R-Tree performance.
Tests and bench are included in this cl.
At this point, I'd like to be able to commit this in order to more easily use the bots to test multiple configurations and a larger number of SKPs. The R-Tree BBH is still used by default so this change shouldn't affect chromium.
BUG=skia:
R=junov@chromium.org, junov@google.com, senorblanco@google.com, senorblanco@chromium.org, reed@google.com, sugoi@google.com, fmalita@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/131343011
git-svn-id: http://skia.googlecode.com/svn/trunk@13282 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-03 18:08:33 +00:00
|
|
|
case kQuadTree_BBoxType:
|
|
|
|
bboxPicture = SkNEW_ARGS(SkQuadTreePicture,
|
|
|
|
(SkIRect::MakeWH(pic->width(), pic->height())));
|
|
|
|
break;
|
2013-12-10 21:51:06 +00:00
|
|
|
case kTileGrid_BBoxType: {
|
|
|
|
SkASSERT(!fTileSize.isEmpty());
|
|
|
|
SkTileGridPicture::TileGridInfo gridInfo;
|
|
|
|
gridInfo.fMargin = SkISize::Make(0, 0);
|
|
|
|
gridInfo.fOffset = SkIPoint::Make(0, 0);
|
|
|
|
gridInfo.fTileInterval = fTileSize.toRound();
|
|
|
|
bboxPicture = SkNEW_ARGS(SkTileGridPicture, (pic->width(), pic->height(), gridInfo));
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
2012-06-04 12:05:43 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2013-12-10 21:51:06 +00:00
|
|
|
if (bboxPicture) {
|
|
|
|
pic->draw(bboxPicture->beginRecording(pic->width(), pic->height(),
|
|
|
|
SkPicture::kOptimizeForClippedPlayback_RecordingFlag));
|
|
|
|
bboxPicture->endRecording();
|
|
|
|
SkDELETE(pic);
|
|
|
|
return bboxPicture;
|
2012-12-10 14:12:55 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 21:51:06 +00:00
|
|
|
return pic;
|
2012-06-04 12:05:43 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-06-04 12:05:43 +00:00
|
|
|
typedef SampleView INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
SampleView* CreateSamplePictFileView(const char filename[]);
|
|
|
|
SampleView* CreateSamplePictFileView(const char filename[]) {
|
|
|
|
return new PictFileView(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static SkView* MyFactory() { return new PictFileView; }
|
|
|
|
static SkViewRegister reg(MyFactory);
|
|
|
|
#endif
|