aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/fontcache.cpp
diff options
context:
space:
mode:
authorGravatar Jim Van Verth <jvanverth@google.com>2018-01-25 16:26:25 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-26 13:54:54 +0000
commitfc4f768e5aaf8efdd112f38295a35de83a0f9a55 (patch)
tree64571d9e826dd917299fd4973111732dd76ddcb1 /gm/fontcache.cpp
parentfc807c885b3cce6252cc1d057098d96f8e14eadc (diff)
Use int when possible to calculate atlas indices in shaders.
On certain iOS devices half has a mantissa of only 10 bits, which is not enough to perform the floating point trickery to get the lower bits out of the "texture coordinates". Instead we use int if available, and float if not available. Also re-enables multitexturing for iOS and adds a sample which stresses the issue, and a version of fontcache that tests multitexturing. Bug: skia:7285 Change-Id: Ia541b6a418c1860c941071750ceb26459eb846ea Reviewed-on: https://skia-review.googlesource.com/99800 Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'gm/fontcache.cpp')
-rw-r--r--gm/fontcache.cpp41
1 files changed, 33 insertions, 8 deletions
diff --git a/gm/fontcache.cpp b/gm/fontcache.cpp
index ce919e9df5..f7a1313fb9 100644
--- a/gm/fontcache.cpp
+++ b/gm/fontcache.cpp
@@ -5,6 +5,13 @@
* found in the LICENSE file.
*/
+// GM to stress the GPU font cache
+// It's not necessary to run this with CPU configs
+
+#include "gm.h"
+
+#if SK_SUPPORT_GPU
+
#include "GrContext.h"
#include "GrContextOptions.h"
#include "SkCanvas.h"
@@ -14,8 +21,6 @@
#include "gm.h"
#include "sk_tool_utils.h"
-// GM to stress the GPU font cache
-
static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x,
SkScalar y, const SkPaint& paint) {
canvas->drawString(text, x, y, paint);
@@ -24,16 +29,23 @@ static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x,
class FontCacheGM : public skiagm::GM {
public:
- FontCacheGM() { this->setBGColor(SK_ColorLTGRAY); }
+ FontCacheGM(GrContextOptions::Enable allowMultipleTextures)
+ : fAllowMultipleTextures(allowMultipleTextures) {
+ this->setBGColor(SK_ColorLTGRAY);
+ }
void modifyGrContextOptions(GrContextOptions* options) override {
options->fGlyphCacheTextureMaximumBytes = 0;
- options->fAllowMultipleGlyphCacheTextures = GrContextOptions::Enable::kNo;
+ options->fAllowMultipleGlyphCacheTextures = fAllowMultipleTextures;
}
protected:
SkString onShortName() override {
- return SkString("fontcache");
+ SkString name("fontcache");
+ if (GrContextOptions::Enable::kYes == fAllowMultipleTextures) {
+ name.append("-mt");
+ }
+ return name;
}
SkISize onISize() override { return SkISize::Make(kSize, kSize); }
@@ -49,9 +61,15 @@ protected:
}
void onDraw(SkCanvas* canvas) override {
+ GrRenderTargetContext* renderTargetContext =
+ canvas->internal_private_accessTopLayerRenderTargetContext();
+ if (!renderTargetContext) {
+ skiagm::GM::DrawGpuOnlyMessage(canvas);
+ return;
+ }
+
canvas->clear(SK_ColorLTGRAY);
this->drawText(canvas);
-#if SK_SUPPORT_GPU
// Debugging tool for GPU.
static const bool kShowAtlas = false;
if (kShowAtlas) {
@@ -60,7 +78,6 @@ protected:
canvas->drawImage(img, 0, 0);
}
}
-#endif
}
private:
@@ -83,6 +100,10 @@ private:
SkScalar subpixelY = 0;
bool offsetX = true;
+ if (GrContextOptions::Enable::kYes == fAllowMultipleTextures) {
+ canvas->scale(10, 10);
+ }
+
do {
for (auto s : kSizes) {
auto size = 2 * s;
@@ -109,6 +130,7 @@ private:
static constexpr SkScalar kSize = 1280;
+ GrContextOptions::Enable fAllowMultipleTextures;
sk_sp<SkTypeface> fTypefaces[6];
typedef GM INHERITED;
};
@@ -117,4 +139,7 @@ constexpr SkScalar FontCacheGM::kSize;
//////////////////////////////////////////////////////////////////////////////
-DEF_GM(return new FontCacheGM;)
+DEF_GM(return new FontCacheGM(GrContextOptions::Enable::kNo))
+DEF_GM(return new FontCacheGM(GrContextOptions::Enable::kYes))
+
+#endif