Remove SkAtlasTextTarget
I can find no references to SkAtlasTextTarget in AOSP or in Chromium.
With google3 CL/314226466 there are no more uses in Google3.
Change-Id: I60b5f06fc17c0e4f8d008886c96645475e3d48e5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293839
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index b0d9425..7a6994c 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -41,9 +41,6 @@
if (!skia_enable_gpu) {
defines += [ "SK_SUPPORT_GPU=0" ]
}
- if (skia_enable_atlas_text) {
- defines += [ "SK_SUPPORT_ATLAS_TEXT=1" ]
- }
if (is_fuchsia) {
defines += fuchsia_defines
}
@@ -639,10 +636,6 @@
cflags_objcc += [ "-fobjc-arc" ]
}
- if (skia_enable_atlas_text) {
- sources += skia_atlas_text_sources
- }
-
if (is_debug) {
public_defines += [ "SK_ENABLE_DUMP_GPU" ]
}
@@ -1157,7 +1150,6 @@
skia_public_includes = [
"client_utils/android",
"include/android",
- "include/atlastext",
"include/c",
"include/codec",
"include/config",
@@ -1353,10 +1345,8 @@
libs = []
if (skia_use_gl) {
- sources += [
- "tools/gpu/atlastext/GLTestAtlasTextRenderer.cpp",
- "tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp",
- ]
+ sources +=
+ [ "tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp" ]
if (is_ios) {
sources += [ "tools/gpu/gl/iOS/CreatePlatformGLTestContext_iOS.mm" ]
libs += [ "OpenGLES.framework" ]
diff --git a/gm/atlastext.cpp b/gm/atlastext.cpp
deleted file mode 100644
index 626b46b..0000000
--- a/gm/atlastext.cpp
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "include/core/SkTypes.h"
-
-#if SK_SUPPORT_ATLAS_TEXT
-
-#include "gm/gm.h"
-#include "include/atlastext/SkAtlasTextContext.h"
-#include "include/atlastext/SkAtlasTextFont.h"
-#include "include/atlastext/SkAtlasTextRenderer.h"
-#include "include/atlastext/SkAtlasTextTarget.h"
-#include "include/core/SkBitmap.h"
-#include "include/core/SkBlendMode.h"
-#include "include/core/SkCanvas.h"
-#include "include/core/SkFont.h"
-#include "include/core/SkFontStyle.h"
-#include "include/core/SkFontTypes.h"
-#include "include/core/SkMatrix.h"
-#include "include/core/SkPaint.h"
-#include "include/core/SkPoint.h"
-#include "include/core/SkRefCnt.h"
-#include "include/core/SkScalar.h"
-#include "include/core/SkSize.h"
-#include "include/core/SkString.h"
-#include "include/core/SkTypeface.h"
-#include "include/utils/SkRandom.h"
-#include "src/utils/SkUTF.h"
-#include "tools/ToolUtils.h"
-#include "tools/gpu/atlastext/GLTestAtlasTextRenderer.h"
-#include "tools/gpu/atlastext/TestAtlasTextRenderer.h"
-
-#include <memory>
-#include <utility>
-
-class GrContext;
-class GrRenderTargetContext;
-
-// GM that draws text using the Atlas Text interface offscreen and then blits that to the canvas.
-
-static SkScalar draw_string(SkAtlasTextTarget* target, const SkString& text, SkScalar x, SkScalar y,
- uint32_t color, sk_sp<SkTypeface> typeface, float size) {
- if (!text.size()) {
- return x;
- }
- auto atlas_font = SkAtlasTextFont::Make(typeface, size);
- int cnt = SkUTF::CountUTF8(text.c_str(), text.size());
- std::unique_ptr<SkGlyphID[]> glyphs(new SkGlyphID[cnt]);
-
- // Using a paint to get the positions for each glyph.
- SkFont font;
- font.setSize(size);
- font.setTypeface(std::move(typeface));
-
- font.textToGlyphs(text.c_str(), text.size(), SkTextEncoding::kUTF8, glyphs.get(), cnt);
-
- std::unique_ptr<SkScalar[]> widths(new SkScalar[cnt]);
- font.getWidths(glyphs.get(), cnt, widths.get());
-
- std::unique_ptr<SkPoint[]> positions(new SkPoint[cnt]);
- positions[0] = {x, y};
- for (int i = 1; i < cnt; ++i) {
- positions[i] = {positions[i - 1].fX + widths[i - 1], y};
- }
-
- target->drawText(glyphs.get(), positions.get(), cnt, color, *atlas_font);
-
- // Return the width of the of draw.
- return positions[cnt - 1].fX + widths[cnt - 1] - positions[0].fX;
-}
-
-class AtlasTextGM : public skiagm::GpuGM {
-public:
- AtlasTextGM() = default;
-
-protected:
- SkString onShortName() override { return SkString("atlastext"); }
-
- SkISize onISize() override { return SkISize::Make(kSize, kSize); }
-
- void onOnceBeforeDraw() override {
- fRenderer = sk_gpu_test::MakeGLTestAtlasTextRenderer();
- if (!fRenderer) {
- return;
- }
- fContext = SkAtlasTextContext::Make(fRenderer);
- auto targetHandle = fRenderer->makeTargetHandle(kSize, kSize);
- if (!targetHandle) {
- return;
- }
-
- fTarget = SkAtlasTextTarget::Make(fContext, kSize, kSize, targetHandle);
-
- fTypefaces[0] = ToolUtils::create_portable_typeface("serif", SkFontStyle::Italic());
- fTypefaces[1] = ToolUtils::create_portable_typeface("sans-serif", SkFontStyle::Italic());
- fTypefaces[2] = ToolUtils::create_portable_typeface("serif", SkFontStyle::Normal());
- fTypefaces[3] = ToolUtils::create_portable_typeface("sans-serif", SkFontStyle::Normal());
- fTypefaces[4] = ToolUtils::create_portable_typeface("serif", SkFontStyle::Bold());
- fTypefaces[5] = ToolUtils::create_portable_typeface("sans-serif", SkFontStyle::Bold());
- }
-
- DrawResult onDraw(GrContext*,
- GrRenderTargetContext*,
- SkCanvas* canvas,
- SkString* errorMsg) override {
- if (!fRenderer) {
- *errorMsg = "No renderer... probably not supported.";
- return DrawResult::kSkip;
- }
- if (!fTarget || !fTarget->handle()) {
- *errorMsg = "No target... we can't continue.";
- return DrawResult::kFail;
- }
- fRenderer->clearTarget(fTarget->handle(), 0xFF808080);
- auto bmp = this->drawText();
- SkPaint paint;
- paint.setBlendMode(SkBlendMode::kSrc);
- canvas->drawBitmap(bmp, 0, 0);
- return DrawResult::kOk;
- }
-
-private:
- SkBitmap drawText() {
- static const int kSizes[] = {8, 13, 18, 23, 30};
-
- static const SkString kTexts[] = {SkString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
- SkString("abcdefghijklmnopqrstuvwxyz"),
- SkString("0123456789"),
- SkString("!@#$%^&*()<>[]{}")};
- SkScalar x = 0;
- SkScalar y = 10;
-
- SkRandom random;
- do {
- for (auto s : kSizes) {
- auto size = 2 * s;
- for (const auto& typeface : fTypefaces) {
- for (const auto& text : kTexts) {
- // Choose a random color but don't let alpha be too small to see.
- uint32_t color = random.nextU() | 0x40000000;
- fTarget->save();
- // Randomly add a little bit of perspective
- if (random.nextBool()) {
- SkMatrix persp;
- persp.reset();
- persp.setPerspY(0.0005f);
- persp.preTranslate(-x, -y + s);
- persp.postTranslate(x, y - s);
- fTarget->concat(persp);
- }
- // Randomly switch between positioning with a matrix vs x, y passed to draw.
- SkScalar drawX = x, drawY = y;
- if (random.nextBool()) {
- fTarget->translate(x, y);
- drawX = drawY = 0;
- }
- x += size +
- draw_string(fTarget.get(), text, drawX, drawY, color, typeface, size);
- x = SkScalarCeilToScalar(x);
- fTarget->restore();
- // Flush periodically to test continued drawing after a flush.
- if ((random.nextU() % 8) == 0) {
- fTarget->flush();
- }
- if (x + 100 > kSize) {
- x = 0;
- y += SkScalarCeilToScalar(size + 3);
- if (y > kSize) {
- fTarget->flush();
- return fRenderer->readTargetHandle(fTarget->handle());
- }
- }
- }
- }
- }
- } while (true);
- }
-
- static constexpr int kSize = 1280;
-
- sk_sp<SkTypeface> fTypefaces[6];
- sk_sp<sk_gpu_test::TestAtlasTextRenderer> fRenderer;
- std::unique_ptr<SkAtlasTextTarget> fTarget;
- sk_sp<SkAtlasTextContext> fContext;
-
- typedef GM INHERITED;
-};
-
-constexpr int AtlasTextGM::kSize;
-
-//////////////////////////////////////////////////////////////////////////////
-
-DEF_GM(return new AtlasTextGM;)
-
-#endif
diff --git a/gn/gm.gni b/gn/gm.gni
index d246eed..77605da 100644
--- a/gn/gm.gni
+++ b/gn/gm.gni
@@ -394,7 +394,4 @@
"$_gm/yuvtorgbeffect.cpp",
]
-gl_gm_sources = [
- "$_gm/atlastext.cpp",
- "$_gm/rectangletexture.cpp",
-]
+gl_gm_sources = [ "$_gm/rectangletexture.cpp" ]
diff --git a/gn/gpu.gni b/gn/gpu.gni
index ab27ce4..fce1847 100644
--- a/gn/gpu.gni
+++ b/gn/gpu.gni
@@ -877,13 +877,3 @@
"$_src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp",
"$_src/gpu/gl/win/GrGLMakeNativeInterface_win.cpp",
]
-
-skia_atlas_text_sources = [
- "$_include/atlastext/SkAtlasTextContext.h",
- "$_include/atlastext/SkAtlasTextFont.h",
- "$_include/atlastext/SkAtlasTextRenderer.h",
- "$_include/atlastext/SkAtlasTextTarget.h",
- "$_src/atlastext/SkAtlasTextContext.cpp",
- "$_src/atlastext/SkAtlasTextTarget.cpp",
- "$_src/atlastext/SkInternalAtlasTextContext.cpp",
-]
diff --git a/gn/skia.gni b/gn/skia.gni
index a649bf2..c72c950 100644
--- a/gn/skia.gni
+++ b/gn/skia.gni
@@ -92,7 +92,6 @@
}
declare_args() {
- skia_enable_atlas_text = is_skia_dev_build && skia_enable_gpu
skia_enable_fontmgr_android = skia_use_expat && skia_use_freetype
skia_enable_fontmgr_custom =
is_linux && skia_use_freetype && !skia_use_fontconfig
diff --git a/include/atlastext/SkAtlasTextContext.h b/include/atlastext/SkAtlasTextContext.h
deleted file mode 100644
index d13ec51..0000000
--- a/include/atlastext/SkAtlasTextContext.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkAtlasTextContext_DEFINED
-#define SkAtlasTextContext_DEFINED
-
-#include "include/core/SkRefCnt.h"
-
-class SkAtlasTextRenderer;
-class SkInternalAtlasTextContext;
-
-SkAtlasTextRenderer* SkGetAtlasTextRendererFromInternalContext(class SkInternalAtlasTextContext&);
-
-/**
- * Class that Atlas Text client uses to register their SkAtlasTextRenderer implementation and
- * to create one or more SkAtlasTextTargets (destination surfaces for text rendering).
- */
-class SK_API SkAtlasTextContext : public SkRefCnt {
-public:
- static sk_sp<SkAtlasTextContext> Make(sk_sp<SkAtlasTextRenderer>);
-
- SkAtlasTextRenderer* renderer() const {
- return SkGetAtlasTextRendererFromInternalContext(*fInternalContext);
- }
-
- SkInternalAtlasTextContext& internal() { return *fInternalContext; }
-
-private:
- SkAtlasTextContext() = delete;
- SkAtlasTextContext(const SkAtlasTextContext&) = delete;
- SkAtlasTextContext& operator=(const SkAtlasTextContext&) = delete;
-
- SkAtlasTextContext(sk_sp<SkAtlasTextRenderer>);
-
- std::unique_ptr<SkInternalAtlasTextContext> fInternalContext;
-};
-
-#endif
diff --git a/include/atlastext/SkAtlasTextFont.h b/include/atlastext/SkAtlasTextFont.h
deleted file mode 100644
index 8bab5bf..0000000
--- a/include/atlastext/SkAtlasTextFont.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkAtlasTextFont_DEFINED
-#define SkAtlasTextFont_DEFINED
-
-#include "include/core/SkFont.h"
-#include "include/core/SkRefCnt.h"
-#include "include/core/SkTypeface.h"
-
-/** Represents a font at a size. TODO: What else do we need here (skewX, scaleX, vertical, ...)? */
-class SK_API SkAtlasTextFont : public SkRefCnt {
-public:
- static sk_sp<SkAtlasTextFont> Make(sk_sp<SkTypeface> typeface, SkScalar size) {
- return sk_sp<SkAtlasTextFont>(new SkAtlasTextFont(std::move(typeface), size));
- }
-
- SkTypeface* typeface() const { return fTypeface.get(); }
-
- sk_sp<SkTypeface> refTypeface() const { return fTypeface; }
-
- SkScalar size() const { return fSize; }
-
- SkFont makeFont() const { return SkFont(fTypeface, fSize); }
-
-private:
- SkAtlasTextFont(sk_sp<SkTypeface> typeface, SkScalar size)
- : fTypeface(std::move(typeface)), fSize(size) {}
-
- sk_sp<SkTypeface> fTypeface;
- SkScalar fSize;
-};
-
-#endif
diff --git a/include/atlastext/SkAtlasTextRenderer.h b/include/atlastext/SkAtlasTextRenderer.h
deleted file mode 100644
index e572bb6..0000000
--- a/include/atlastext/SkAtlasTextRenderer.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "include/core/SkPoint3.h"
-#include "include/core/SkRefCnt.h"
-
-#ifndef SkAtlasTextRenderer_DEFINED
-#define SkAtlasTextRenderer_DEFINED
-
-/**
- * This is the base class for a renderer implemented by the SkAtlasText client. The
- * SkAtlasTextContext issues texture creations, deletions, uploads, and vertex draws to the
- * renderer. The renderer must perform those actions in the order called to correctly render
- * the text drawn to SkAtlasTextTargets.
- */
-class SK_API SkAtlasTextRenderer : public SkRefCnt {
-public:
- enum class AtlasFormat {
- /** Unsigned normalized 8 bit single channel format. */
- kA8
- };
-
- struct SDFVertex {
- /** Position in device space (not normalized). The third component is w (not z). */
- SkPoint3 fPosition;
- /** Color, same value for all four corners of a glyph quad. */
- uint32_t fColor;
- /** Texture coordinate (in texel units, not normalized). */
- int16_t fTextureCoordX;
- int16_t fTextureCoordY;
- };
-
- virtual ~SkAtlasTextRenderer() = default;
-
- /**
- * Create a texture of the provided format with dimensions 'width' x 'height'
- * and return a unique handle.
- */
- virtual void* createTexture(AtlasFormat, int width, int height) = 0;
-
- /**
- * Delete the texture with the passed handle.
- */
- virtual void deleteTexture(void* textureHandle) = 0;
-
- /**
- * Place the pixel data specified by 'data' in the texture with handle
- * 'textureHandle' in the rectangle ['x', 'x' + 'width') x ['y', 'y' + 'height').
- * 'rowBytes' specifies the byte offset between successive rows in 'data' and will always be
- * a multiple of the number of bytes per pixel.
- * The pixel format of data is the same as that of 'textureHandle'.
- */
- virtual void setTextureData(void* textureHandle, const void* data, int x, int y, int width,
- int height, size_t rowBytes) = 0;
-
- /**
- * Draws glyphs using SDFs. The SDF data resides in 'textureHandle'. The array
- * 'vertices' provides interleaved device-space positions, colors, and
- * texture coordinates. There are are 4 * 'quadCnt' entries in 'vertices'.
- */
- virtual void drawSDFGlyphs(void* targetHandle, void* textureHandle, const SDFVertex vertices[],
- int quadCnt) = 0;
-
- /** Called when a SkAtlasTextureTarget is destroyed. */
- virtual void targetDeleted(void* targetHandle) = 0;
-};
-
-#endif
diff --git a/include/atlastext/SkAtlasTextTarget.h b/include/atlastext/SkAtlasTextTarget.h
deleted file mode 100644
index ca8eca7..0000000
--- a/include/atlastext/SkAtlasTextTarget.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkAtlasTextTarget_DEFINED
-#define SkAtlasTextTarget_DEFINED
-
-#include "include/core/SkRefCnt.h"
-#include "include/core/SkScalar.h"
-#include "include/private/SkDeque.h"
-
-#include <memory>
-
-class SkAtlasTextContext;
-class SkAtlasTextFont;
-class SkMatrix;
-struct SkPoint;
-
-/** Represents a client-created renderable surface and is used to draw text into the surface. */
-class SK_API SkAtlasTextTarget {
-public:
- virtual ~SkAtlasTextTarget();
-
- /**
- * Creates a text drawing target. ‘handle’ is used to identify this rendering surface when
- * draws are flushed to the SkAtlasTextContext's SkAtlasTextRenderer.
- */
- static std::unique_ptr<SkAtlasTextTarget> Make(sk_sp<SkAtlasTextContext>,
- int width,
- int height,
- void* handle);
-
- /**
- * Enqueues a text draw in the target. The caller provides an array of glyphs and their
- * positions. The meaning of 'color' here is interpreted by the client's SkAtlasTextRenderer
- * when it actually renders the text.
- */
- virtual void drawText(const SkGlyphID[], const SkPoint[], int glyphCnt, uint32_t color,
- const SkAtlasTextFont&) = 0;
-
- /** Issues all queued text draws to SkAtlasTextRenderer. */
- virtual void flush() = 0;
-
- int width() const { return fWidth; }
- int height() const { return fHeight; }
-
- void* handle() const { return fHandle; }
-
- SkAtlasTextContext* context() const { return fContext.get(); }
-
- /** Saves the current matrix in a stack. Returns the prior depth of the saved matrix stack. */
- int save();
- /** Pops the top matrix on the stack if the stack is not empty. */
- void restore();
- /**
- * Pops the matrix stack until the stack depth is count. Does nothing if the depth is already
- * less than count.
- */
- void restoreToCount(int count);
-
- /** Pre-translates the current CTM. */
- void translate(SkScalar dx, SkScalar dy);
- /** Pre-scales the current CTM. */
- void scale(SkScalar sx, SkScalar sy);
- /** Pre-rotates the current CTM about the origin. */
- void rotate(SkScalar degrees);
- /** Pre-rotates the current CTM about the (px, py). */
- void rotate(SkScalar degrees, SkScalar px, SkScalar py);
- /** Pre-skews the current CTM. */
- void skew(SkScalar sx, SkScalar sy);
- /** Pre-concats the current CTM. */
- void concat(const SkMatrix& matrix);
-
-protected:
- SkAtlasTextTarget(sk_sp<SkAtlasTextContext>, int width, int height, void* handle);
-
- const SkMatrix& ctm() const { return *static_cast<const SkMatrix*>(fMatrixStack.back()); }
-
- void* const fHandle;
- const sk_sp<SkAtlasTextContext> fContext;
- const int fWidth;
- const int fHeight;
-
-private:
- SkDeque fMatrixStack;
- int fSaveCnt;
-
- SkMatrix* accessCTM() const {
- return static_cast<SkMatrix*>(const_cast<void*>(fMatrixStack.back()));
- }
-
- SkAtlasTextTarget() = delete;
- SkAtlasTextTarget(const SkAtlasTextContext&) = delete;
- SkAtlasTextTarget& operator=(const SkAtlasTextContext&) = delete;
-};
-
-#endif
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index 5ab70cd..65a67eb 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -263,12 +263,6 @@
# undef SK_DIRECT3D
#endif
-#if !defined(SK_SUPPORT_ATLAS_TEXT)
-# define SK_SUPPORT_ATLAS_TEXT 0
-#elif SK_SUPPORT_ATLAS_TEXT && !SK_SUPPORT_GPU
-# error "SK_SUPPORT_ATLAS_TEXT requires SK_SUPPORT_GPU"
-#endif
-
#if !defined(SkUNREACHABLE)
# if defined(_MSC_VER) && !defined(__clang__)
# define SkUNREACHABLE __assume(false)
diff --git a/include/gpu/GrContextOptions.h b/include/gpu/GrContextOptions.h
index 5bdf376..1d762bf 100644
--- a/include/gpu/GrContextOptions.h
+++ b/include/gpu/GrContextOptions.h
@@ -263,14 +263,6 @@
GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault;
#endif
-#if SK_SUPPORT_ATLAS_TEXT
- /**
- * Controls whether distance field glyph vertices always have 3 components even when the view
- * matrix does not have perspective.
- */
- Enable fDistanceFieldGlyphVerticesAlwaysHaveW = Enable::kDefault;
-#endif
-
GrDriverBugWorkarounds fDriverBugWorkarounds;
};
#else
diff --git a/platform_tools/android/apps/arcore/CMakeLists.txt b/platform_tools/android/apps/arcore/CMakeLists.txt
index 6bfe1b7..760b7bf 100644
--- a/platform_tools/android/apps/arcore/CMakeLists.txt
+++ b/platform_tools/android/apps/arcore/CMakeLists.txt
@@ -56,7 +56,6 @@
"${SKIA_INCLUDE_PATH}/config"
"${SKIA_INCLUDE_PATH}/gpu"
"${SKIA_INCLUDE_PATH}/android"
- "${SKIA_INCLUDE_PATH}/atlastext"
"${SKIA_INCLUDE_PATH}/c"
"${SKIA_INCLUDE_PATH}/codec"
"${SKIA_INCLUDE_PATH}/effects"
diff --git a/public.bzl b/public.bzl
index b1f8dda..0db0487 100644
--- a/public.bzl
+++ b/public.bzl
@@ -249,9 +249,6 @@
# Only used to regenerate the lexer
"src/sksl/lex/*",
-
- # Atlas text
- "src/atlastext/*",
],
)
@@ -604,7 +601,6 @@
"tests/FontMgrFontConfigTest.cpp", # FontConfig-only.
"tests/SkParagraphTest.cpp", # Skipping tests for now.
"tests/skia_test.cpp", # Old main.
- "tools/gpu/atlastext/*",
"tools/gpu/d3d/*",
"tools/gpu/dawn/*",
"tools/gpu/gl/angle/*",
diff --git a/src/atlastext/SkAtlasTextContext.cpp b/src/atlastext/SkAtlasTextContext.cpp
deleted file mode 100644
index 91e7713..0000000
--- a/src/atlastext/SkAtlasTextContext.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "include/atlastext/SkAtlasTextContext.h"
-#include "include/atlastext/SkAtlasTextRenderer.h"
-#include "src/atlastext/SkInternalAtlasTextContext.h"
-
-sk_sp<SkAtlasTextContext> SkAtlasTextContext::Make(sk_sp<SkAtlasTextRenderer> renderer) {
- return sk_sp<SkAtlasTextContext>(new SkAtlasTextContext(std::move(renderer)));
-}
-
-SkAtlasTextContext::SkAtlasTextContext(sk_sp<SkAtlasTextRenderer> renderer)
- : fInternalContext(SkInternalAtlasTextContext::Make(std::move(renderer))) {}
diff --git a/src/atlastext/SkAtlasTextTarget.cpp b/src/atlastext/SkAtlasTextTarget.cpp
deleted file mode 100644
index 3ae4796..0000000
--- a/src/atlastext/SkAtlasTextTarget.cpp
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "include/atlastext/SkAtlasTextTarget.h"
-
-#include "include/atlastext/SkAtlasTextContext.h"
-#include "include/atlastext/SkAtlasTextFont.h"
-#include "include/atlastext/SkAtlasTextRenderer.h"
-#include "src/atlastext/SkInternalAtlasTextContext.h"
-#include "src/core/SkGlyphRunPainter.h"
-#include "src/core/SkMatrixProvider.h"
-#include "src/gpu/GrClip.h"
-#include "src/gpu/GrContextPriv.h"
-#include "src/gpu/GrDrawingManager.h"
-#include "src/gpu/GrMemoryPool.h"
-#include "src/gpu/GrRecordingContextPriv.h"
-#include "src/gpu/SkGr.h"
-#include "src/gpu/ops/GrAtlasTextOp.h"
-#include "src/gpu/text/GrAtlasManager.h"
-#include "src/gpu/text/GrTextContext.h"
-
-static constexpr int kMaxBatchLookBack = 10;
-
-SkAtlasTextTarget::SkAtlasTextTarget(sk_sp<SkAtlasTextContext> context, int width, int height,
- void* handle)
- : fHandle(handle)
- , fContext(std::move(context))
- , fWidth(width)
- , fHeight(height)
- , fMatrixStack(sizeof(SkMatrix), 4)
- , fSaveCnt(0) {
- fMatrixStack.push_back();
- this->accessCTM()->reset();
-}
-
-SkAtlasTextTarget::~SkAtlasTextTarget() { fContext->renderer()->targetDeleted(fHandle); }
-
-int SkAtlasTextTarget::save() {
- const auto& currCTM = this->ctm();
- *static_cast<SkMatrix*>(fMatrixStack.push_back()) = currCTM;
- return fSaveCnt++;
-}
-
-void SkAtlasTextTarget::restore() {
- if (fSaveCnt) {
- fMatrixStack.pop_back();
- fSaveCnt--;
- }
-}
-
-void SkAtlasTextTarget::restoreToCount(int count) {
- while (fSaveCnt > count) {
- this->restore();
- }
-}
-
-void SkAtlasTextTarget::translate(SkScalar dx, SkScalar dy) {
- this->accessCTM()->preTranslate(dx, dy);
-}
-
-void SkAtlasTextTarget::scale(SkScalar sx, SkScalar sy) { this->accessCTM()->preScale(sx, sy); }
-
-void SkAtlasTextTarget::rotate(SkScalar degrees) { this->accessCTM()->preRotate(degrees); }
-
-void SkAtlasTextTarget::rotate(SkScalar degrees, SkScalar px, SkScalar py) {
- this->accessCTM()->preRotate(degrees, px, py);
-}
-
-void SkAtlasTextTarget::skew(SkScalar sx, SkScalar sy) { this->accessCTM()->preSkew(sx, sy); }
-
-void SkAtlasTextTarget::concat(const SkMatrix& matrix) { this->accessCTM()->preConcat(matrix); }
-
-//////////////////////////////////////////////////////////////////////////////
-
-static const GrColorInfo kColorInfo(GrColorType::kRGBA_8888, kPremul_SkAlphaType, nullptr);
-static const SkSurfaceProps kProps(
- SkSurfaceProps::kUseDistanceFieldFonts_Flag, kUnknown_SkPixelGeometry);
-
-//////////////////////////////////////////////////////////////////////////////
-
-class SkInternalAtlasTextTarget : public GrTextTarget, public SkAtlasTextTarget {
-public:
- SkInternalAtlasTextTarget(sk_sp<SkAtlasTextContext> context, int width, int height,
- void* handle)
- : GrTextTarget(width, height, kColorInfo)
- , SkAtlasTextTarget(std::move(context), width, height, handle)
- , fGlyphPainter(kProps, kColorInfo) {}
-
- ~SkInternalAtlasTextTarget() override {
- this->deleteOps();
- }
-
- /** GrTextTarget overrides */
-
- void addDrawOp(const GrClip*, std::unique_ptr<GrAtlasTextOp> op) override;
-
- void drawShape(const GrClip*,
- const SkPaint&,
- const SkMatrixProvider&,
- const GrStyledShape&) override {
- SkDebugf("Path glyph??");
- }
-
- void makeGrPaint(GrMaskFormat,
- const SkPaint& skPaint,
- const SkMatrixProvider&,
- GrPaint* grPaint) override {
- grPaint->setColor4f(skPaint.getColor4f().premul());
- }
-
- GrContext* getContext() override {
- return this->context()->internal().grContext();
- }
-
- SkGlyphRunListPainter* glyphPainter() override {
- return &fGlyphPainter;
- }
-
- /** SkAtlasTextTarget overrides */
-
- void drawText(const SkGlyphID[], const SkPoint[], int glyphCnt, uint32_t color,
- const SkAtlasTextFont&) override;
- void flush() override;
-
-private:
- void deleteOps();
-
- GrRecordingContext::Arenas arenas() {
- return fContext->internal().grContext()->GrRecordingContext::priv().arenas();
- }
-
- uint32_t fColor;
- using SkAtlasTextTarget::fWidth;
- using SkAtlasTextTarget::fHeight;
- SkTArray<std::unique_ptr<GrAtlasTextOp>, true> fOps;
- SkGlyphRunListPainter fGlyphPainter;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-std::unique_ptr<SkAtlasTextTarget> SkAtlasTextTarget::Make(sk_sp<SkAtlasTextContext> context,
- int width, int height, void* handle) {
- return std::unique_ptr<SkAtlasTextTarget>(
- new SkInternalAtlasTextTarget(std::move(context), width, height, handle));
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-void SkInternalAtlasTextTarget::drawText(const SkGlyphID glyphs[], const SkPoint positions[],
- int glyphCnt, uint32_t color,
- const SkAtlasTextFont& font) {
- SkPaint paint;
- paint.setAntiAlias(true);
-
- // The atlas text context does munging of the paint color. We store the client's color here
- // and then overwrite the generated op's color when addDrawOp() is called.
- fColor = color;
-
- SkSurfaceProps props(SkSurfaceProps::kUseDistanceFieldFonts_Flag, kUnknown_SkPixelGeometry);
- auto grContext = this->context()->internal().grContext();
- auto atlasTextContext = grContext->priv().drawingManager()->getTextContext();
- SkGlyphRunBuilder builder;
- builder.drawGlyphsWithPositions(paint, font.makeFont(),
- SkSpan<const SkGlyphID>{glyphs, SkTo<size_t>(glyphCnt)},
- positions);
- auto glyphRunList = builder.useGlyphRunList();
- if (!glyphRunList.empty()) {
- SkSimpleMatrixProvider matrixProvider(this->ctm());
- atlasTextContext->drawGlyphRunList(grContext, this, nullptr, matrixProvider, props,
- glyphRunList);
- }
-}
-
-void SkInternalAtlasTextTarget::addDrawOp(const GrClip* clip, std::unique_ptr<GrAtlasTextOp> op) {
- SkASSERT(!clip || clip->quickContains(SkRect::MakeIWH(fWidth, fHeight)));
- // The SkAtlasTextRenderer currently only handles grayscale SDF glyphs.
- if (op->maskType() != GrAtlasTextOp::kGrayscaleDistanceField_MaskType) {
- return;
- }
- const GrCaps& caps = *this->context()->internal().grContext()->priv().caps();
- op->finalizeForTextTarget(fColor, caps);
- int n = std::min(kMaxBatchLookBack, fOps.count());
-
- GrRecordingContext::Arenas arenas = this->arenas();
- for (int i = 0; i < n; ++i) {
- GrAtlasTextOp* other = fOps.fromBack(i).get();
- if (other->combineIfPossible(op.get(), &arenas, caps) == GrOp::CombineResult::kMerged) {
- arenas.opMemoryPool()->release(std::move(op));
- return;
- }
- if (GrRectsOverlap(op->bounds(), other->bounds())) {
- break;
- }
- }
- fOps.emplace_back(std::move(op));
-}
-
-void SkInternalAtlasTextTarget::deleteOps() {
- GrOpMemoryPool* pool = this->arenas().opMemoryPool();
- for (int i = 0; i < fOps.count(); ++i) {
- if (fOps[i]) {
- pool->release(std::move(fOps[i]));
- }
- }
- fOps.reset();
-}
-
-void SkInternalAtlasTextTarget::flush() {
- for (int i = 0; i < fOps.count(); ++i) {
- fOps[i]->executeForTextTarget(this);
- }
- this->context()->internal().flush();
- this->deleteOps();
-}
-
-void GrAtlasTextOp::finalizeForTextTarget(uint32_t color, const GrCaps& caps) {
- // TODO4F: Odd handling of client colors among AtlasTextTarget and AtlasTextRenderer
- SkPMColor4f color4f = SkPMColor4f::FromBytes_RGBA(color);
- for (int i = 0; i < fGeoCount; ++i) {
- fGeoData[i].fColor = color4f;
- }
- // Atlas text doesn't use MSAA, so no need to handle mixed samples.
- // Also, no need to support normalized F16 with manual clamp?
- this->finalize(caps, nullptr /* applied clip */, false /* mixed samples */, GrClampType::kAuto);
-}
-
-void GrAtlasTextOp::executeForTextTarget(SkAtlasTextTarget* target) {
- auto& context = target->context()->internal();
- auto atlasManager = context.grContext()->priv().getAtlasManager();
- auto resourceProvider = context.grContext()->priv().resourceProvider();
-
- unsigned int numProxies;
- if (!atlasManager->getViews(kA8_GrMaskFormat, &numProxies)) {
- return;
- }
-
- for (int i = 0; i < fGeoCount; ++i) {
- auto subRun = fGeoData[i].fSubRunPtr;
- subRun->prepareGrGlyphs(context.grContext()->priv().getGrStrikeCache());
- // TODO4F: Preserve float colors
- GrTextBlob::VertexRegenerator regenerator(resourceProvider, subRun, &context, atlasManager);
- int subRunEnd = subRun->glyphCount();
- for (int subRunIndex = 0; subRunIndex < subRunEnd;) {
- auto [ok, glyphsRegenerated] = regenerator.regenerate(subRunIndex, subRunEnd);
- if (!ok) {
- break;
- }
-
- std::unique_ptr<GrTextBlob::Mask3DVertex[][4]> vertexData =
- fGeoData[i].textTargetCreateVertexData(subRunIndex, glyphsRegenerated);
-
- context.recordDraw(vertexData.get(), glyphsRegenerated,
- fGeoData[i].fDrawMatrix, target->handle());
- subRunIndex += glyphsRegenerated;
- if (subRunIndex != subRunEnd) {
- // Make space in the atlas so we can continue generating vertices.
- context.flush();
- }
- }
- }
-}
diff --git a/src/atlastext/SkInternalAtlasTextContext.cpp b/src/atlastext/SkInternalAtlasTextContext.cpp
deleted file mode 100644
index afab657..0000000
--- a/src/atlastext/SkInternalAtlasTextContext.cpp
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "include/atlastext/SkAtlasTextContext.h"
-#include "include/atlastext/SkAtlasTextRenderer.h"
-#include "include/gpu/GrContext.h"
-#include "src/atlastext/SkInternalAtlasTextContext.h"
-#include "src/gpu/GrContextPriv.h"
-#include "src/gpu/text/GrAtlasManager.h"
-#include "src/gpu/text/GrStrikeCache.h"
-
-SkAtlasTextRenderer* SkGetAtlasTextRendererFromInternalContext(
- class SkInternalAtlasTextContext& internal) {
- return internal.renderer();
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-std::unique_ptr<SkInternalAtlasTextContext> SkInternalAtlasTextContext::Make(
- sk_sp<SkAtlasTextRenderer> renderer) {
- return std::unique_ptr<SkInternalAtlasTextContext>(
- new SkInternalAtlasTextContext(std::move(renderer)));
-}
-
-SkInternalAtlasTextContext::SkInternalAtlasTextContext(sk_sp<SkAtlasTextRenderer> renderer)
- : fRenderer(std::move(renderer)) {
- GrContextOptions options;
- options.fAllowMultipleGlyphCacheTextures = GrContextOptions::Enable::kNo;
- options.fMinDistanceFieldFontSize = 0.f;
- options.fGlyphsAsPathsFontSize = SK_ScalarInfinity;
- options.fDistanceFieldGlyphVerticesAlwaysHaveW = GrContextOptions::Enable::kYes;
- fGrContext = GrContext::MakeMock(nullptr, options);
-}
-
-SkInternalAtlasTextContext::~SkInternalAtlasTextContext() {
- if (fDistanceFieldAtlas.fProxy) {
-#ifdef SK_DEBUG
- auto atlasManager = fGrContext->priv().getAtlasManager();
- if (atlasManager) {
- unsigned int numProxies;
- atlasManager->getViews(kA8_GrMaskFormat, &numProxies);
- SkASSERT(1 == numProxies);
- }
-#endif
- fRenderer->deleteTexture(fDistanceFieldAtlas.fTextureHandle);
- }
-}
-
-GrTextBlobCache* SkInternalAtlasTextContext::textBlobCache() {
- return fGrContext->priv().getTextBlobCache();
-}
-
-GrDeferredUploadToken SkInternalAtlasTextContext::addInlineUpload(
- GrDeferredTextureUploadFn&& upload) {
- auto token = fTokenTracker.nextDrawToken();
- fInlineUploads.append(&fArena, InlineUpload{std::move(upload), token});
- return token;
-}
-
-GrDeferredUploadToken SkInternalAtlasTextContext::addASAPUpload(
- GrDeferredTextureUploadFn&& upload) {
- fASAPUploads.append(&fArena, std::move(upload));
- return fTokenTracker.nextTokenToFlush();
-}
-
-void SkInternalAtlasTextContext::recordDraw(const void* srcVertexData, int glyphCnt,
- const SkMatrix& matrix, void* targetHandle) {
- auto vertexDataSize = sizeof(SkAtlasTextRenderer::SDFVertex) * 4 * glyphCnt;
- auto vertexData = fArena.makeArrayDefault<char>(vertexDataSize);
- memcpy(vertexData, srcVertexData, vertexDataSize);
- for (int i = 0; i < 4 * glyphCnt; ++i) {
- auto* vertex = reinterpret_cast<SkAtlasTextRenderer::SDFVertex*>(vertexData) + i;
- // GrTextContext encodes a texture index into the lower bit of each texture coord.
- // This isn't expected by SkAtlasTextRenderer subclasses.
- vertex->fTextureCoordX /= 2;
- vertex->fTextureCoordY /= 2;
- matrix.mapHomogeneousPoints(&vertex->fPosition, &vertex->fPosition, 1);
- }
- fDraws.append(&fArena,
- Draw{glyphCnt, fTokenTracker.issueDrawToken(), targetHandle, vertexData});
-}
-
-void SkInternalAtlasTextContext::flush() {
- auto* atlasManager = fGrContext->priv().getAtlasManager();
- if (!fDistanceFieldAtlas.fProxy) {
- unsigned int numProxies;
- fDistanceFieldAtlas.fProxy =
- atlasManager->getViews(kA8_GrMaskFormat, &numProxies)->asTextureProxy();
- SkASSERT(1 == numProxies);
- fDistanceFieldAtlas.fTextureHandle =
- fRenderer->createTexture(SkAtlasTextRenderer::AtlasFormat::kA8,
- fDistanceFieldAtlas.fProxy->width(),
- fDistanceFieldAtlas.fProxy->height());
- }
- GrDeferredTextureUploadWritePixelsFn writePixelsFn =
- [this](GrTextureProxy* proxy, int left, int top, int width, int height,
- GrColorType colorType, const void* data, size_t rowBytes) -> bool {
- SkASSERT(GrColorType::kAlpha_8 == colorType);
- SkASSERT(proxy == this->fDistanceFieldAtlas.fProxy);
- void* handle = fDistanceFieldAtlas.fTextureHandle;
- this->fRenderer->setTextureData(handle, data, left, top, width, height, rowBytes);
- return true;
- };
- for (const auto& upload : fASAPUploads) {
- upload(writePixelsFn);
- }
- auto inlineUpload = fInlineUploads.begin();
- for (const auto& draw : fDraws) {
- while (inlineUpload != fInlineUploads.end() && inlineUpload->fToken == draw.fToken) {
- inlineUpload->fUpload(writePixelsFn);
- ++inlineUpload;
- }
- auto vertices = reinterpret_cast<const SkAtlasTextRenderer::SDFVertex*>(draw.fVertexData);
- fRenderer->drawSDFGlyphs(draw.fTargetHandle, fDistanceFieldAtlas.fTextureHandle, vertices,
- draw.fGlyphCnt);
- fTokenTracker.flushToken();
- }
- fASAPUploads.reset();
- fInlineUploads.reset();
- fDraws.reset();
- fArena.reset();
-}
diff --git a/src/atlastext/SkInternalAtlasTextContext.h b/src/atlastext/SkInternalAtlasTextContext.h
deleted file mode 100644
index 81b6df0..0000000
--- a/src/atlastext/SkInternalAtlasTextContext.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkInternalAtlasTextContext_DEFINED
-#define SkInternalAtlasTextContext_DEFINED
-
-#include "include/core/SkRefCnt.h"
-#include "src/core/SkArenaAlloc.h"
-#include "src/core/SkArenaAllocList.h"
-#include "src/gpu/GrDeferredUpload.h"
-
-class GrContext;
-class GrStrikeCache;
-class GrTextBlobCache;
-
-class SkAtlasTextRenderer;
-class SkMatrix;
-
-/**
- * The implementation of SkAtlasTextContext. This exists to hide the details from the public class.
- * and to be able to use other private types.
- */
-class SkInternalAtlasTextContext : public GrDeferredUploadTarget {
-public:
- static std::unique_ptr<SkInternalAtlasTextContext> Make(sk_sp<SkAtlasTextRenderer>);
-
- ~SkInternalAtlasTextContext() override;
-
- SkAtlasTextRenderer* renderer() const { return fRenderer.get(); }
-
- GrContext* grContext() const { return fGrContext.get(); }
- GrTextBlobCache* textBlobCache();
-
- const GrTokenTracker* tokenTracker() final { return &fTokenTracker; }
- GrDeferredUploadToken addInlineUpload(GrDeferredTextureUploadFn&&) final;
- GrDeferredUploadToken addASAPUpload(GrDeferredTextureUploadFn&&) final;
-
- void recordDraw(const void* vertexData, int glyphCnt, const SkMatrix&, void* targetHandle);
-
- void flush();
-
-private:
- class DeferredUploader;
- SkInternalAtlasTextContext() = delete;
- SkInternalAtlasTextContext(const SkInternalAtlasTextContext&) = delete;
- SkInternalAtlasTextContext& operator=(const SkInternalAtlasTextContext&) = delete;
-
- SkInternalAtlasTextContext(sk_sp<SkAtlasTextRenderer>);
-
- sk_sp<SkAtlasTextRenderer> fRenderer;
-
- struct AtlasTexture {
- void* fTextureHandle = nullptr;
- GrTextureProxy* fProxy = nullptr;
- };
-
- struct Draw {
- int fGlyphCnt;
- GrDeferredUploadToken fToken;
- void* fTargetHandle;
- const void* fVertexData;
- };
-
- struct InlineUpload {
- GrDeferredTextureUploadFn fUpload;
- GrDeferredUploadToken fToken;
- };
-
- GrTokenTracker fTokenTracker;
- SkArenaAllocList<InlineUpload> fInlineUploads;
- SkArenaAllocList<Draw> fDraws;
- SkArenaAllocList<GrDeferredTextureUploadFn> fASAPUploads;
- SkArenaAlloc fArena{1024 * 40};
- sk_sp<GrContext> fGrContext;
- AtlasTexture fDistanceFieldAtlas;
-};
-
-#endif
diff --git a/src/gpu/GrRecordingContext.cpp b/src/gpu/GrRecordingContext.cpp
index 1743c04..41b0bce 100644
--- a/src/gpu/GrRecordingContext.cpp
+++ b/src/gpu/GrRecordingContext.cpp
@@ -91,11 +91,6 @@
textContextOptions.fMaxDistanceFieldFontSize = this->options().fGlyphsAsPathsFontSize;
textContextOptions.fMinDistanceFieldFontSize = this->options().fMinDistanceFieldFontSize;
textContextOptions.fDistanceFieldVerticesAlwaysHaveW = false;
-#if SK_SUPPORT_ATLAS_TEXT
- if (GrContextOptions::Enable::kYes == this->options().fDistanceFieldGlyphVerticesAlwaysHaveW) {
- textContextOptions.fDistanceFieldVerticesAlwaysHaveW = true;
- }
-#endif
fDrawingManager.reset(new GrDrawingManager(this,
prcOptions,
diff --git a/tools/gpu/atlastext/GLTestAtlasTextRenderer.cpp b/tools/gpu/atlastext/GLTestAtlasTextRenderer.cpp
deleted file mode 100644
index c8dc054..0000000
--- a/tools/gpu/atlastext/GLTestAtlasTextRenderer.cpp
+++ /dev/null
@@ -1,483 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "include/core/SkBitmap.h"
-#include "src/gpu/gl/GrGLDefines.h"
-#include "src/gpu/gl/GrGLUtil.h"
-#include "tools/gpu/atlastext/GLTestAtlasTextRenderer.h"
-#include "tools/gpu/atlastext/TestAtlasTextRenderer.h"
-#include "tools/gpu/gl/GLTestContext.h"
-
-using sk_gpu_test::GLTestContext;
-
-namespace {
-
-class GLTestAtlasTextRenderer : public sk_gpu_test::TestAtlasTextRenderer {
-public:
- GLTestAtlasTextRenderer(std::unique_ptr<GLTestContext>);
-
- void* createTexture(AtlasFormat, int width, int height) override;
-
- void deleteTexture(void* textureHandle) override;
-
- void setTextureData(void* textureHandle, const void* data, int x, int y, int width, int height,
- size_t rowBytes) override;
-
- void drawSDFGlyphs(void* targetHandle, void* textureHandle, const SDFVertex vertices[],
- int quadCnt) override;
-
- void* makeTargetHandle(int width, int height) override;
-
- void targetDeleted(void* targetHandle) override;
-
- SkBitmap readTargetHandle(void* targetHandle) override;
-
- void clearTarget(void* targetHandle, uint32_t color) override;
-
- bool initialized() const { return 0 != fProgram; }
-
-private:
- struct AtlasTexture {
- GrGLuint fID;
- AtlasFormat fFormat;
- int fWidth;
- int fHeight;
- };
-
- struct Target {
- GrGLuint fFBOID;
- GrGLuint fRBID;
- int fWidth;
- int fHeight;
- };
-
- std::unique_ptr<GLTestContext> fContext;
- GrGLuint fProgram = 0;
- GrGLint fDstScaleAndTranslateLocation = 0;
- GrGLint fAtlasInvSizeLocation = 0;
- GrGLint fSamplerLocation = 0;
-};
-
-#define callgl(NAME, ...) fContext->gl()->fFunctions.f##NAME(__VA_ARGS__)
-#define checkgl() \
- do { \
- static constexpr auto line = __LINE__; \
- auto error = fContext->gl()->fFunctions.fGetError(); \
- if (error != GR_GL_NO_ERROR) { \
- SkDebugf("GL ERROR: 0x%x, line %d\n", error, line); \
- } \
- } while (false)
-
-GLTestAtlasTextRenderer::GLTestAtlasTextRenderer(std::unique_ptr<GLTestContext> context)
- : fContext(std::move(context)) {
- auto restore = fContext->makeCurrentAndAutoRestore();
-
- // First check whether the GL is supported so we can avoid spammy failures on systems
- // where the GL simply doesn't work with this class.
- const char* versionStr = reinterpret_cast<const char*>(callgl(GetString, GR_GL_VERSION));
- auto version = GrGLGetVersionFromString(versionStr);
- auto standard = GrGLGetStandardInUseFromString(versionStr);
- switch (standard) {
- case kWebGL_GrGLStandard:
- case kNone_GrGLStandard:
- return;
- case kGLES_GrGLStandard:
- if (version < GR_GL_VER(3, 0)) {
- return;
- }
- break;
- case kGL_GrGLStandard: {
- if (version < GR_GL_VER(4, 3)) {
- return;
- }
- GrGLint profileMask;
- callgl(GetIntegerv, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
- if (profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT) {
- return;
- }
- }
- }
-
- auto vs = callgl(CreateShader, GR_GL_VERTEX_SHADER);
- static constexpr char kGLVersionString[] = "#version 430 compatibility";
- static constexpr char kGLESVersionString[] = "#version 300 es";
- GrGLint lengths[2];
- const GrGLchar* strings[2];
- switch (fContext->gl()->fStandard) {
- case kGL_GrGLStandard:
- strings[0] = kGLVersionString;
- lengths[0] = static_cast<GrGLint>(SK_ARRAY_COUNT(kGLVersionString)) - 1;
- break;
- case kGLES_GrGLStandard:
- strings[0] = kGLESVersionString;
- lengths[0] = static_cast<GrGLint>(SK_ARRAY_COUNT(kGLESVersionString)) - 1;
- break;
- default:
- strings[0] = nullptr;
- lengths[0] = 0;
- break;
- }
-
- static constexpr const char kVS[] = R"(
- uniform vec4 uDstScaleAndTranslate;
- uniform vec2 uAtlasInvSize;
-
- layout (location = 0) in vec3 inPosition;
- layout (location = 1) in vec4 inColor;
- layout (location = 2) in uvec2 inTextureCoords;
-
- out vec2 vTexCoord;
- out vec4 vColor;
- out vec2 vIntTexCoord;
-
- void main() {
- vec2 intCoords;
- // floor(vec2) doesn't seem to work on some ES devices.
- intCoords.x = floor(float(inTextureCoords.x));
- intCoords.y = floor(float(inTextureCoords.y));
- vTexCoord = intCoords * uAtlasInvSize;
- vIntTexCoord = intCoords;
- vColor = inColor;
- gl_Position = vec4(inPosition.x * uDstScaleAndTranslate.x + uDstScaleAndTranslate.y,
- inPosition.y * uDstScaleAndTranslate.z + uDstScaleAndTranslate.w,
- 0.0, inPosition.z);
- }
- )";
- strings[1] = kVS;
- lengths[1] = SK_ARRAY_COUNT(kVS) - 1;
- callgl(ShaderSource, vs, 2, strings, lengths);
- callgl(CompileShader, vs);
- GrGLint compileStatus;
- callgl(GetShaderiv, vs, GR_GL_COMPILE_STATUS, &compileStatus);
- if (compileStatus == GR_GL_FALSE) {
- GrGLint logLength;
- callgl(GetShaderiv, vs, GR_GL_INFO_LOG_LENGTH, &logLength);
- std::unique_ptr<GrGLchar[]> log(new GrGLchar[logLength + 1]);
- log[logLength] = '\0';
- callgl(GetShaderInfoLog, vs, logLength, &logLength, log.get());
- SkDebugf("Vertex Shader failed to compile\n%s", log.get());
- callgl(DeleteShader, vs);
- return;
- }
-
- auto fs = callgl(CreateShader, GR_GL_FRAGMENT_SHADER);
- static constexpr const char kFS[] = R"(
- uniform sampler2D uSampler;
-
- in vec2 vTexCoord;
- in vec4 vColor;
- in vec2 vIntTexCoord;
-
- layout (location = 0) out vec4 outColor;
-
- void main() {
- float sdfValue = texture(uSampler, vTexCoord).r;
- float distance = 7.96875 * (sdfValue - 0.50196078431000002);
- vec2 dist_grad = vec2(dFdx(distance), dFdy(distance));
- vec2 Jdx = dFdx(vIntTexCoord);
- vec2 Jdy = dFdy(vIntTexCoord);
- float dg_len2 = dot(dist_grad, dist_grad);
- if (dg_len2 < 0.0001) {
- dist_grad = vec2(0.7071, 0.7071);
- } else {
- dist_grad = dist_grad * inversesqrt(dg_len2);
- }
- vec2 grad = vec2(dist_grad.x * Jdx.x + dist_grad.y * Jdy.x,
- dist_grad.x * Jdx.y + dist_grad.y * Jdy.y);
- float afwidth = abs(0.65000000000000002 * length(grad));
- float value = smoothstep(-afwidth, afwidth, distance);
- outColor = value * vec4(vColor.rgb * vColor.a, vColor.a);
- }
- )";
- strings[1] = kFS;
- lengths[1] = SK_ARRAY_COUNT(kFS) - 1;
- callgl(ShaderSource, fs, 2, strings, lengths);
- callgl(CompileShader, fs);
- callgl(GetShaderiv, fs, GR_GL_COMPILE_STATUS, &compileStatus);
- if (compileStatus == GR_GL_FALSE) {
- GrGLint logLength;
- callgl(GetShaderiv, fs, GR_GL_INFO_LOG_LENGTH, &logLength);
- std::unique_ptr<GrGLchar[]> log(new GrGLchar[logLength + 1]);
- log[logLength] = '\0';
- callgl(GetShaderInfoLog, fs, logLength, &logLength, log.get());
- SkDebugf("Fragment Shader failed to compile\n%s", log.get());
- callgl(DeleteShader, vs);
- callgl(DeleteShader, fs);
- return;
- }
-
- fProgram = callgl(CreateProgram);
- if (!fProgram) {
- callgl(DeleteShader, vs);
- callgl(DeleteShader, fs);
- return;
- }
-
- callgl(AttachShader, fProgram, vs);
- callgl(AttachShader, fProgram, fs);
- callgl(LinkProgram, fProgram);
- GrGLint linkStatus;
- callgl(GetProgramiv, fProgram, GR_GL_LINK_STATUS, &linkStatus);
- if (linkStatus == GR_GL_FALSE) {
- GrGLint logLength = 0;
- callgl(GetProgramiv, vs, GR_GL_INFO_LOG_LENGTH, &logLength);
- std::unique_ptr<GrGLchar[]> log(new GrGLchar[logLength + 1]);
- log[logLength] = '\0';
- callgl(GetProgramInfoLog, vs, logLength, &logLength, log.get());
- SkDebugf("Program failed to link\n%s", log.get());
- callgl(DeleteShader, vs);
- callgl(DeleteShader, fs);
- callgl(DeleteProgram, fProgram);
- fProgram = 0;
- return;
- }
- fDstScaleAndTranslateLocation = callgl(GetUniformLocation, fProgram, "uDstScaleAndTranslate");
- fAtlasInvSizeLocation = callgl(GetUniformLocation, fProgram, "uAtlasInvSize");
- fSamplerLocation = callgl(GetUniformLocation, fProgram, "uSampler");
- if (fDstScaleAndTranslateLocation < 0 || fAtlasInvSizeLocation < 0 || fSamplerLocation < 0) {
- callgl(DeleteShader, vs);
- callgl(DeleteShader, fs);
- callgl(DeleteProgram, fProgram);
- fProgram = 0;
- }
-
- checkgl();
-}
-
-inline bool atlas_format_to_gl_types(SkAtlasTextRenderer::AtlasFormat format,
- GrGLenum* internalFormat, GrGLenum* externalFormat,
- GrGLenum* type) {
- switch (format) {
- case SkAtlasTextRenderer::AtlasFormat::kA8:
- *internalFormat = GR_GL_R8;
- *externalFormat = GR_GL_RED;
- *type = GR_GL_UNSIGNED_BYTE;
- return true;
- }
- return false;
-}
-
-inline int atlas_format_bytes_per_pixel(SkAtlasTextRenderer::AtlasFormat format) {
- switch (format) {
- case SkAtlasTextRenderer::AtlasFormat::kA8:
- return 1;
- }
- return 0;
-}
-
-void* GLTestAtlasTextRenderer::createTexture(AtlasFormat format, int width, int height) {
- GrGLenum internalFormat;
- GrGLenum externalFormat;
- GrGLenum type;
- if (!atlas_format_to_gl_types(format, &internalFormat, &externalFormat, &type)) {
- return nullptr;
- }
- auto restore = fContext->makeCurrentAndAutoRestore();
-
- GrGLuint id;
- callgl(GenTextures, 1, &id);
- if (!id) {
- return nullptr;
- }
-
- callgl(BindTexture, GR_GL_TEXTURE_2D, id);
- callgl(TexImage2D, GR_GL_TEXTURE_2D, 0, internalFormat, width, height, 0, externalFormat, type,
- nullptr);
- checkgl();
-
- AtlasTexture* atlas = new AtlasTexture;
- atlas->fID = id;
- atlas->fFormat = format;
- atlas->fWidth = width;
- atlas->fHeight = height;
- return atlas;
-}
-
-void GLTestAtlasTextRenderer::deleteTexture(void* textureHandle) {
- auto restore = fContext->makeCurrentAndAutoRestore();
-
- auto* atlasTexture = reinterpret_cast<const AtlasTexture*>(textureHandle);
-
- callgl(DeleteTextures, 1, &atlasTexture->fID);
- checkgl();
-
- delete atlasTexture;
-}
-
-void GLTestAtlasTextRenderer::setTextureData(void* textureHandle, const void* data, int x, int y,
- int width, int height, size_t rowBytes) {
- auto restore = fContext->makeCurrentAndAutoRestore();
-
- auto atlasTexture = reinterpret_cast<const AtlasTexture*>(textureHandle);
-
- GrGLenum internalFormat;
- GrGLenum externalFormat;
- GrGLenum type;
- if (!atlas_format_to_gl_types(atlasTexture->fFormat, &internalFormat, &externalFormat, &type)) {
- return;
- }
- int bpp = atlas_format_bytes_per_pixel(atlasTexture->fFormat);
- GrGLint rowLength = static_cast<GrGLint>(rowBytes / bpp);
- if (static_cast<size_t>(rowLength * bpp) != rowBytes) {
- return;
- }
- callgl(PixelStorei, GR_GL_UNPACK_ALIGNMENT, 1);
- callgl(PixelStorei, GR_GL_UNPACK_ROW_LENGTH, rowLength);
- callgl(BindTexture, GR_GL_TEXTURE_2D, atlasTexture->fID);
- callgl(TexSubImage2D, GR_GL_TEXTURE_2D, 0, x, y, width, height, externalFormat, type, data);
- checkgl();
-}
-
-void GLTestAtlasTextRenderer::drawSDFGlyphs(void* targetHandle, void* textureHandle,
- const SDFVertex vertices[], int quadCnt) {
- auto restore = fContext->makeCurrentAndAutoRestore();
-
- auto target = reinterpret_cast<const Target*>(targetHandle);
- auto atlas = reinterpret_cast<const AtlasTexture*>(textureHandle);
-
- callgl(UseProgram, fProgram);
-
- callgl(ActiveTexture, GR_GL_TEXTURE0);
- callgl(BindTexture, GR_GL_TEXTURE_2D, atlas->fID);
- callgl(TexParameteri, GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FILTER, GR_GL_LINEAR);
- callgl(TexParameteri, GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, GR_GL_LINEAR);
-
- float uniformScaleAndTranslate[4] = {2.f / target->fWidth, -1.f, 2.f / target->fHeight, -1.f};
- callgl(Uniform4fv, fDstScaleAndTranslateLocation, 1, uniformScaleAndTranslate);
- callgl(Uniform2f, fAtlasInvSizeLocation, 1.f / atlas->fWidth, 1.f / atlas->fHeight);
- callgl(Uniform1i, fSamplerLocation, 0);
-
- callgl(BindFramebuffer, GR_GL_FRAMEBUFFER, target->fFBOID);
- callgl(Viewport, 0, 0, target->fWidth, target->fHeight);
-
- callgl(Enable, GR_GL_BLEND);
- callgl(BlendFunc, GR_GL_ONE, GR_GL_ONE_MINUS_SRC_ALPHA);
- callgl(Disable, GR_GL_DEPTH_TEST);
-
- callgl(BindVertexArray, 0);
- callgl(BindBuffer, GR_GL_ARRAY_BUFFER, 0);
- callgl(BindBuffer, GR_GL_ELEMENT_ARRAY_BUFFER, 0);
- callgl(VertexAttribPointer, 0, 3, GR_GL_FLOAT, GR_GL_FALSE, sizeof(SDFVertex), vertices);
- size_t colorOffset = 3 * sizeof(float);
- callgl(VertexAttribPointer, 1, 4, GR_GL_UNSIGNED_BYTE, GR_GL_TRUE, sizeof(SDFVertex),
- reinterpret_cast<const char*>(vertices) + colorOffset);
- size_t texOffset = colorOffset + sizeof(uint32_t);
- callgl(VertexAttribIPointer, 2, 2, GR_GL_UNSIGNED_SHORT, sizeof(SDFVertex),
- reinterpret_cast<const char*>(vertices) + texOffset);
- callgl(EnableVertexAttribArray, 0);
- callgl(EnableVertexAttribArray, 1);
- callgl(EnableVertexAttribArray, 2);
-
- std::unique_ptr<uint16_t[]> indices(new uint16_t[quadCnt * 6]);
- for (int q = 0; q < quadCnt; ++q) {
- indices[q * 6 + 0] = 0 + 4 * q;
- indices[q * 6 + 1] = 1 + 4 * q;
- indices[q * 6 + 2] = 2 + 4 * q;
- indices[q * 6 + 3] = 2 + 4 * q;
- indices[q * 6 + 4] = 1 + 4 * q;
- indices[q * 6 + 5] = 3 + 4 * q;
- }
- callgl(DrawElements, GR_GL_TRIANGLES, 6 * quadCnt, GR_GL_UNSIGNED_SHORT, indices.get());
- checkgl();
-}
-
-void* GLTestAtlasTextRenderer::makeTargetHandle(int width, int height) {
- auto restore = fContext->makeCurrentAndAutoRestore();
-
- GrGLuint fbo;
- callgl(GenFramebuffers, 1, &fbo);
- if (!fbo) {
- return nullptr;
- }
- GrGLuint rb;
- callgl(GenRenderbuffers, 1, &rb);
- if (!rb) {
- callgl(DeleteFramebuffers, 1, &fbo);
- return nullptr;
- }
- callgl(BindFramebuffer, GR_GL_FRAMEBUFFER, fbo);
- callgl(BindRenderbuffer, GR_GL_RENDERBUFFER, rb);
- callgl(RenderbufferStorage, GR_GL_RENDERBUFFER, GR_GL_RGBA8, width, height);
- callgl(FramebufferRenderbuffer, GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0, GR_GL_RENDERBUFFER,
- rb);
- GrGLenum status = callgl(CheckFramebufferStatus, GR_GL_FRAMEBUFFER);
- if (GR_GL_FRAMEBUFFER_COMPLETE != status) {
- callgl(DeleteFramebuffers, 1, &fbo);
- callgl(DeleteRenderbuffers, 1, &rb);
- return nullptr;
- }
- callgl(Disable, GR_GL_SCISSOR_TEST);
- callgl(ClearColor, 0, 0, 0, 0.0);
- callgl(Clear, GR_GL_COLOR_BUFFER_BIT);
- checkgl();
- Target* target = new Target;
- target->fFBOID = fbo;
- target->fRBID = rb;
- target->fWidth = width;
- target->fHeight = height;
- return target;
-}
-
-void GLTestAtlasTextRenderer::targetDeleted(void* targetHandle) {
- auto restore = fContext->makeCurrentAndAutoRestore();
-
- Target* target = reinterpret_cast<Target*>(targetHandle);
- callgl(DeleteFramebuffers, 1, &target->fFBOID);
- callgl(DeleteRenderbuffers, 1, &target->fRBID);
- delete target;
-}
-
-SkBitmap GLTestAtlasTextRenderer::readTargetHandle(void* targetHandle) {
- auto restore = fContext->makeCurrentAndAutoRestore();
-
- Target* target = reinterpret_cast<Target*>(targetHandle);
-
- auto info =
- SkImageInfo::Make(target->fWidth, target->fHeight, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
- SkBitmap bmp;
- bmp.setInfo(info, sizeof(uint32_t) * target->fWidth);
- bmp.allocPixels();
-
- callgl(BindFramebuffer, GR_GL_FRAMEBUFFER, target->fFBOID);
- callgl(ReadPixels, 0, 0, target->fWidth, target->fHeight, GR_GL_RGBA, GR_GL_UNSIGNED_BYTE,
- bmp.getPixels());
- checkgl();
- return bmp;
-}
-
-void GLTestAtlasTextRenderer::clearTarget(void* targetHandle, uint32_t color) {
- auto restore = fContext->makeCurrentAndAutoRestore();
-
- Target* target = reinterpret_cast<Target*>(targetHandle);
- callgl(BindFramebuffer, GR_GL_FRAMEBUFFER, target->fFBOID);
- callgl(Disable, GR_GL_SCISSOR_TEST);
- float r = ((color >> 0) & 0xff) / 255.f;
- float g = ((color >> 8) & 0xff) / 255.f;
- float b = ((color >> 16) & 0xff) / 255.f;
- float a = ((color >> 24) & 0xff) / 255.f;
- callgl(ClearColor, r, g, b, a);
- callgl(Clear, GR_GL_COLOR_BUFFER_BIT);
-}
-
-} // anonymous namespace
-
-namespace sk_gpu_test {
-
-sk_sp<TestAtlasTextRenderer> MakeGLTestAtlasTextRenderer() {
- std::unique_ptr<GLTestContext> context(CreatePlatformGLTestContext(kGL_GrGLStandard));
- if (!context) {
- context.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard));
- }
- if (!context) {
- return nullptr;
- }
- auto restorer = context->makeCurrentAndAutoRestore();
- auto renderer = sk_make_sp<GLTestAtlasTextRenderer>(std::move(context));
- return renderer->initialized() ? std::move(renderer) : nullptr;
-}
-
-} // namespace sk_gpu_test
diff --git a/tools/gpu/atlastext/GLTestAtlasTextRenderer.h b/tools/gpu/atlastext/GLTestAtlasTextRenderer.h
deleted file mode 100644
index d1536d3..0000000
--- a/tools/gpu/atlastext/GLTestAtlasTextRenderer.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GLTestAtlasTextRenderer_DEFINED
-#define GLTestAtlasTextRenderer_DEFINED
-
-#include "include/core/SkRefCnt.h"
-
-namespace sk_gpu_test {
-
-class TestAtlasTextRenderer;
-
-/**
- * Creates a TestAtlasTextRenderer that uses its own OpenGL context to implement
- * SkAtlasTextRenderer.
- */
-sk_sp<TestAtlasTextRenderer> MakeGLTestAtlasTextRenderer();
-
-} // namespace sk_gpu_test
-
-#endif
diff --git a/tools/gpu/atlastext/TestAtlasTextRenderer.h b/tools/gpu/atlastext/TestAtlasTextRenderer.h
deleted file mode 100644
index e928e76..0000000
--- a/tools/gpu/atlastext/TestAtlasTextRenderer.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef TestAtlasTextRenderer_DEFINED
-#define TestAtlasTextRenderer_DEFINED
-
-#include "include/atlastext/SkAtlasTextRenderer.h"
-#include "include/core/SkBitmap.h"
-
-namespace sk_gpu_test {
-
-class TestContext;
-
-/**
- * Base class for implementations of SkAtlasTextRenderer in order to test the SkAtlasText APIs.
- * Adds a helper for creating SkAtlasTextTargets and to read back the contents of a target as a
- * bitmap.
- */
-class TestAtlasTextRenderer : public SkAtlasTextRenderer {
-public:
- /** Returns a handle that can be used to construct a SkAtlasTextTarget instance. */
- virtual void* makeTargetHandle(int width, int height) = 0;
-
- /** Makes a SkBitmap of the target handle's contents. */
- virtual SkBitmap readTargetHandle(void* targetHandle) = 0;
-
- /** Clears the target to the specified color, encoded as RGBA (low to high byte order) */
- virtual void clearTarget(void* targetHandle, uint32_t color) = 0;
-};
-
-} // namespace sk_gpu_test
-
-#endif
diff --git a/tools/skqp/bad_gms.txt b/tools/skqp/bad_gms.txt
index 551ba44..bf0c1f3 100644
--- a/tools/skqp/bad_gms.txt
+++ b/tools/skqp/bad_gms.txt
@@ -1,5 +1,4 @@
arcs_as_paths
-atlastext
bigbitmaprect_i
bigbitmaprect_s
blurcircles2