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"
|
|
|
|
|
2015-01-28 21:28:53 +00:00
|
|
|
#include "SkGlyphCache.h"
|
|
|
|
|
2012-06-04 12:05:43 +00:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onTileSizeChanged(const SkSize &tileSize) override {
|
2013-12-10 21:51:06 +00:00
|
|
|
if (tileSize != fTileSize) {
|
|
|
|
fTileSize = tileSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// overrides from SkEventSink
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onQuery(SkEvent* evt) override {
|
2013-12-10 21:51:06 +00:00
|
|
|
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;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onEvent(const SkEvent& evt) override {
|
2013-12-10 21:51:06 +00:00
|
|
|
if (evt.isType("PictFileView::toggleBBox")) {
|
|
|
|
fBBox = (BBoxType)((fBBox + 1) % kBBoxTypeCount);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onEvent(evt);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) 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;
|
|
|
|
|
2015-01-28 21:28:53 +00:00
|
|
|
#ifdef SK_GLYPHCACHE_TRACK_HASH_STATS
|
|
|
|
SkGraphics::PurgeFontCache();
|
|
|
|
#endif
|
|
|
|
|
2013-12-10 21:51:06 +00:00
|
|
|
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
|
|
|
}
|
2015-01-28 21:28:53 +00:00
|
|
|
|
|
|
|
#ifdef SK_GLYPHCACHE_TRACK_HASH_STATS
|
|
|
|
SkGlyphCache::Dump();
|
|
|
|
SkDebugf("\n");
|
|
|
|
#endif
|
2013-12-10 21:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum BBoxType {
|
|
|
|
kNo_BBoxType,
|
|
|
|
kRTree_BBoxType,
|
|
|
|
|
2015-01-09 14:41:48 +00:00
|
|
|
kLast_BBoxType = kRTree_BBoxType,
|
2013-12-10 21:51:06 +00:00
|
|
|
};
|
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;
|
2015-01-09 14:41:48 +00:00
|
|
|
SkCanvas* can = recorder.beginRecording(SkIntToScalar(bm.width()),
|
|
|
|
SkIntToScalar(bm.height()),
|
2014-08-29 15:03:56 +00:00
|
|
|
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
|
|
|
|
2012-08-31 13:32:47 +00:00
|
|
|
if (false) { // re-record
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPictureRecorder recorder;
|
2014-09-04 15:42:50 +00:00
|
|
|
pic->playback(recorder.beginRecording(pic->cullRect().width(),
|
2015-01-09 14:41:48 +00:00
|
|
|
pic->cullRect().height(),
|
2014-09-04 15:42:50 +00:00
|
|
|
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;
|
|
|
|
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;
|
2014-09-04 15:42:50 +00:00
|
|
|
pic->playback(recorder.beginRecording(pic->cullRect().width(),
|
2015-01-09 14:41:48 +00:00
|
|
|
pic->cullRect().height(),
|
2014-09-04 15:42:50 +00:00
|
|
|
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
|