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
|
|
|
|
2016-03-18 22:48:49 +00:00
|
|
|
#include "DecodeFile.h"
|
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"
|
2012-12-10 14:12:55 +00:00
|
|
|
#include "SkOSFile.h"
|
2016-11-07 23:05:29 +00:00
|
|
|
#include "SkOSPath.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 "SkStream.h"
|
2013-09-17 20:03:43 +00:00
|
|
|
#include "SkSurface.h"
|
2012-06-04 12:05:43 +00:00
|
|
|
|
2015-01-28 21:28:53 +00:00
|
|
|
#include "SkGlyphCache.h"
|
|
|
|
|
2015-08-05 01:46:38 +00:00
|
|
|
#include "SkDrawFilter.h"
|
|
|
|
class SkCounterDrawFilter : public SkDrawFilter {
|
|
|
|
public:
|
|
|
|
SkCounterDrawFilter(int count) : fCount(count) {}
|
|
|
|
|
|
|
|
bool filter(SkPaint*, Type t) override {
|
|
|
|
return --fCount >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fCount;
|
|
|
|
};
|
|
|
|
|
2012-06-04 12:05:43 +00:00
|
|
|
class PictFileView : public SampleView {
|
2013-12-10 21:51:06 +00:00
|
|
|
public:
|
2015-08-27 14:41:13 +00:00
|
|
|
PictFileView(const char name[] = nullptr)
|
2013-12-10 21:51:06 +00:00
|
|
|
: 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) {
|
2015-08-27 14:41:13 +00:00
|
|
|
fPictures[i] = nullptr;
|
2013-12-10 21:51:06 +00:00
|
|
|
}
|
2015-08-05 01:46:38 +00:00
|
|
|
fCount = 0;
|
2013-12-10 21:51:06 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 14:41:46 +00:00
|
|
|
~PictFileView() override {
|
|
|
|
this->freePictures();
|
|
|
|
}
|
|
|
|
|
|
|
|
void freePictures() {
|
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]);
|
2016-08-22 14:41:46 +00:00
|
|
|
fPictures[i] = nullptr;
|
2013-12-10 21:51:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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:");
|
2016-11-07 23:05:29 +00:00
|
|
|
const char* basename = strrchr(fFilename.c_str(), SkOSPath::SEPARATOR);
|
2013-12-10 21:51:06 +00:00
|
|
|
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;
|
|
|
|
}
|
2015-08-05 01:46:38 +00:00
|
|
|
SkUnichar uni;
|
|
|
|
if (SampleCode::CharQ(*evt, &uni)) {
|
|
|
|
switch (uni) {
|
|
|
|
case 'n': fCount += 1; this->inval(nullptr); return true;
|
|
|
|
case 'p': fCount -= 1; this->inval(nullptr); return true;
|
|
|
|
case 's': fCount = 0; this->inval(nullptr); return true;
|
2016-08-22 14:41:46 +00:00
|
|
|
case 'F':
|
|
|
|
fFilterQuality = (kNone_SkFilterQuality == fFilterQuality) ?
|
|
|
|
kHigh_SkFilterQuality : kNone_SkFilterQuality;
|
|
|
|
this->freePictures();
|
|
|
|
this->inval(nullptr);
|
|
|
|
return true;
|
2015-08-05 01:46:38 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
2013-12-10 21:51:06 +00:00
|
|
|
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) {
|
2016-03-18 14:25:55 +00:00
|
|
|
*picture = LoadPicture(fFilename.c_str(), fBBox).release();
|
2013-12-10 21:51:06 +00:00
|
|
|
}
|
|
|
|
if (*picture) {
|
2015-08-05 01:46:38 +00:00
|
|
|
SkCounterDrawFilter filter(fCount);
|
|
|
|
if (fCount > 0) {
|
|
|
|
canvas->setDrawFilter(&filter);
|
|
|
|
}
|
2014-06-04 12:40:44 +00:00
|
|
|
canvas->drawPicture(*picture);
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->setDrawFilter(nullptr);
|
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;
|
2015-08-05 01:46:38 +00:00
|
|
|
int fCount;
|
2016-08-22 14:41:46 +00:00
|
|
|
SkFilterQuality fFilterQuality = kNone_SkFilterQuality;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> LoadPicture(const char path[], BBoxType bbox) {
|
|
|
|
sk_sp<SkPicture> pic;
|
2012-08-03 13:39:57 +00:00
|
|
|
|
2016-08-22 14:41:46 +00:00
|
|
|
if (sk_sp<SkImage> img = decode_file(path)) {
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPictureRecorder recorder;
|
2016-08-22 14:41:46 +00:00
|
|
|
SkCanvas* can = recorder.beginRecording(SkIntToScalar(img->width()),
|
|
|
|
SkIntToScalar(img->height()),
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr, 0);
|
2016-08-22 14:41:46 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setFilterQuality(fFilterQuality);
|
|
|
|
can->drawImage(img, 0, 0, &paint);
|
2016-03-18 14:25:55 +00:00
|
|
|
pic = recorder.finishRecordingAsPicture();
|
2012-08-03 13:39:57 +00:00
|
|
|
} else {
|
|
|
|
SkFILEStream stream(path);
|
|
|
|
if (stream.isValid()) {
|
2016-03-18 14:25:55 +00:00
|
|
|
pic = SkPicture::MakeFromStream(&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(),
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr, 0));
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> p2(recorder.finishRecordingAsPicture());
|
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
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == pic) {
|
|
|
|
return nullptr;
|
2012-12-10 14:12:55 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkBBHFactory> factory;
|
2013-12-10 21:51:06 +00:00
|
|
|
switch (bbox) {
|
|
|
|
case kNo_BBoxType:
|
|
|
|
// no bbox playback necessary
|
2016-03-18 18:07:50 +00:00
|
|
|
return pic;
|
2013-12-10 21:51:06 +00:00
|
|
|
case kRTree_BBoxType:
|
2015-08-26 20:07:48 +00:00
|
|
|
factory.reset(new 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));
|
2016-03-18 14:25:55 +00:00
|
|
|
return recorder.finishRecordingAsPicture();
|
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
|