aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/gpu/GrContext.h2
-rw-r--r--samplecode/SampleChineseFling.cpp135
-rw-r--r--tools/gpu/GrTest.cpp8
-rw-r--r--tools/viewer/Viewer.cpp4
4 files changed, 138 insertions, 11 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 142140e39d..31ed522edf 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -332,7 +332,7 @@ public:
/** Get pointer to atlas texture for given mask format. Note that this wraps an
actively mutating texture in an SkImage. This could yield unexpected results
if it gets cached or used more generally. */
- sk_sp<SkImage> getFontAtlasImage_ForTesting(GrMaskFormat format);
+ sk_sp<SkImage> getFontAtlasImage_ForTesting(GrMaskFormat format, uint32_t index = 0);
GrAuditTrail* getAuditTrail() { return &fAuditTrail; }
diff --git a/samplecode/SampleChineseFling.cpp b/samplecode/SampleChineseFling.cpp
index 01366316d0..cf14013caa 100644
--- a/samplecode/SampleChineseFling.cpp
+++ b/samplecode/SampleChineseFling.cpp
@@ -15,6 +15,10 @@
#include "SkTypeface.h"
#include "SkTextBlob.h"
+#if SK_SUPPORT_GPU
+#include "GrContext.h"
+#endif
+
static void make_paint(SkPaint* paint, sk_sp<SkTypeface> typeface) {
static const int kTextSize = 56;
@@ -124,7 +128,134 @@ private:
typedef SkView INHERITED;
};
+class ChineseZoomView : public SampleView {
+public:
+ ChineseZoomView() : fBlobs(kNumBlobs), fScale(1.0f) {}
+
+protected:
+ bool onQuery(SkEvent* evt) override {
+ if (SampleCode::TitleQ(*evt)) {
+ SampleCode::TitleR(evt, "chinese-zoom");
+ return true;
+ }
+ SkUnichar uni;
+ if (SampleCode::CharQ(*evt, &uni)) {
+ if ('>' == uni) {
+ fScale += 0.125f;
+ return true;
+ }
+ if ('<' == uni) {
+ fScale -= 0.125f;
+ return true;
+ }
+ }
+ return this->INHERITED::onQuery(evt);
+ }
+
+ void onDrawContent(SkCanvas* canvas) override {
+ if (!fInitialized) {
+ this->init();
+ fInitialized = true;
+ }
+
+ canvas->clear(0xFFDDDDDD);
+
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setColor(0xDE000000);
+ paint.setTypeface(fTypeface);
+ paint.setTextSize(11);
+ paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
+
+#if SK_SUPPORT_GPU
+ GrContext* grContext = canvas->getGrContext();
+ if (grContext) {
+ sk_sp<SkImage> image =
+ grContext->getFontAtlasImage_ForTesting(GrMaskFormat::kA8_GrMaskFormat, 0);
+ canvas->drawImageRect(image,
+ SkRect::MakeXYWH(512.0f, 10.0f, 512.0f, 512.0), &paint);
+ image = grContext->getFontAtlasImage_ForTesting(GrMaskFormat::kA8_GrMaskFormat, 1);
+ canvas->drawImageRect(image,
+ SkRect::MakeXYWH(1024.0f, 10.0f, 512.f, 512.0f), &paint);
+ image = grContext->getFontAtlasImage_ForTesting(GrMaskFormat::kA8_GrMaskFormat, 2);
+ canvas->drawImageRect(image,
+ SkRect::MakeXYWH(512.0f, 522.0f, 512.0f, 512.0f), &paint);
+ image = grContext->getFontAtlasImage_ForTesting(GrMaskFormat::kA8_GrMaskFormat, 3);
+ canvas->drawImageRect(image,
+ SkRect::MakeXYWH(1024.0f, 522.0f, 512.0f, 512.0f), &paint);
+ }
+#endif
+
+ canvas->scale(fScale, fScale);
+
+ // draw a consistent run of the 'words' - one word per line
+ SkScalar y = 0;
+ for (int index = 0; index < kNumBlobs; ++index) {
+ y += -fMetrics.fAscent;
+ canvas->drawTextBlob(fBlobs[index], 0, y, paint);
+
+ y += 3*(fMetrics.fDescent - fMetrics.fAscent + fMetrics.fLeading);
+ }
+ }
+
+private:
+ static constexpr auto kNumBlobs = 8;
+ static constexpr auto kParagraphLength = 175;
+
+ void init() {
+ fTypeface = chinese_typeface();
+
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setColor(0xDE000000);
+ paint.setTypeface(fTypeface);
+ paint.setTextSize(11);
+ paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
+
+ paint.getFontMetrics(&fMetrics);
+
+ SkUnichar glyphs[45];
+ for (int32_t i = 0; i < kNumBlobs; ++i) {
+ SkTextBlobBuilder builder;
+ auto paragraphLength = kParagraphLength;
+ SkScalar y = 0;
+ while (paragraphLength - 45 > 0) {
+ auto currentLineLength = SkTMin(45, paragraphLength - 45);
+ this->createRandomLine(glyphs, currentLineLength);
+
+ sk_tool_utils::add_to_text_blob_w_len(&builder, (const char*) glyphs,
+ currentLineLength*4, paint, 0, y);
+ y += fMetrics.fDescent - fMetrics.fAscent + fMetrics.fLeading;
+ paragraphLength -= 45;
+ }
+ fBlobs.emplace_back(builder.make());
+ }
+
+ fIndex = 0;
+ }
+
+ // Construct a random kWordLength character 'word' drawing from the full Chinese set
+ void createRandomLine(SkUnichar glyphs[45], int lineLength) {
+ for (auto i = 0; i < lineLength; ++i) {
+ glyphs[i] = fRand.nextRangeU(0x4F00, 0x9FA0);
+ }
+ }
+
+ bool fInitialized = false;
+ sk_sp<SkTypeface> fTypeface;
+ SkPaint::FontMetrics fMetrics;
+ SkTArray<sk_sp<SkTextBlob>> fBlobs;
+ SkRandom fRand;
+ SkScalar fScale;
+ int fIndex;
+
+ typedef SkView INHERITED;
+};
+
//////////////////////////////////////////////////////////////////////////////
-static SkView* MyFactory() { return new ChineseFlingView; }
-static SkViewRegister reg(MyFactory);
+static SkView* FlingFactory() { return new ChineseFlingView; }
+static SkViewRegister regFling(FlingFactory);
+
+static SkView* ZoomFactory() { return new ChineseZoomView; }
+static SkViewRegister regZoom(ZoomFactory);
diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
index 25c5a602f9..e76731b59f 100644
--- a/tools/gpu/GrTest.cpp
+++ b/tools/gpu/GrTest.cpp
@@ -147,17 +147,17 @@ void GrContext::printGpuStats() const {
SkDebugf("%s", out.c_str());
}
-sk_sp<SkImage> GrContext::getFontAtlasImage_ForTesting(GrMaskFormat format) {
+sk_sp<SkImage> GrContext::getFontAtlasImage_ForTesting(GrMaskFormat format, uint32_t index) {
GrAtlasGlyphCache* cache = this->contextPriv().getAtlasGlyphCache();
const sk_sp<GrTextureProxy>* proxies = cache->getProxies(format);
- if (!proxies[0]) {
+ if (index >= cache->getAtlasPageCount(format) || !proxies[index]) {
return nullptr;
}
- SkASSERT(proxies[0]->priv().isExact());
+ SkASSERT(proxies[index]->priv().isExact());
sk_sp<SkImage> image(new SkImage_Gpu(this, kNeedNewImageUniqueID, kPremul_SkAlphaType,
- std::move(proxies[0]), nullptr, SkBudgeted::kNo));
+ std::move(proxies[index]), nullptr, SkBudgeted::kNo));
return image;
}
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index f9d1c1b372..8db541c8fd 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -819,12 +819,8 @@ void Viewer::drawSlide(SkCanvas* canvas) {
}
void Viewer::onBackendCreated() {
- this->updateTitle();
- this->updateUIState();
this->setupCurrentSlide();
- fStatsLayer.resetMeasurements();
fWindow->show();
- fWindow->inval();
}
void Viewer::onPaint(SkCanvas* canvas) {