Revert "Move text logic from jni to hwui level"
This reverts commit a7f6bba1a3565c19715e878dfe7f0e01022944ff.
Change-Id: If4f36f87a85411b6128fd92d391313803ccaf9dd
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 67a7b6b..8ef1a22 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -117,10 +117,13 @@
android/graphics/Interpolator.cpp \
android/graphics/MaskFilter.cpp \
android/graphics/Matrix.cpp \
+ android/graphics/MinikinSkia.cpp \
+ android/graphics/MinikinUtils.cpp \
android/graphics/Movie.cpp \
android/graphics/NinePatch.cpp \
android/graphics/NinePatchPeeker.cpp \
android/graphics/Paint.cpp \
+ android/graphics/PaintImpl.cpp \
android/graphics/Path.cpp \
android/graphics/PathMeasure.cpp \
android/graphics/PathEffect.cpp \
@@ -132,6 +135,7 @@
android/graphics/Shader.cpp \
android/graphics/SurfaceTexture.cpp \
android/graphics/Typeface.cpp \
+ android/graphics/TypefaceImpl.cpp \
android/graphics/Utils.cpp \
android/graphics/Xfermode.cpp \
android/graphics/YuvToJpegEncoder.cpp \
diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp
index 27b9830..43e26b3 100755
--- a/core/jni/android/graphics/Bitmap.cpp
+++ b/core/jni/android/graphics/Bitmap.cpp
@@ -1,6 +1,7 @@
#define LOG_TAG "Bitmap"
#include "Bitmap.h"
+#include "Paint.h"
#include "SkBitmap.h"
#include "SkPixelRef.h"
#include "SkImageEncoder.h"
@@ -17,7 +18,6 @@
#include "android_nio_utils.h"
#include "CreateJavaOutputStreamAdaptor.h"
#include <Caches.h>
-#include <hwui/Paint.h>
#include "core_jni_helpers.h"
diff --git a/core/jni/android/graphics/Camera.cpp b/core/jni/android/graphics/Camera.cpp
index 76d6851..6fcf689 100644
--- a/core/jni/android/graphics/Camera.cpp
+++ b/core/jni/android/graphics/Camera.cpp
@@ -3,8 +3,8 @@
#include "SkCamera.h"
+#include "Canvas.h"
#include "GraphicsJNI.h"
-#include <hwui/Canvas.h>
static jfieldID gNativeInstanceFieldID;
diff --git a/core/jni/android/graphics/CanvasProperty.cpp b/core/jni/android/graphics/CanvasProperty.cpp
index c841d6a..728bc1c 100644
--- a/core/jni/android/graphics/CanvasProperty.cpp
+++ b/core/jni/android/graphics/CanvasProperty.cpp
@@ -16,9 +16,9 @@
#include "jni.h"
#include "GraphicsJNI.h"
+#include "Paint.h"
#include <core_jni_helpers.h>
-#include <hwui/Paint.h>
#include <utils/RefBase.h>
#include <CanvasProperty.h>
diff --git a/core/jni/android/graphics/FontFamily.cpp b/core/jni/android/graphics/FontFamily.cpp
index a24af29..2e974a3 100644
--- a/core/jni/android/graphics/FontFamily.cpp
+++ b/core/jni/android/graphics/FontFamily.cpp
@@ -31,9 +31,9 @@
#include <androidfw/AssetManager.h>
#include "Utils.h"
-#include <hwui/MinikinSkia.h>
-#include <hwui/TypefaceImpl.h>
+#include "TypefaceImpl.h"
#include <minikin/FontFamily.h>
+#include "MinikinSkia.h"
#include <memory>
diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp
index 1ead618..bd01c73 100644
--- a/core/jni/android/graphics/Graphics.cpp
+++ b/core/jni/android/graphics/Graphics.cpp
@@ -7,13 +7,13 @@
#include "JNIHelp.h"
#include "GraphicsJNI.h"
+#include "Canvas.h"
#include "SkCanvas.h"
#include "SkDevice.h"
#include "SkMath.h"
#include "SkRegion.h"
#include <android_runtime/AndroidRuntime.h>
#include <cutils/ashmem.h>
-#include <hwui/Canvas.h>
#include <Caches.h>
#include <TextureCache.h>
diff --git a/core/jni/android/graphics/GraphicsJNI.h b/core/jni/android/graphics/GraphicsJNI.h
index 8108e0a..e99a3ff 100644
--- a/core/jni/android/graphics/GraphicsJNI.h
+++ b/core/jni/android/graphics/GraphicsJNI.h
@@ -11,8 +11,8 @@
#include "SkPoint.h"
#include "SkRect.h"
#include "SkImageDecoder.h"
+#include <Canvas.h>
#include <jni.h>
-#include <hwui/Canvas.h>
class SkBitmapRegionDecoder;
class SkCanvas;
diff --git a/libs/hwui/hwui/MinikinSkia.cpp b/core/jni/android/graphics/MinikinSkia.cpp
similarity index 98%
rename from libs/hwui/hwui/MinikinSkia.cpp
rename to core/jni/android/graphics/MinikinSkia.cpp
index b9e3358..8ac5d46 100644
--- a/libs/hwui/hwui/MinikinSkia.cpp
+++ b/core/jni/android/graphics/MinikinSkia.cpp
@@ -14,12 +14,14 @@
* limitations under the License.
*/
-#include "MinikinSkia.h"
-
-#include <SkPaint.h>
#include <SkTypeface.h>
+#include <SkPaint.h>
+
+#define LOG_TAG "Minikin"
#include <cutils/log.h>
+#include "MinikinSkia.h"
+
namespace android {
MinikinFontSkia::MinikinFontSkia(SkTypeface *typeface) :
diff --git a/libs/hwui/hwui/MinikinSkia.h b/core/jni/android/graphics/MinikinSkia.h
similarity index 92%
rename from libs/hwui/hwui/MinikinSkia.h
rename to core/jni/android/graphics/MinikinSkia.h
index 1d50168..8f469ba 100644
--- a/libs/hwui/hwui/MinikinSkia.h
+++ b/core/jni/android/graphics/MinikinSkia.h
@@ -17,15 +17,11 @@
#ifndef _ANDROID_GRAPHICS_MINIKIN_SKIA_H_
#define _ANDROID_GRAPHICS_MINIKIN_SKIA_H_
-#include <cutils/compiler.h>
#include <minikin/MinikinFont.h>
-class SkPaint;
-class SkTypeface;
-
namespace android {
-class ANDROID_API MinikinFontSkia : public MinikinFont {
+class MinikinFontSkia : public MinikinFont {
public:
// Note: this takes ownership of the reference (will unref on dtor)
explicit MinikinFontSkia(SkTypeface *typeface);
diff --git a/libs/hwui/hwui/MinikinUtils.cpp b/core/jni/android/graphics/MinikinUtils.cpp
similarity index 98%
rename from libs/hwui/hwui/MinikinUtils.cpp
rename to core/jni/android/graphics/MinikinUtils.cpp
index f4feee2..309d35b 100644
--- a/libs/hwui/hwui/MinikinUtils.cpp
+++ b/core/jni/android/graphics/MinikinUtils.cpp
@@ -13,15 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "MinikinUtils.h"
-#include "Paint.h"
-#include "SkPathMeasure.h"
-#include "TypefaceImpl.h"
-
+#define LOG_TAG "Minikin"
#include <cutils/log.h>
#include <string>
+#include "SkPathMeasure.h"
+#include "Paint.h"
+#include "TypefaceImpl.h"
+
+#include "MinikinUtils.h"
+
namespace android {
FontStyle MinikinUtils::prepareMinikinPaint(MinikinPaint* minikinPaint, FontCollection** pFont,
diff --git a/libs/hwui/hwui/MinikinUtils.h b/core/jni/android/graphics/MinikinUtils.h
similarity index 76%
rename from libs/hwui/hwui/MinikinUtils.h
rename to core/jni/android/graphics/MinikinUtils.h
index 4a49581..9152539 100644
--- a/libs/hwui/hwui/MinikinUtils.h
+++ b/core/jni/android/graphics/MinikinUtils.h
@@ -24,7 +24,6 @@
#ifndef _ANDROID_GRAPHICS_MINIKIN_UTILS_H_
#define _ANDROID_GRAPHICS_MINIKIN_UTILS_H_
-#include <cutils/compiler.h>
#include <minikin/Layout.h>
#include "Paint.h"
#include "MinikinSkia.h"
@@ -34,24 +33,24 @@
class MinikinUtils {
public:
- ANDROID_API static FontStyle prepareMinikinPaint(MinikinPaint* minikinPaint, FontCollection** pFont,
+ static FontStyle prepareMinikinPaint(MinikinPaint* minikinPaint, FontCollection** pFont,
const Paint* paint, TypefaceImpl* typeface);
- ANDROID_API static void doLayout(Layout* layout, const Paint* paint, int bidiFlags,
+ static void doLayout(Layout* layout, const Paint* paint, int bidiFlags,
TypefaceImpl* typeface, const uint16_t* buf, size_t start, size_t count,
size_t bufSize);
- ANDROID_API static float measureText(const Paint* paint, int bidiFlags, TypefaceImpl* typeface,
+ static float measureText(const Paint* paint, int bidiFlags, TypefaceImpl* typeface,
const uint16_t* buf, size_t start, size_t count, size_t bufSize, float *advances);
- ANDROID_API static bool hasVariationSelector(TypefaceImpl* typeface, uint32_t codepoint, uint32_t vs);
+ static bool hasVariationSelector(TypefaceImpl* typeface, uint32_t codepoint, uint32_t vs);
- ANDROID_API static float xOffsetForTextAlign(Paint* paint, const Layout& layout);
+ static float xOffsetForTextAlign(Paint* paint, const Layout& layout);
- ANDROID_API static float hOffsetForTextAlign(Paint* paint, const Layout& layout, const SkPath& path);
+ static float hOffsetForTextAlign(Paint* paint, const Layout& layout, const SkPath& path);
// f is a functor of type void f(size_t start, size_t end);
template <typename F>
- ANDROID_API static void forFontRun(const Layout& layout, Paint* paint, F& f) {
+ static void forFontRun(const Layout& layout, Paint* paint, F& f) {
float saveSkewX = paint->getTextSkewX();
bool savefakeBold = paint->isFakeBoldText();
MinikinFont* curFont = NULL;
diff --git a/core/jni/android/graphics/Movie.cpp b/core/jni/android/graphics/Movie.cpp
index 71988f9c..498c590 100644
--- a/core/jni/android/graphics/Movie.cpp
+++ b/core/jni/android/graphics/Movie.cpp
@@ -1,5 +1,7 @@
+#include "Canvas.h"
#include "CreateJavaOutputStreamAdaptor.h"
#include "GraphicsJNI.h"
+#include "Paint.h"
#include "ScopedLocalRef.h"
#include "SkFrontBufferedStream.h"
#include "SkMovie.h"
@@ -10,8 +12,6 @@
#include <androidfw/Asset.h>
#include <androidfw/ResourceTypes.h>
-#include <hwui/Canvas.h>
-#include <hwui/Paint.h>
#include <jni.h>
#include <netinet/in.h>
diff --git a/core/jni/android/graphics/NinePatch.cpp b/core/jni/android/graphics/NinePatch.cpp
index 4f2f389..3ccbb35 100644
--- a/core/jni/android/graphics/NinePatch.cpp
+++ b/core/jni/android/graphics/NinePatch.cpp
@@ -19,12 +19,12 @@
#define LOG_NDEBUG 1
#include <androidfw/ResourceTypes.h>
-#include <hwui/Canvas.h>
-#include <hwui/Paint.h>
#include <utils/Log.h>
#include <ResourceCache.h>
+#include "Paint.h"
+#include "Canvas.h"
#include "SkCanvas.h"
#include "SkRegion.h"
#include "GraphicsJNI.h"
diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp
index d222a4b..d00e94c 100644
--- a/core/jni/android/graphics/Paint.cpp
+++ b/core/jni/android/graphics/Paint.cpp
@@ -37,13 +37,13 @@
#include "unicode/ushape.h"
#include "utils/Blur.h"
-#include <hwui/MinikinSkia.h>
-#include <hwui/MinikinUtils.h>
-#include <hwui/Paint.h>
-#include <hwui/TypefaceImpl.h>
#include <minikin/GraphemeBreak.h>
#include <minikin/Measurement.h>
#include <unicode/utf16.h>
+#include "MinikinSkia.h"
+#include "MinikinUtils.h"
+#include "Paint.h"
+#include "TypefaceImpl.h"
#include <cassert>
#include <cstring>
diff --git a/libs/hwui/hwui/Paint.h b/core/jni/android/graphics/Paint.h
similarity index 93%
rename from libs/hwui/hwui/Paint.h
rename to core/jni/android/graphics/Paint.h
index 69c321c..cb6e622 100644
--- a/libs/hwui/hwui/Paint.h
+++ b/core/jni/android/graphics/Paint.h
@@ -17,8 +17,6 @@
#ifndef ANDROID_GRAPHICS_PAINT_H_
#define ANDROID_GRAPHICS_PAINT_H_
-#include <cutils/compiler.h>
-
#include <SkPaint.h>
#include <string>
@@ -26,7 +24,7 @@
namespace android {
-class ANDROID_API Paint : public SkPaint {
+class Paint : public SkPaint {
public:
Paint();
Paint(const Paint& paint);
@@ -47,7 +45,7 @@
return mLetterSpacing;
}
- void setFontFeatureSettings(const std::string& fontFeatureSettings) {
+ void setFontFeatureSettings(const std::string &fontFeatureSettings) {
mFontFeatureSettings = fontFeatureSettings;
}
diff --git a/libs/hwui/hwui/PaintImpl.cpp b/core/jni/android/graphics/PaintImpl.cpp
similarity index 95%
rename from libs/hwui/hwui/PaintImpl.cpp
rename to core/jni/android/graphics/PaintImpl.cpp
index 1172a0e..bd513ae 100644
--- a/libs/hwui/hwui/PaintImpl.cpp
+++ b/core/jni/android/graphics/PaintImpl.cpp
@@ -15,6 +15,10 @@
*/
#include "Paint.h"
+#include <SkPaint.h>
+
+#define LOG_TAG "Paint"
+#include <cutils/log.h>
namespace android {
diff --git a/core/jni/android/graphics/Picture.cpp b/core/jni/android/graphics/Picture.cpp
index 07e14a2..6e83f1b 100644
--- a/core/jni/android/graphics/Picture.cpp
+++ b/core/jni/android/graphics/Picture.cpp
@@ -14,11 +14,11 @@
* limitations under the License.
*/
+#include "Canvas.h"
#include "Picture.h"
#include "SkStream.h"
#include <memory>
-#include <hwui/Canvas.h>
namespace android {
diff --git a/core/jni/android/graphics/Rasterizer.cpp b/core/jni/android/graphics/Rasterizer.cpp
index 3784f0d..a106ecf 100644
--- a/core/jni/android/graphics/Rasterizer.cpp
+++ b/core/jni/android/graphics/Rasterizer.cpp
@@ -22,11 +22,10 @@
#include "jni.h"
#include "GraphicsJNI.h"
+#include "Paint.h"
#include "SkLayerRasterizer.h"
#include "core_jni_helpers.h"
-#include <hwui/Paint.h>
-
// Rasterizer.java holds a pointer (jlong) to this guy
class NativeRasterizer {
public:
diff --git a/core/jni/android/graphics/Typeface.cpp b/core/jni/android/graphics/Typeface.cpp
index 8e2572c..e97b768d 100644
--- a/core/jni/android/graphics/Typeface.cpp
+++ b/core/jni/android/graphics/Typeface.cpp
@@ -20,9 +20,9 @@
#include "GraphicsJNI.h"
#include "ScopedPrimitiveArray.h"
#include "SkTypeface.h"
+#include "TypefaceImpl.h"
#include <android_runtime/android_util_AssetManager.h>
#include <androidfw/AssetManager.h>
-#include <hwui/TypefaceImpl.h>
using namespace android;
@@ -58,12 +58,7 @@
static jlong Typeface_createFromArray(JNIEnv *env, jobject, jlongArray familyArray) {
ScopedLongArrayRO families(env, familyArray);
- std::vector<FontFamily*> familyVec;
- for (size_t i = 0; i < families.size(); i++) {
- FontFamily* family = reinterpret_cast<FontFamily*>(families[i]);
- familyVec.push_back(family);
- }
- return reinterpret_cast<jlong>(TypefaceImpl_createFromFamilies(familyVec));
+ return reinterpret_cast<jlong>(TypefaceImpl_createFromFamilies(families.get(), families.size()));
}
static void Typeface_setDefault(JNIEnv *env, jobject, jlong faceHandle) {
diff --git a/libs/hwui/hwui/TypefaceImpl.cpp b/core/jni/android/graphics/TypefaceImpl.cpp
similarity index 91%
rename from libs/hwui/hwui/TypefaceImpl.cpp
rename to core/jni/android/graphics/TypefaceImpl.cpp
index f14381b..da56290 100644
--- a/libs/hwui/hwui/TypefaceImpl.cpp
+++ b/core/jni/android/graphics/TypefaceImpl.cpp
@@ -20,16 +20,21 @@
* being, that choice is hidden under the USE_MINIKIN compile-time flag.
*/
-#include "TypefaceImpl.h"
+#define LOG_TAG "TypefaceImpl"
-#include "MinikinSkia.h"
+#include "jni.h" // for jlong, remove when being passed proper type
+
#include "SkTypeface.h"
-#include "SkPaint.h"
+#include <vector>
#include <minikin/FontCollection.h>
#include <minikin/FontFamily.h>
#include <minikin/Layout.h>
-#include <utils/Log.h>
+#include "SkPaint.h"
+#include "MinikinSkia.h"
+
+#include "TypefaceImpl.h"
+#include "Utils.h"
namespace android {
@@ -128,10 +133,15 @@
return result;
}
-TypefaceImpl* TypefaceImpl_createFromFamilies(const std::vector<FontFamily*>& families) {
+TypefaceImpl* TypefaceImpl_createFromFamilies(const jlong* families, size_t size) {
+ std::vector<FontFamily *>familyVec;
+ for (size_t i = 0; i < size; i++) {
+ FontFamily* family = reinterpret_cast<FontFamily*>(families[i]);
+ familyVec.push_back(family);
+ }
TypefaceImpl* result = new TypefaceImpl;
- result->fFontCollection = new FontCollection(families);
- if (families.empty()) {
+ result->fFontCollection = new FontCollection(familyVec);
+ if (size == 0) {
ALOGW("createFromFamilies creating empty collection");
result->fSkiaStyle = SkTypeface::kNormal;
} else {
diff --git a/libs/hwui/hwui/TypefaceImpl.h b/core/jni/android/graphics/TypefaceImpl.h
similarity index 67%
rename from libs/hwui/hwui/TypefaceImpl.h
rename to core/jni/android/graphics/TypefaceImpl.h
index 01f1e83..4b14917 100644
--- a/libs/hwui/hwui/TypefaceImpl.h
+++ b/core/jni/android/graphics/TypefaceImpl.h
@@ -18,15 +18,15 @@
#ifndef _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_
#define _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_
+#include "jni.h" // for jlong, eventually remove
#include "SkTypeface.h"
+#include <androidfw/AssetManager.h>
-#include <cutils/compiler.h>
#include <minikin/FontCollection.h>
-#include <vector>
namespace android {
-struct ANDROID_API TypefaceImpl {
+struct TypefaceImpl {
FontCollection *fFontCollection;
// style used for constructing and querying Typeface objects
@@ -44,19 +44,21 @@
// is just a pointer to SkTypeface, in the non-USE_MINIKIN case.
// TODO: when #ifdef USE_MINIKIN is removed, move to member functions.
-ANDROID_API TypefaceImpl* TypefaceImpl_resolveDefault(TypefaceImpl* src);
+TypefaceImpl* TypefaceImpl_resolveDefault(TypefaceImpl* src);
-ANDROID_API TypefaceImpl* TypefaceImpl_createFromTypeface(TypefaceImpl* src, SkTypeface::Style style);
+TypefaceImpl* TypefaceImpl_createFromTypeface(TypefaceImpl* src, SkTypeface::Style style);
-ANDROID_API TypefaceImpl* TypefaceImpl_createWeightAlias(TypefaceImpl* src, int baseweight);
+TypefaceImpl* TypefaceImpl_createWeightAlias(TypefaceImpl* src, int baseweight);
-ANDROID_API TypefaceImpl* TypefaceImpl_createFromFamilies(const std::vector<FontFamily*>& families);
+// When we remove the USE_MINIKIN ifdef, probably a good idea to move the casting
+// (from jlong to FontFamily*) to the caller in Typeface.cpp.
+TypefaceImpl* TypefaceImpl_createFromFamilies(const jlong* families, size_t size);
-ANDROID_API void TypefaceImpl_unref(TypefaceImpl* face);
+void TypefaceImpl_unref(TypefaceImpl* face);
-ANDROID_API int TypefaceImpl_getStyle(TypefaceImpl* face);
+int TypefaceImpl_getStyle(TypefaceImpl* face);
-ANDROID_API void TypefaceImpl_setDefault(TypefaceImpl* face);
+void TypefaceImpl_setDefault(TypefaceImpl* face);
}
diff --git a/core/jni/android/graphics/pdf/PdfDocument.cpp b/core/jni/android/graphics/pdf/PdfDocument.cpp
index 88e37e5..5d496e5 100644
--- a/core/jni/android/graphics/pdf/PdfDocument.cpp
+++ b/core/jni/android/graphics/pdf/PdfDocument.cpp
@@ -19,6 +19,7 @@
#include "core_jni_helpers.h"
#include <vector>
+#include "Canvas.h"
#include "CreateJavaOutputStreamAdaptor.h"
#include "SkDocument.h"
@@ -27,8 +28,6 @@
#include "SkStream.h"
#include "SkRect.h"
-#include <hwui/Canvas.h>
-
namespace android {
struct PageRecord {
diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp
index 094f3c5..cf73316 100644
--- a/core/jni/android_graphics_Canvas.cpp
+++ b/core/jni/android_graphics_Canvas.cpp
@@ -19,14 +19,15 @@
#include "core_jni_helpers.h"
#include <androidfw/ResourceTypes.h>
-#include <hwui/Canvas.h>
-#include <hwui/Paint.h>
-#include <hwui/TypefaceImpl.h>
-#include <minikin/Layout.h>
+#include <Canvas.h>
#include "Bitmap.h"
#include "SkDrawFilter.h"
#include "SkGraphics.h"
+#include "Paint.h"
+#include "TypefaceImpl.h"
+
+#include "MinikinUtils.h"
namespace android {
@@ -474,13 +475,111 @@
vertA.ptr(), colorA.ptr(), paint);
}
+static void simplifyPaint(int color, SkPaint* paint) {
+ paint->setColor(color);
+ paint->setShader(nullptr);
+ paint->setColorFilter(nullptr);
+ paint->setLooper(nullptr);
+ paint->setStrokeWidth(4 + 0.04 * paint->getTextSize());
+ paint->setStrokeJoin(SkPaint::kRound_Join);
+ paint->setLooper(nullptr);
+}
+
+class DrawTextFunctor {
+public:
+ DrawTextFunctor(const Layout& layout, Canvas* canvas, uint16_t* glyphs, float* pos,
+ const SkPaint& paint, float x, float y, MinikinRect& bounds,
+ float totalAdvance)
+ : layout(layout), canvas(canvas), glyphs(glyphs), pos(pos), paint(paint),
+ x(x), y(y), bounds(bounds), totalAdvance(totalAdvance) { }
+
+ void operator()(size_t start, size_t end) {
+ if (canvas->drawTextAbsolutePos()) {
+ for (size_t i = start; i < end; i++) {
+ glyphs[i] = layout.getGlyphId(i);
+ pos[2 * i] = x + layout.getX(i);
+ pos[2 * i + 1] = y + layout.getY(i);
+ }
+ } else {
+ for (size_t i = start; i < end; i++) {
+ glyphs[i] = layout.getGlyphId(i);
+ pos[2 * i] = layout.getX(i);
+ pos[2 * i + 1] = layout.getY(i);
+ }
+ }
+
+ size_t glyphCount = end - start;
+
+ if (CC_UNLIKELY(canvas->isHighContrastText() && paint.getAlpha() != 0)) {
+ // high contrast draw path
+ int color = paint.getColor();
+ int channelSum = SkColorGetR(color) + SkColorGetG(color) + SkColorGetB(color);
+ bool darken = channelSum < (128 * 3);
+
+ // outline
+ SkPaint outlinePaint(paint);
+ simplifyPaint(darken ? SK_ColorWHITE : SK_ColorBLACK, &outlinePaint);
+ outlinePaint.setStyle(SkPaint::kStrokeAndFill_Style);
+ canvas->drawText(glyphs + start, pos + (2 * start), glyphCount, outlinePaint, x, y,
+ bounds.mLeft, bounds.mTop, bounds.mRight, bounds.mBottom, totalAdvance);
+
+ // inner
+ SkPaint innerPaint(paint);
+ simplifyPaint(darken ? SK_ColorBLACK : SK_ColorWHITE, &innerPaint);
+ innerPaint.setStyle(SkPaint::kFill_Style);
+ canvas->drawText(glyphs + start, pos + (2 * start), glyphCount, innerPaint, x, y,
+ bounds.mLeft, bounds.mTop, bounds.mRight, bounds.mBottom, totalAdvance);
+ } else {
+ // standard draw path
+ canvas->drawText(glyphs + start, pos + (2 * start), glyphCount, paint, x, y,
+ bounds.mLeft, bounds.mTop, bounds.mRight, bounds.mBottom,
+ totalAdvance);
+ }
+ }
+private:
+ const Layout& layout;
+ Canvas* canvas;
+ uint16_t* glyphs;
+ float* pos;
+ const SkPaint& paint;
+ float x;
+ float y;
+ MinikinRect& bounds;
+ float totalAdvance;
+};
+
+void drawText(Canvas* canvas, const uint16_t* text, int start, int count, int contextCount,
+ float x, float y, int bidiFlags, const Paint& origPaint, TypefaceImpl* typeface) {
+ // minikin may modify the original paint
+ Paint paint(origPaint);
+
+ Layout layout;
+ MinikinUtils::doLayout(&layout, &paint, bidiFlags, typeface, text, start, count, contextCount);
+
+ size_t nGlyphs = layout.nGlyphs();
+ std::unique_ptr<uint16_t[]> glyphs(new uint16_t[nGlyphs]);
+ std::unique_ptr<float[]> pos(new float[nGlyphs * 2]);
+
+ x += MinikinUtils::xOffsetForTextAlign(&paint, layout);
+
+ MinikinRect bounds;
+ layout.getBounds(&bounds);
+ if (!canvas->drawTextAbsolutePos()) {
+ bounds.offset(x, y);
+ }
+
+ DrawTextFunctor f(layout, canvas, glyphs.get(), pos.get(),
+ paint, x, y, bounds, layout.getAdvance());
+ MinikinUtils::forFontRun(layout, &paint, f);
+}
+
static void drawTextChars(JNIEnv* env, jobject, jlong canvasHandle, jcharArray text,
jint index, jint count, jfloat x, jfloat y, jint bidiFlags,
jlong paintHandle, jlong typefaceHandle) {
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
jchar* jchars = env->GetCharArrayElements(text, NULL);
- get_canvas(canvasHandle)->drawText(jchars + index, 0, count, count, x, y,
+ drawText(get_canvas(canvasHandle), jchars + index, 0, count, count, x, y,
bidiFlags, *paint, typeface);
env->ReleaseCharArrayElements(text, jchars, JNI_ABORT);
}
@@ -492,7 +591,7 @@
TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
const int count = end - start;
const jchar* jchars = env->GetStringChars(text, NULL);
- get_canvas(canvasHandle)->drawText(jchars + start, 0, count, count, x, y,
+ drawText(get_canvas(canvasHandle), jchars + start, 0, count, count, x, y,
bidiFlags, *paint, typeface);
env->ReleaseStringChars(text, jchars);
}
@@ -505,7 +604,7 @@
const int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR;
jchar* jchars = env->GetCharArrayElements(text, NULL);
- get_canvas(canvasHandle)->drawText(jchars + contextIndex, index - contextIndex, count,
+ drawText(get_canvas(canvasHandle), jchars + contextIndex, index - contextIndex, count,
contextCount, x, y, bidiFlags, *paint, typeface);
env->ReleaseCharArrayElements(text, jchars, JNI_ABORT);
}
@@ -521,11 +620,53 @@
jint count = end - start;
jint contextCount = contextEnd - contextStart;
const jchar* jchars = env->GetStringChars(text, NULL);
- get_canvas(canvasHandle)->drawText(jchars + contextStart, start - contextStart, count,
+ drawText(get_canvas(canvasHandle), jchars + contextStart, start - contextStart, count,
contextCount, x, y, bidiFlags, *paint, typeface);
env->ReleaseStringChars(text, jchars);
}
+class DrawTextOnPathFunctor {
+public:
+ DrawTextOnPathFunctor(const Layout& layout, Canvas* canvas, float hOffset,
+ float vOffset, const Paint& paint, const SkPath& path)
+ : layout(layout), canvas(canvas), hOffset(hOffset), vOffset(vOffset),
+ paint(paint), path(path) {
+ }
+ void operator()(size_t start, size_t end) {
+ uint16_t glyphs[1];
+ for (size_t i = start; i < end; i++) {
+ glyphs[0] = layout.getGlyphId(i);
+ float x = hOffset + layout.getX(i);
+ float y = vOffset + layout.getY(i);
+ canvas->drawTextOnPath(glyphs, 1, path, x, y, paint);
+ }
+ }
+private:
+ const Layout& layout;
+ Canvas* canvas;
+ float hOffset;
+ float vOffset;
+ const Paint& paint;
+ const SkPath& path;
+};
+
+static void drawTextOnPath(Canvas* canvas, const uint16_t* text, int count, int bidiFlags,
+ const SkPath& path, float hOffset, float vOffset,
+ const Paint& paint, TypefaceImpl* typeface) {
+ Paint paintCopy(paint);
+ Layout layout;
+ MinikinUtils::doLayout(&layout, &paintCopy, bidiFlags, typeface, text, 0, count, count);
+ hOffset += MinikinUtils::hOffsetForTextAlign(&paintCopy, layout, path);
+
+ // Set align to left for drawing, as we don't want individual
+ // glyphs centered or right-aligned; the offset above takes
+ // care of all alignment.
+ paintCopy.setTextAlign(Paint::kLeft_Align);
+
+ DrawTextOnPathFunctor f(layout, canvas, hOffset, vOffset, paintCopy, path);
+ MinikinUtils::forFontRun(layout, &paintCopy, f);
+}
+
static void drawTextOnPathChars(JNIEnv* env, jobject, jlong canvasHandle, jcharArray text,
jint index, jint count, jlong pathHandle, jfloat hOffset,
jfloat vOffset, jint bidiFlags, jlong paintHandle,
@@ -536,7 +677,7 @@
jchar* jchars = env->GetCharArrayElements(text, NULL);
- get_canvas(canvasHandle)->drawTextOnPath(jchars + index, count, bidiFlags, *path,
+ drawTextOnPath(get_canvas(canvasHandle), jchars + index, count, bidiFlags, *path,
hOffset, vOffset, *paint, typeface);
env->ReleaseCharArrayElements(text, jchars, 0);
@@ -552,7 +693,7 @@
const jchar* jchars = env->GetStringChars(text, NULL);
int count = env->GetStringLength(text);
- get_canvas(canvasHandle)->drawTextOnPath(jchars, count, bidiFlags, *path,
+ drawTextOnPath(get_canvas(canvasHandle), jchars, count, bidiFlags, *path,
hOffset, vOffset, *paint, typeface);
env->ReleaseStringChars(text, jchars);
diff --git a/core/jni/android_graphics_drawable_VectorDrawable.cpp b/core/jni/android_graphics_drawable_VectorDrawable.cpp
index a2662f9..e17de17 100644
--- a/core/jni/android_graphics_drawable_VectorDrawable.cpp
+++ b/core/jni/android_graphics_drawable_VectorDrawable.cpp
@@ -19,10 +19,9 @@
#include "core_jni_helpers.h"
#include "log/log.h"
+#include "Paint.h"
#include "VectorDrawable.h"
-#include <hwui/Paint.h>
-
namespace android {
using namespace uirenderer;
using namespace uirenderer::VectorDrawable;
diff --git a/core/jni/android_text_StaticLayout.cpp b/core/jni/android_text_StaticLayout.cpp
index fddcfa8..83f76ea 100644
--- a/core/jni/android_text_StaticLayout.cpp
+++ b/core/jni/android_text_StaticLayout.cpp
@@ -32,12 +32,10 @@
#include "SkPaint.h"
#include "SkTypeface.h"
-#include <hwui/MinikinSkia.h>
-#include <hwui/MinikinUtils.h>
-#include <hwui/Paint.h>
-#include <minikin/FontCollection.h>
-#include <minikin/LineBreaker.h>
-#include <minikin/MinikinFont.h>
+#include "MinikinSkia.h"
+#include "MinikinUtils.h"
+#include "Paint.h"
+#include "minikin/LineBreaker.h"
namespace android {
diff --git a/core/jni/android_view_DisplayListCanvas.cpp b/core/jni/android_view_DisplayListCanvas.cpp
index 6aac0e4..c87a770 100644
--- a/core/jni/android_view_DisplayListCanvas.cpp
+++ b/core/jni/android_view_DisplayListCanvas.cpp
@@ -28,11 +28,11 @@
#include <SkRegion.h>
+#include <Canvas.h>
#include <Rect.h>
#include <RenderNode.h>
#include <CanvasProperty.h>
-#include <hwui/Canvas.h>
-#include <hwui/Paint.h>
+#include <Paint.h>
#include <renderthread/RenderProxy.h>
#include "core_jni_helpers.h"
diff --git a/core/jni/android_view_HardwareLayer.cpp b/core/jni/android_view_HardwareLayer.cpp
index 6b774e8..3a0ddc9 100644
--- a/core/jni/android_view_HardwareLayer.cpp
+++ b/core/jni/android_view_HardwareLayer.cpp
@@ -24,8 +24,8 @@
#include <android_runtime/android_graphics_SurfaceTexture.h>
#include <gui/GLConsumer.h>
-#include <hwui/Paint.h>
+#include <Paint.h>
#include <SkBitmap.h>
#include <SkCanvas.h>
#include <SkMatrix.h>
diff --git a/core/jni/android_view_RenderNode.cpp b/core/jni/android_view_RenderNode.cpp
index f907d85..a9003c1 100644
--- a/core/jni/android_view_RenderNode.cpp
+++ b/core/jni/android_view_RenderNode.cpp
@@ -29,7 +29,7 @@
#include <Matrix.h>
#include <RenderNode.h>
#include <TreeInfo.h>
-#include <hwui/Paint.h>
+#include <Paint.h>
#include "core_jni_helpers.h"
diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk
index 26b4c4e..ca07738 100644
--- a/libs/hwui/Android.mk
+++ b/libs/hwui/Android.mk
@@ -12,11 +12,6 @@
hwui_src_files := \
font/CacheTexture.cpp \
font/Font.cpp \
- hwui/Canvas.cpp \
- hwui/MinikinSkia.cpp \
- hwui/MinikinUtils.cpp \
- hwui/PaintImpl.cpp \
- hwui/TypefaceImpl.cpp \
renderstate/Blend.cpp \
renderstate/MeshState.cpp \
renderstate/OffscreenBufferPool.cpp \
@@ -46,6 +41,7 @@
AnimatorManager.cpp \
AssetAtlas.cpp \
Caches.cpp \
+ Canvas.cpp \
CanvasState.cpp \
ClipArea.cpp \
DamageAccumulator.cpp \
@@ -147,9 +143,7 @@
hwui_c_includes += \
external/skia/include/private \
- external/skia/src/core \
- external/harfbuzz_ng/src \
- external/freetype/include
+ external/skia/src/core
ifneq (false,$(ANDROID_ENABLE_RENDERSCRIPT))
hwui_cflags += -DANDROID_ENABLE_RENDERSCRIPT
diff --git a/libs/hwui/Canvas.cpp b/libs/hwui/Canvas.cpp
new file mode 100644
index 0000000..11ae1a1
--- /dev/null
+++ b/libs/hwui/Canvas.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Canvas.h"
+
+#include "DisplayListCanvas.h"
+#include "RecordingCanvas.h"
+#include <SkDrawFilter.h>
+
+namespace android {
+
+Canvas* Canvas::create_recording_canvas(int width, int height) {
+#if HWUI_NEW_OPS
+ return new uirenderer::RecordingCanvas(width, height);
+#else
+ return new uirenderer::DisplayListCanvas(width, height);
+#endif
+}
+
+void Canvas::drawTextDecorations(float x, float y, float length, const SkPaint& paint) {
+ uint32_t flags;
+ SkDrawFilter* drawFilter = getDrawFilter();
+ if (drawFilter) {
+ SkPaint paintCopy(paint);
+ drawFilter->filter(&paintCopy, SkDrawFilter::kText_Type);
+ flags = paintCopy.getFlags();
+ } else {
+ flags = paint.getFlags();
+ }
+ if (flags & (SkPaint::kUnderlineText_Flag | SkPaint::kStrikeThruText_Flag)) {
+ // Same values used by Skia
+ const float kStdStrikeThru_Offset = (-6.0f / 21.0f);
+ const float kStdUnderline_Offset = (1.0f / 9.0f);
+ const float kStdUnderline_Thickness = (1.0f / 18.0f);
+
+ SkScalar left = x;
+ SkScalar right = x + length;
+ float textSize = paint.getTextSize();
+ float strokeWidth = fmax(textSize * kStdUnderline_Thickness, 1.0f);
+ if (flags & SkPaint::kUnderlineText_Flag) {
+ SkScalar top = y + textSize * kStdUnderline_Offset - 0.5f * strokeWidth;
+ SkScalar bottom = y + textSize * kStdUnderline_Offset + 0.5f * strokeWidth;
+ drawRect(left, top, right, bottom, paint);
+ }
+ if (flags & SkPaint::kStrikeThruText_Flag) {
+ SkScalar top = y + textSize * kStdStrikeThru_Offset - 0.5f * strokeWidth;
+ SkScalar bottom = y + textSize * kStdStrikeThru_Offset + 0.5f * strokeWidth;
+ drawRect(left, top, right, bottom, paint);
+ }
+ }
+}
+
+} // namespace android
diff --git a/libs/hwui/hwui/Canvas.h b/libs/hwui/Canvas.h
similarity index 92%
rename from libs/hwui/hwui/Canvas.h
rename to libs/hwui/Canvas.h
index 5a05cf0..27facdf 100644
--- a/libs/hwui/hwui/Canvas.h
+++ b/libs/hwui/Canvas.h
@@ -59,9 +59,6 @@
};
typedef uirenderer::VectorDrawable::Tree VectorDrawableRoot;
-class Paint;
-struct TypefaceImpl;
-
class ANDROID_API Canvas {
public:
virtual ~Canvas() {};
@@ -210,12 +207,12 @@
* drawText: count is of glyphs
* totalAdvance: used to define width of text decorations (underlines, strikethroughs).
*/
- virtual void drawGlyphs(const uint16_t* glyphs, const float* positions, int count,
+ virtual void drawText(const uint16_t* glyphs, const float* positions, int count,
const SkPaint& paint, float x, float y,
float boundsLeft, float boundsTop, float boundsRight, float boundsBottom,
float totalAdvance) = 0;
/** drawTextOnPath: count is of glyphs */
- virtual void drawGlyphsOnPath(const uint16_t* glyphs, int count, const SkPath& path,
+ virtual void drawTextOnPath(const uint16_t* glyphs, int count, const SkPath& path,
float hOffset, float vOffset, const SkPaint& paint) = 0;
/**
@@ -232,17 +229,6 @@
*/
virtual void drawVectorDrawable(VectorDrawableRoot* tree);
- /**
- * Converts utf16 text to glyphs, calculating position and boundary,
- * and delegating the final draw to virtual drawGlyphs method.
- */
- void drawText(const uint16_t* text, int start, int count, int contextCount,
- float x, float y, int bidiFlags, const Paint& origPaint, TypefaceImpl* typeface);
-
- void drawTextOnPath(const uint16_t* text, int count, int bidiFlags,
- const SkPath& path, float hOffset, float vOffset,
- const Paint& paint, TypefaceImpl* typeface);
-
protected:
void drawTextDecorations(float x, float y, float length, const SkPaint& paint);
};
diff --git a/libs/hwui/CanvasState.cpp b/libs/hwui/CanvasState.cpp
index e2149d1..43ff33f 100644
--- a/libs/hwui/CanvasState.cpp
+++ b/libs/hwui/CanvasState.cpp
@@ -14,8 +14,8 @@
* limitations under the License.
*/
+#include "Canvas.h"
#include "CanvasState.h"
-#include "hwui/Canvas.h"
#include "utils/MathUtils.h"
namespace android {
diff --git a/libs/hwui/DisplayListCanvas.cpp b/libs/hwui/DisplayListCanvas.cpp
index 2dccf32..a14bdc4 100644
--- a/libs/hwui/DisplayListCanvas.cpp
+++ b/libs/hwui/DisplayListCanvas.cpp
@@ -418,7 +418,7 @@
addDrawOp(new (alloc()) DrawVectorDrawableOp(tree));
}
-void DisplayListCanvas::drawGlyphsOnPath(const uint16_t* glyphs, int count,
+void DisplayListCanvas::drawTextOnPath(const uint16_t* glyphs, int count,
const SkPath& path, float hOffset, float vOffset, const SkPaint& paint) {
if (!glyphs || count <= 0) return;
@@ -429,7 +429,7 @@
addDrawOp(op);
}
-void DisplayListCanvas::drawGlyphs(const uint16_t* glyphs, const float* positions,
+void DisplayListCanvas::drawText(const uint16_t* glyphs, const float* positions,
int count, const SkPaint& paint, float x, float y,
float boundsLeft, float boundsTop, float boundsRight, float boundsBottom,
float totalAdvance) {
diff --git a/libs/hwui/DisplayListCanvas.h b/libs/hwui/DisplayListCanvas.h
index d6a5794..a703e22 100644
--- a/libs/hwui/DisplayListCanvas.h
+++ b/libs/hwui/DisplayListCanvas.h
@@ -17,12 +17,12 @@
#ifndef ANDROID_HWUI_DISPLAY_LIST_RENDERER_H
#define ANDROID_HWUI_DISPLAY_LIST_RENDERER_H
+#include "Canvas.h"
#include "CanvasState.h"
#include "DisplayList.h"
#include "RenderNode.h"
#include "ResourceCache.h"
#include "SkiaCanvasProxy.h"
-#include "hwui/Canvas.h"
#include "utils/Macros.h"
#include <SkDrawFilter.h>
@@ -209,10 +209,10 @@
virtual void drawVectorDrawable(VectorDrawableRoot* tree) override;
// Text
- virtual void drawGlyphs(const uint16_t* glyphs, const float* positions, int count,
+ virtual void drawText(const uint16_t* glyphs, const float* positions, int count,
const SkPaint& paint, float x, float y, float boundsLeft, float boundsTop,
float boundsRight, float boundsBottom, float totalAdvance) override;
- virtual void drawGlyphsOnPath(const uint16_t* glyphs, int count, const SkPath& path,
+ virtual void drawTextOnPath(const uint16_t* glyphs, int count, const SkPath& path,
float hOffset, float vOffset, const SkPaint& paint) override;
virtual bool drawTextAbsolutePos() const override { return false; }
diff --git a/libs/hwui/FrameBuilder.cpp b/libs/hwui/FrameBuilder.cpp
index 51e1e40..fd5856a 100644
--- a/libs/hwui/FrameBuilder.cpp
+++ b/libs/hwui/FrameBuilder.cpp
@@ -16,11 +16,11 @@
#include "FrameBuilder.h"
+#include "Canvas.h"
#include "LayerUpdateQueue.h"
#include "RenderNode.h"
#include "VectorDrawable.h"
#include "renderstate/OffscreenBufferPool.h"
-#include "hwui/Canvas.h"
#include "utils/FatVector.h"
#include "utils/PaintUtils.h"
#include "utils/TraceUtils.h"
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index c099427..7693fdc 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -17,6 +17,7 @@
#include <GpuMemoryTracker.h>
#include "OpenGLRenderer.h"
+#include "Canvas.h"
#include "DeferredDisplayList.h"
#include "GammaFontRenderer.h"
#include "Glop.h"
@@ -31,7 +32,6 @@
#include "SkiaShader.h"
#include "Vector.h"
#include "VertexBuffer.h"
-#include "hwui/Canvas.h"
#include "utils/GLUtils.h"
#include "utils/PaintUtils.h"
#include "utils/TraceUtils.h"
diff --git a/libs/hwui/RecordingCanvas.cpp b/libs/hwui/RecordingCanvas.cpp
index 7865a54..11eb825 100644
--- a/libs/hwui/RecordingCanvas.cpp
+++ b/libs/hwui/RecordingCanvas.cpp
@@ -524,7 +524,7 @@
}
// Text
-void RecordingCanvas::drawGlyphs(const uint16_t* glyphs, const float* positions, int glyphCount,
+void RecordingCanvas::drawText(const uint16_t* glyphs, const float* positions, int glyphCount,
const SkPaint& paint, float x, float y, float boundsLeft, float boundsTop,
float boundsRight, float boundsBottom, float totalAdvance) {
if (!glyphs || !positions || glyphCount <= 0 || PaintUtils::paintWillNotDrawText(paint)) return;
@@ -540,7 +540,7 @@
drawTextDecorations(x, y, totalAdvance, paint);
}
-void RecordingCanvas::drawGlyphsOnPath(const uint16_t* glyphs, int glyphCount, const SkPath& path,
+void RecordingCanvas::drawTextOnPath(const uint16_t* glyphs, int glyphCount, const SkPath& path,
float hOffset, float vOffset, const SkPaint& paint) {
if (!glyphs || glyphCount <= 0 || PaintUtils::paintWillNotDrawText(paint)) return;
glyphs = refBuffer<glyph_t>(glyphs, glyphCount);
diff --git a/libs/hwui/RecordingCanvas.h b/libs/hwui/RecordingCanvas.h
index 1eb4fa0..719872d 100644
--- a/libs/hwui/RecordingCanvas.h
+++ b/libs/hwui/RecordingCanvas.h
@@ -17,12 +17,12 @@
#ifndef ANDROID_HWUI_RECORDING_CANVAS_H
#define ANDROID_HWUI_RECORDING_CANVAS_H
+#include "Canvas.h"
#include "CanvasState.h"
#include "DisplayList.h"
#include "ResourceCache.h"
#include "SkiaCanvasProxy.h"
#include "Snapshot.h"
-#include "hwui/Canvas.h"
#include "utils/LinearAllocator.h"
#include "utils/Macros.h"
#include "utils/NinePatch.h"
@@ -191,10 +191,10 @@
const SkPaint* paint) override;
// Text
- virtual void drawGlyphs(const uint16_t* glyphs, const float* positions, int glyphCount,
+ virtual void drawText(const uint16_t* glyphs, const float* positions, int glyphCount,
const SkPaint& paint, float x, float y, float boundsLeft, float boundsTop,
float boundsRight, float boundsBottom, float totalAdvance) override;
- virtual void drawGlyphsOnPath(const uint16_t* glyphs, int glyphCount, const SkPath& path,
+ virtual void drawTextOnPath(const uint16_t* glyphs, int glyphCount, const SkPath& path,
float hOffset, float vOffset, const SkPaint& paint) override;
virtual bool drawTextAbsolutePos() const override { return false; }
diff --git a/libs/hwui/RenderProperties.cpp b/libs/hwui/RenderProperties.cpp
index f577785..0b0f0fa 100644
--- a/libs/hwui/RenderProperties.cpp
+++ b/libs/hwui/RenderProperties.cpp
@@ -23,9 +23,9 @@
#include <SkPath.h>
#include <SkPathOps.h>
+#include "Canvas.h"
#include "Matrix.h"
#include "OpenGLRenderer.h"
-#include "hwui/Canvas.h"
#include "utils/MathUtils.h"
namespace android {
diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp
index b1ecb71..bd4442d 100644
--- a/libs/hwui/SkiaCanvas.cpp
+++ b/libs/hwui/SkiaCanvas.cpp
@@ -14,10 +14,10 @@
* limitations under the License.
*/
+#include "Canvas.h"
#include "CanvasProperty.h"
#include "Layer.h"
#include "RenderNode.h"
-#include "hwui/Canvas.h"
#include <SkCanvas.h>
#include <SkClipStack.h>
@@ -147,11 +147,11 @@
float dstLeft, float dstTop, float dstRight, float dstBottom,
const SkPaint* paint) override;
- virtual void drawGlyphs(const uint16_t* text, const float* positions, int count,
+ virtual void drawText(const uint16_t* text, const float* positions, int count,
const SkPaint& paint, float x, float y,
float boundsLeft, float boundsTop, float boundsRight, float boundsBottom,
float totalAdvance) override;
- virtual void drawGlyphsOnPath(const uint16_t* glyphs, int count, const SkPath& path,
+ virtual void drawTextOnPath(const uint16_t* glyphs, int count, const SkPath& path,
float hOffset, float vOffset, const SkPaint& paint) override;
virtual bool drawTextAbsolutePos() const override { return true; }
@@ -757,7 +757,7 @@
// Canvas draw operations: Text
// ----------------------------------------------------------------------------
-void SkiaCanvas::drawGlyphs(const uint16_t* text, const float* positions, int count,
+void SkiaCanvas::drawText(const uint16_t* text, const float* positions, int count,
const SkPaint& paint, float x, float y,
float boundsLeft, float boundsTop, float boundsRight, float boundsBottom,
float totalAdvance) {
@@ -772,7 +772,7 @@
drawTextDecorations(x, y, totalAdvance, paint);
}
-void SkiaCanvas::drawGlyphsOnPath(const uint16_t* glyphs, int count, const SkPath& path,
+void SkiaCanvas::drawTextOnPath(const uint16_t* glyphs, int count, const SkPath& path,
float hOffset, float vOffset, const SkPaint& paint) {
mCanvas->drawTextOnPathHV(glyphs, count << 1, path, hOffset, vOffset, paint);
}
diff --git a/libs/hwui/SkiaCanvasProxy.cpp b/libs/hwui/SkiaCanvasProxy.cpp
index c612480..6530d4ed8 100644
--- a/libs/hwui/SkiaCanvasProxy.cpp
+++ b/libs/hwui/SkiaCanvasProxy.cpp
@@ -290,7 +290,7 @@
}
static_assert(sizeof(SkPoint) == sizeof(float)*2, "SkPoint is no longer two floats");
- mCanvas->drawGlyphs(glyphs.glyphIDs, &pointStorage[0].fX, glyphs.count, glyphs.paint,
+ mCanvas->drawText(glyphs.glyphIDs, &pointStorage[0].fX, glyphs.count, glyphs.paint,
x, y, bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom, 0);
}
@@ -326,7 +326,7 @@
bounds.offset(x, y);
static_assert(sizeof(SkPoint) == sizeof(float)*2, "SkPoint is no longer two floats");
- mCanvas->drawGlyphs(glyphs.glyphIDs, &posArray[0].fX, glyphs.count, glyphs.paint, x, y,
+ mCanvas->drawText(glyphs.glyphIDs, &posArray[0].fX, glyphs.count, glyphs.paint, x, y,
bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom, 0);
}
@@ -344,7 +344,7 @@
const SkMatrix* matrix, const SkPaint& origPaint) {
// convert to glyphIDs if necessary
GlyphIDConverter glyphs(text, byteLength, origPaint);
- mCanvas->drawGlyphsOnPath(glyphs.glyphIDs, glyphs.count, path, 0, 0, glyphs.paint);
+ mCanvas->drawTextOnPath(glyphs.glyphIDs, glyphs.count, path, 0, 0, glyphs.paint);
}
void SkiaCanvasProxy::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
diff --git a/libs/hwui/SkiaCanvasProxy.h b/libs/hwui/SkiaCanvasProxy.h
index 973c55f..e342d19 100644
--- a/libs/hwui/SkiaCanvasProxy.h
+++ b/libs/hwui/SkiaCanvasProxy.h
@@ -20,7 +20,7 @@
#include <cutils/compiler.h>
#include <SkCanvas.h>
-#include "hwui/Canvas.h"
+#include "Canvas.h"
namespace android {
namespace uirenderer {
diff --git a/libs/hwui/Snapshot.cpp b/libs/hwui/Snapshot.cpp
index d784280..cf5e69a 100644
--- a/libs/hwui/Snapshot.cpp
+++ b/libs/hwui/Snapshot.cpp
@@ -16,7 +16,7 @@
#include "Snapshot.h"
-#include "hwui/Canvas.h"
+#include "Canvas.h"
namespace android {
namespace uirenderer {
diff --git a/libs/hwui/VectorDrawable.h b/libs/hwui/VectorDrawable.h
index 7a45bf5..4d2fed0 100644
--- a/libs/hwui/VectorDrawable.h
+++ b/libs/hwui/VectorDrawable.h
@@ -17,7 +17,7 @@
#ifndef ANDROID_HWUI_VPATH_H
#define ANDROID_HWUI_VPATH_H
-#include "hwui/Canvas.h"
+#include "Canvas.h"
#include <SkBitmap.h>
#include <SkColor.h>
diff --git a/libs/hwui/hwui/Canvas.cpp b/libs/hwui/hwui/Canvas.cpp
deleted file mode 100644
index 04e3af6..0000000
--- a/libs/hwui/hwui/Canvas.cpp
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "Canvas.h"
-
-#include "DisplayListCanvas.h"
-#include "RecordingCanvas.h"
-#include "MinikinUtils.h"
-#include "Paint.h"
-#include "TypefaceImpl.h"
-
-#include <SkDrawFilter.h>
-
-namespace android {
-
-Canvas* Canvas::create_recording_canvas(int width, int height) {
-#if HWUI_NEW_OPS
- return new uirenderer::RecordingCanvas(width, height);
-#else
- return new uirenderer::DisplayListCanvas(width, height);
-#endif
-}
-
-void Canvas::drawTextDecorations(float x, float y, float length, const SkPaint& paint) {
- uint32_t flags;
- SkDrawFilter* drawFilter = getDrawFilter();
- if (drawFilter) {
- SkPaint paintCopy(paint);
- drawFilter->filter(&paintCopy, SkDrawFilter::kText_Type);
- flags = paintCopy.getFlags();
- } else {
- flags = paint.getFlags();
- }
- if (flags & (SkPaint::kUnderlineText_Flag | SkPaint::kStrikeThruText_Flag)) {
- // Same values used by Skia
- const float kStdStrikeThru_Offset = (-6.0f / 21.0f);
- const float kStdUnderline_Offset = (1.0f / 9.0f);
- const float kStdUnderline_Thickness = (1.0f / 18.0f);
-
- SkScalar left = x;
- SkScalar right = x + length;
- float textSize = paint.getTextSize();
- float strokeWidth = fmax(textSize * kStdUnderline_Thickness, 1.0f);
- if (flags & SkPaint::kUnderlineText_Flag) {
- SkScalar top = y + textSize * kStdUnderline_Offset - 0.5f * strokeWidth;
- SkScalar bottom = y + textSize * kStdUnderline_Offset + 0.5f * strokeWidth;
- drawRect(left, top, right, bottom, paint);
- }
- if (flags & SkPaint::kStrikeThruText_Flag) {
- SkScalar top = y + textSize * kStdStrikeThru_Offset - 0.5f * strokeWidth;
- SkScalar bottom = y + textSize * kStdStrikeThru_Offset + 0.5f * strokeWidth;
- drawRect(left, top, right, bottom, paint);
- }
- }
-}
-
-static void simplifyPaint(int color, SkPaint* paint) {
- paint->setColor(color);
- paint->setShader(nullptr);
- paint->setColorFilter(nullptr);
- paint->setLooper(nullptr);
- paint->setStrokeWidth(4 + 0.04 * paint->getTextSize());
- paint->setStrokeJoin(SkPaint::kRound_Join);
- paint->setLooper(nullptr);
-}
-
-class DrawTextFunctor {
-public:
- DrawTextFunctor(const Layout& layout, Canvas* canvas, uint16_t* glyphs, float* pos,
- const SkPaint& paint, float x, float y, MinikinRect& bounds, float totalAdvance)
- : layout(layout)
- , canvas(canvas)
- , glyphs(glyphs)
- , pos(pos)
- , paint(paint)
- , x(x)
- , y(y)
- , bounds(bounds)
- , totalAdvance(totalAdvance) {
- }
-
- void operator()(size_t start, size_t end) {
- if (canvas->drawTextAbsolutePos()) {
- for (size_t i = start; i < end; i++) {
- glyphs[i] = layout.getGlyphId(i);
- pos[2 * i] = x + layout.getX(i);
- pos[2 * i + 1] = y + layout.getY(i);
- }
- } else {
- for (size_t i = start; i < end; i++) {
- glyphs[i] = layout.getGlyphId(i);
- pos[2 * i] = layout.getX(i);
- pos[2 * i + 1] = layout.getY(i);
- }
- }
-
- size_t glyphCount = end - start;
-
- if (CC_UNLIKELY(canvas->isHighContrastText() && paint.getAlpha() != 0)) {
- // high contrast draw path
- int color = paint.getColor();
- int channelSum = SkColorGetR(color) + SkColorGetG(color) + SkColorGetB(color);
- bool darken = channelSum < (128 * 3);
-
- // outline
- SkPaint outlinePaint(paint);
- simplifyPaint(darken ? SK_ColorWHITE : SK_ColorBLACK, &outlinePaint);
- outlinePaint.setStyle(SkPaint::kStrokeAndFill_Style);
- canvas->drawGlyphs(glyphs + start, pos + (2 * start), glyphCount, outlinePaint, x, y,
- bounds.mLeft, bounds.mTop, bounds.mRight, bounds.mBottom, totalAdvance);
-
- // inner
- SkPaint innerPaint(paint);
- simplifyPaint(darken ? SK_ColorBLACK : SK_ColorWHITE, &innerPaint);
- innerPaint.setStyle(SkPaint::kFill_Style);
- canvas->drawGlyphs(glyphs + start, pos + (2 * start), glyphCount, innerPaint, x, y,
- bounds.mLeft, bounds.mTop, bounds.mRight, bounds.mBottom, totalAdvance);
- } else {
- // standard draw path
- canvas->drawGlyphs(glyphs + start, pos + (2 * start), glyphCount, paint, x, y,
- bounds.mLeft, bounds.mTop, bounds.mRight, bounds.mBottom, totalAdvance);
- }
- }
-private:
- const Layout& layout;
- Canvas* canvas;
- uint16_t* glyphs;
- float* pos;
- const SkPaint& paint;
- float x;
- float y;
- MinikinRect& bounds;
- float totalAdvance;
-};
-
-void Canvas::drawText(const uint16_t* text, int start, int count, int contextCount,
- float x, float y, int bidiFlags, const Paint& origPaint, TypefaceImpl* typeface) {
- // minikin may modify the original paint
- Paint paint(origPaint);
-
- Layout layout;
- MinikinUtils::doLayout(&layout, &paint, bidiFlags, typeface, text, start, count, contextCount);
-
- size_t nGlyphs = layout.nGlyphs();
- std::unique_ptr<uint16_t[]> glyphs(new uint16_t[nGlyphs]);
- std::unique_ptr<float[]> pos(new float[nGlyphs * 2]);
-
- x += MinikinUtils::xOffsetForTextAlign(&paint, layout);
-
- MinikinRect bounds;
- layout.getBounds(&bounds);
- if (!drawTextAbsolutePos()) {
- bounds.offset(x, y);
- }
-
- DrawTextFunctor f(layout, this, glyphs.get(), pos.get(),
- paint, x, y, bounds, layout.getAdvance());
- MinikinUtils::forFontRun(layout, &paint, f);
-}
-
-class DrawTextOnPathFunctor {
-public:
- DrawTextOnPathFunctor(const Layout& layout, Canvas* canvas, float hOffset,
- float vOffset, const Paint& paint, const SkPath& path)
- : layout(layout)
- , canvas(canvas)
- , hOffset(hOffset)
- , vOffset(vOffset)
- , paint(paint)
- , path(path) {
- }
-
- void operator()(size_t start, size_t end) {
- uint16_t glyphs[1];
- for (size_t i = start; i < end; i++) {
- glyphs[0] = layout.getGlyphId(i);
- float x = hOffset + layout.getX(i);
- float y = vOffset + layout.getY(i);
- canvas->drawGlyphsOnPath(glyphs, 1, path, x, y, paint);
- }
- }
-private:
- const Layout& layout;
- Canvas* canvas;
- float hOffset;
- float vOffset;
- const Paint& paint;
- const SkPath& path;
-};
-
-void Canvas::drawTextOnPath(const uint16_t* text, int count, int bidiFlags, const SkPath& path,
- float hOffset, float vOffset, const Paint& paint, TypefaceImpl* typeface) {
- Paint paintCopy(paint);
- Layout layout;
- MinikinUtils::doLayout(&layout, &paintCopy, bidiFlags, typeface, text, 0, count, count);
- hOffset += MinikinUtils::hOffsetForTextAlign(&paintCopy, layout, path);
-
- // Set align to left for drawing, as we don't want individual
- // glyphs centered or right-aligned; the offset above takes
- // care of all alignment.
- paintCopy.setTextAlign(Paint::kLeft_Align);
-
- DrawTextOnPathFunctor f(layout, this, hOffset, vOffset, paintCopy, path);
- MinikinUtils::forFontRun(layout, &paintCopy, f);
-}
-
-} // namespace android
diff --git a/libs/hwui/hwui_static_deps.mk b/libs/hwui/hwui_static_deps.mk
index 47bbd66..7d4ef0f 100644
--- a/libs/hwui/hwui_static_deps.mk
+++ b/libs/hwui/hwui_static_deps.mk
@@ -21,10 +21,7 @@
libskia \
libui \
libgui \
- libprotobuf-cpp-lite \
- libharfbuzz_ng \
- libft2 \
- libminikin
+ libprotobuf-cpp-lite
ifneq (false,$(ANDROID_ENABLE_RENDERSCRIPT))
LOCAL_SHARED_LIBRARIES += libRS libRScpp
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index e348a8c..a496b49 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -19,6 +19,7 @@
#include "AnimationContext.h"
#include "Caches.h"
+#include "Canvas.h"
#include "DeferredLayerUpdater.h"
#include "EglManager.h"
#include "LayerUpdateQueue.h"
@@ -26,7 +27,6 @@
#include "OpenGLRenderer.h"
#include "Properties.h"
#include "RenderThread.h"
-#include "hwui/Canvas.h"
#include "renderstate/RenderState.h"
#include "renderstate/Stencil.h"
#include "protos/hwui.pb.h"
diff --git a/libs/hwui/tests/common/TestUtils.cpp b/libs/hwui/tests/common/TestUtils.cpp
index a4aee61..c809ff4 100644
--- a/libs/hwui/tests/common/TestUtils.cpp
+++ b/libs/hwui/tests/common/TestUtils.cpp
@@ -87,7 +87,7 @@
*outTotalAdvance = totalAdvance;
}
-void TestUtils::drawUtf8ToCanvas(TestCanvas* canvas, const char* text,
+void TestUtils::drawTextToCanvas(TestCanvas* canvas, const char* text,
const SkPaint& paint, float x, float y) {
// drawing text requires GlyphID TextEncoding (which JNI layer would have done)
LOG_ALWAYS_FATAL_IF(paint.getTextEncoding() != SkPaint::kGlyphID_TextEncoding,
@@ -113,11 +113,11 @@
// Force left alignment, since alignment offset is already baked in
SkPaint alignPaintCopy(paint);
alignPaintCopy.setTextAlign(SkPaint::kLeft_Align);
- canvas->drawGlyphs(glyphs.data(), positions.data(), glyphs.size(), alignPaintCopy, x, y,
+ canvas->drawText(glyphs.data(), positions.data(), glyphs.size(), alignPaintCopy, x, y,
bounds.left, bounds.top, bounds.right, bounds.bottom, totalAdvance);
}
-void TestUtils::drawUtf8ToCanvas(TestCanvas* canvas, const char* text,
+void TestUtils::drawTextToCanvas(TestCanvas* canvas, const char* text,
const SkPaint& paint, const SkPath& path) {
// drawing text requires GlyphID TextEncoding (which JNI layer would have done)
LOG_ALWAYS_FATAL_IF(paint.getTextEncoding() != SkPaint::kGlyphID_TextEncoding,
@@ -130,7 +130,7 @@
SkUnichar unichar = SkUTF8_NextUnichar(&text);
glyphs.push_back(autoCache.getCache()->unicharToGlyph(unichar));
}
- canvas->drawGlyphsOnPath(glyphs.data(), glyphs.size(), path, 0, 0, paint);
+ canvas->drawTextOnPath(glyphs.data(), glyphs.size(), path, 0, 0, paint);
}
void TestUtils::TestTask::run() {
@@ -143,13 +143,5 @@
renderState.onGLContextDestroyed();
}
-std::unique_ptr<uint16_t[]> TestUtils::utf8ToUtf16(const char* str) {
- const size_t strLen = strlen(str);
- const ssize_t utf16Len = utf8_to_utf16_length((uint8_t*) str, strLen);
- std::unique_ptr<uint16_t[]> dst(new uint16_t[utf16Len + 1]);
- utf8_to_utf16((uint8_t*) str, strLen, (char16_t*) dst.get());
- return dst;
-}
-
} /* namespace uirenderer */
} /* namespace android */
diff --git a/libs/hwui/tests/common/TestUtils.h b/libs/hwui/tests/common/TestUtils.h
index a5e7a5f..28ac116 100644
--- a/libs/hwui/tests/common/TestUtils.h
+++ b/libs/hwui/tests/common/TestUtils.h
@@ -207,14 +207,12 @@
std::vector<glyph_t>* outGlyphs, std::vector<float>* outPositions,
float* outTotalAdvance, Rect* outBounds);
- static void drawUtf8ToCanvas(TestCanvas* canvas, const char* text,
+ static void drawTextToCanvas(TestCanvas* canvas, const char* text,
const SkPaint& paint, float x, float y);
- static void drawUtf8ToCanvas(TestCanvas* canvas, const char* text,
+ static void drawTextToCanvas(TestCanvas* canvas, const char* text,
const SkPaint& paint, const SkPath& path);
- static std::unique_ptr<uint16_t[]> utf8ToUtf16(const char* str);
-
private:
static void syncHierarchyPropertiesAndDisplayListImpl(RenderNode* node) {
node->syncProperties();
diff --git a/libs/hwui/tests/common/scenes/ListViewAnimation.cpp b/libs/hwui/tests/common/scenes/ListViewAnimation.cpp
index ab368c05..43e247e 100644
--- a/libs/hwui/tests/common/scenes/ListViewAnimation.cpp
+++ b/libs/hwui/tests/common/scenes/ListViewAnimation.cpp
@@ -136,9 +136,9 @@
textPaint.setAntiAlias(true);
char buf[256];
snprintf(buf, sizeof(buf), "This card is #%d", cardId);
- TestUtils::drawUtf8ToCanvas(&canvas, buf, textPaint, cardHeight, dp(25));
+ TestUtils::drawTextToCanvas(&canvas, buf, textPaint, cardHeight, dp(25));
textPaint.setTextSize(dp(15));
- TestUtils::drawUtf8ToCanvas(&canvas, "This is some more text on the card", textPaint,
+ TestUtils::drawTextToCanvas(&canvas, "This is some more text on the card", textPaint,
cardHeight, dp(45));
canvas.drawBitmap(createRandomCharIcon(), dp(10), dp(10), nullptr);
diff --git a/libs/hwui/tests/common/scenes/TextAnimation.cpp b/libs/hwui/tests/common/scenes/TextAnimation.cpp
index be8f48b..1823db2 100644
--- a/libs/hwui/tests/common/scenes/TextAnimation.cpp
+++ b/libs/hwui/tests/common/scenes/TextAnimation.cpp
@@ -39,14 +39,14 @@
paint.setColor(Color::Black);
for (int i = 0; i < 10; i++) {
- TestUtils::drawUtf8ToCanvas(&canvas, "Test string", paint, 400, i * 100);
+ TestUtils::drawTextToCanvas(&canvas, "Test string", paint, 400, i * 100);
}
SkPath path;
path.addOval(SkRect::MakeLTRB(100, 100, 300, 300));
paint.setColor(Color::Blue_500);
- TestUtils::drawUtf8ToCanvas(&canvas, "This is a neat circle of text!", paint, path);
+ TestUtils::drawTextToCanvas(&canvas, "This is a neat circle of text!", paint, path);
});
canvas.drawRenderNode(card.get());
}
diff --git a/libs/hwui/tests/unit/CanvasStateTests.cpp b/libs/hwui/tests/unit/CanvasStateTests.cpp
index 0afabd8..68d74ee 100644
--- a/libs/hwui/tests/unit/CanvasStateTests.cpp
+++ b/libs/hwui/tests/unit/CanvasStateTests.cpp
@@ -16,9 +16,9 @@
#include "CanvasState.h"
+#include "Canvas.h"
#include "Matrix.h"
#include "Rect.h"
-#include "hwui/Canvas.h"
#include "utils/LinearAllocator.h"
#include <gtest/gtest.h>
diff --git a/libs/hwui/tests/unit/FrameBuilderTests.cpp b/libs/hwui/tests/unit/FrameBuilderTests.cpp
index d496f59..f147fd4 100644
--- a/libs/hwui/tests/unit/FrameBuilderTests.cpp
+++ b/libs/hwui/tests/unit/FrameBuilderTests.cpp
@@ -274,8 +274,8 @@
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
paint.setAntiAlias(true);
paint.setTextSize(50);
- TestUtils::drawUtf8ToCanvas(&canvas, "Test string1", paint, 100, 0); // will be top clipped
- TestUtils::drawUtf8ToCanvas(&canvas, "Test string1", paint, 100, 100); // not clipped
+ TestUtils::drawTextToCanvas(&canvas, "Test string1", paint, 100, 0); // will be top clipped
+ TestUtils::drawTextToCanvas(&canvas, "Test string1", paint, 100, 100); // not clipped
});
FrameBuilder frameBuilder(sEmptyLayerUpdateQueue, SkRect::MakeWH(400, 400), 400, 400,
TestUtils::createSyncedNodeList(node), sLightGeometry, nullptr);
@@ -305,7 +305,7 @@
textPaint.setStrikeThruText(true);
textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
for (int i = 0; i < LOOPS; i++) {
- TestUtils::drawUtf8ToCanvas(&canvas, "test text", textPaint, 10, 100 * (i + 1));
+ TestUtils::drawTextToCanvas(&canvas, "test text", textPaint, 10, 100 * (i + 1));
}
});
FrameBuilder frameBuilder(sEmptyLayerUpdateQueue, SkRect::MakeWH(200, 2000), 200, 2000,
diff --git a/libs/hwui/tests/unit/RecordingCanvasTests.cpp b/libs/hwui/tests/unit/RecordingCanvasTests.cpp
index d38f2a4..5e613fd 100644
--- a/libs/hwui/tests/unit/RecordingCanvasTests.cpp
+++ b/libs/hwui/tests/unit/RecordingCanvasTests.cpp
@@ -18,8 +18,6 @@
#include <RecordedOp.h>
#include <RecordingCanvas.h>
-#include <hwui/Paint.h>
-#include <minikin/Layout.h>
#include <tests/common/TestUtils.h>
#include <utils/Color.h>
@@ -133,13 +131,13 @@
<< "Non-rounded rects should be converted";
}
-TEST(RecordingCanvas, drawGlyphs) {
+TEST(RecordingCanvas, drawText) {
auto dl = TestUtils::createDisplayList<RecordingCanvas>(200, 200, [](RecordingCanvas& canvas) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setTextSize(20);
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- TestUtils::drawUtf8ToCanvas(&canvas, "test text", paint, 25, 25);
+ TestUtils::drawTextToCanvas(&canvas, "test text", paint, 25, 25);
});
int count = 0;
@@ -154,7 +152,7 @@
ASSERT_EQ(1, count);
}
-TEST(RecordingCanvas, drawGlyphs_strikeThruAndUnderline) {
+TEST(RecordingCanvas, drawText_strikeThruAndUnderline) {
auto dl = TestUtils::createDisplayList<RecordingCanvas>(200, 200, [](RecordingCanvas& canvas) {
SkPaint paint;
paint.setAntiAlias(true);
@@ -164,7 +162,7 @@
for (int j = 0; j < 2; j++) {
paint.setUnderlineText(i != 0);
paint.setStrikeThruText(j != 0);
- TestUtils::drawUtf8ToCanvas(&canvas, "test text", paint, 25, 25);
+ TestUtils::drawTextToCanvas(&canvas, "test text", paint, 25, 25);
}
}
});
@@ -186,18 +184,18 @@
EXPECT_EQ(RecordedOpId::RectOp, ops[index++]->opId); // strikethrough
}
-TEST(RecordingCanvas, drawGlyphs_forceAlignLeft) {
+TEST(RecordingCanvas, drawText_forceAlignLeft) {
auto dl = TestUtils::createDisplayList<RecordingCanvas>(200, 200, [](RecordingCanvas& canvas) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setTextSize(20);
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
paint.setTextAlign(SkPaint::kLeft_Align);
- TestUtils::drawUtf8ToCanvas(&canvas, "test text", paint, 25, 25);
+ TestUtils::drawTextToCanvas(&canvas, "test text", paint, 25, 25);
paint.setTextAlign(SkPaint::kCenter_Align);
- TestUtils::drawUtf8ToCanvas(&canvas, "test text", paint, 25, 25);
+ TestUtils::drawTextToCanvas(&canvas, "test text", paint, 25, 25);
paint.setTextAlign(SkPaint::kRight_Align);
- TestUtils::drawUtf8ToCanvas(&canvas, "test text", paint, 25, 25);
+ TestUtils::drawTextToCanvas(&canvas, "test text", paint, 25, 25);
});
int count = 0;
@@ -579,7 +577,7 @@
canvas.drawRect(0, 0, 200, 10, paint);
SkPaint paintCopy(paint);
canvas.drawRect(0, 10, 200, 20, paintCopy);
- TestUtils::drawUtf8ToCanvas(&canvas, "helloworld", paint, 50, 25);
+ TestUtils::drawTextToCanvas(&canvas, "helloworld", paint, 50, 25);
// only here do we use different paint ptr
paint.setColor(SK_ColorRED);
@@ -600,54 +598,5 @@
EXPECT_NE(&paint, ops[3]->paint);
}
-TEST(RecordingCanvas, drawText) {
- auto dl = TestUtils::createDisplayList<RecordingCanvas>(200, 200, [](RecordingCanvas& canvas) {
- Paint paint;
- paint.setAntiAlias(true);
- paint.setTextSize(20);
- paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- std::unique_ptr<uint16_t[]> dst = TestUtils::utf8ToUtf16("HELLO");
- canvas.drawText(dst.get(), 0, 5, 5, 25, 25, kBidi_Force_LTR, paint, NULL);
- });
-
- int count = 0;
- playbackOps(*dl, [&count](const RecordedOp& op) {
- count++;
- ASSERT_EQ(RecordedOpId::TextOp, op.opId);
- EXPECT_EQ(nullptr, op.localClip);
- EXPECT_TRUE(op.localMatrix.isIdentity());
- EXPECT_TRUE(op.unmappedBounds.getHeight() >= 10);
- EXPECT_TRUE(op.unmappedBounds.getWidth() >= 25);
- });
- ASSERT_EQ(1, count);
-}
-
-TEST(RecordingCanvas, drawTextInHighContrast) {
- auto dl = TestUtils::createDisplayList<RecordingCanvas>(200, 200, [](RecordingCanvas& canvas) {
- canvas.setHighContrastText(true);
- Paint paint;
- paint.setColor(SK_ColorWHITE);
- paint.setAntiAlias(true);
- paint.setTextSize(20);
- paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- std::unique_ptr<uint16_t[]> dst = TestUtils::utf8ToUtf16("HELLO");
- canvas.drawText(dst.get(), 0, 5, 5, 25, 25, kBidi_Force_LTR, paint, NULL);
- });
-
- int count = 0;
- playbackOps(*dl, [&count](const RecordedOp& op) {
- ASSERT_EQ(RecordedOpId::TextOp, op.opId);
- if (count++ == 0) {
- EXPECT_EQ(SK_ColorBLACK, op.paint->getColor());
- EXPECT_EQ(SkPaint::kStrokeAndFill_Style, op.paint->getStyle());
- } else {
- EXPECT_EQ(SK_ColorWHITE, op.paint->getColor());
- EXPECT_EQ(SkPaint::kFill_Style, op.paint->getStyle());
- }
-
- });
- ASSERT_EQ(2, count);
-}
-
} // namespace uirenderer
} // namespace android