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"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2012-06-04 12:05:43 +00:00
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#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) {
|
2014-06-04 12:40:44 +00:00
|
|
|
canvas->drawPicture(*picture);
|
2013-12-10 21:51:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2014-04-13 19:09:42 +00:00
|
|
|
SkAutoTUnref<SkPicture> pic;
|
2012-08-03 13:39:57 +00:00
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
if (SkImageDecoder::DecodeFile(path, &bm)) {
|
|
|
|
bm.setImmutable();
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPictureRecorder recorder;
|
2014-04-17 23:35:06 +00:00
|
|
|
SkCanvas* can = recorder.beginRecording(bm.width(), bm.height(), NULL, 0);
|
2012-08-03 13:39:57 +00:00
|
|
|
can->drawBitmap(bm, 0, 0, NULL);
|
2014-04-13 19:09:42 +00:00
|
|
|
pic.reset(recorder.endRecording());
|
2012-08-03 13:39:57 +00:00
|
|
|
} else {
|
|
|
|
SkFILEStream stream(path);
|
|
|
|
if (stream.isValid()) {
|
2014-04-13 19:09:42 +00:00
|
|
|
pic.reset(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());
|
2014-06-04 12:40:44 +00:00
|
|
|
surf->getCanvas()->drawPicture(pic);
|
2013-09-17 20:03:43 +00:00
|
|
|
surf->unref();
|
|
|
|
}
|
2012-08-31 13:32:47 +00:00
|
|
|
if (false) { // re-record
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPictureRecorder recorder;
|
2014-04-17 23:35:06 +00:00
|
|
|
pic->draw(recorder.beginRecording(pic->width(), pic->height(), NULL, 0));
|
2014-04-13 19:09:42 +00:00
|
|
|
SkAutoTUnref<SkPicture> p2(recorder.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());
|
2014-04-13 19:09:42 +00:00
|
|
|
p2->serialize(&writer);
|
2012-08-31 13:32:47 +00:00
|
|
|
}
|
2012-08-03 13:39:57 +00:00
|
|
|
}
|
2012-12-10 14:12:55 +00:00
|
|
|
|
2014-04-13 19:09:42 +00:00
|
|
|
if (NULL == pic) {
|
2013-12-10 21:51:06 +00:00
|
|
|
return NULL;
|
2012-12-10 14:12:55 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2014-04-17 23:35:06 +00:00
|
|
|
SkAutoTDelete<SkBBHFactory> factory;
|
2013-12-10 21:51:06 +00:00
|
|
|
switch (bbox) {
|
|
|
|
case kNo_BBoxType:
|
|
|
|
// no bbox playback necessary
|
2014-04-13 19:09:42 +00:00
|
|
|
return pic.detach();
|
2013-12-10 21:51:06 +00:00
|
|
|
case kRTree_BBoxType:
|
2014-04-17 23:35:06 +00:00
|
|
|
factory.reset(SkNEW(SkRTreeFactory));
|
2013-12-10 21:51:06 +00:00
|
|
|
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:
|
2014-04-17 23:35:06 +00:00
|
|
|
factory.reset(SkNEW(SkQuadTreeFactory));
|
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
|
|
|
break;
|
2013-12-10 21:51:06 +00:00
|
|
|
case kTileGrid_BBoxType: {
|
|
|
|
SkASSERT(!fTileSize.isEmpty());
|
2014-04-17 23:35:06 +00:00
|
|
|
SkTileGridFactory::TileGridInfo gridInfo;
|
2013-12-10 21:51:06 +00:00
|
|
|
gridInfo.fMargin = SkISize::Make(0, 0);
|
|
|
|
gridInfo.fOffset = SkIPoint::Make(0, 0);
|
|
|
|
gridInfo.fTileInterval = fTileSize.toRound();
|
2014-04-17 23:35:06 +00:00
|
|
|
factory.reset(SkNEW_ARGS(SkTileGridFactory, (gridInfo)));
|
2014-04-13 19:09:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-12-10 21:51:06 +00:00
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
2012-06-04 12:05:43 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2014-04-17 23:35:06 +00:00
|
|
|
SkPictureRecorder recorder;
|
|
|
|
pic->draw(recorder.beginRecording(pic->width(), pic->height(), factory.get(), 0));
|
2014-04-13 19:09:42 +00:00
|
|
|
return recorder.endRecording();
|
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
|