Remove uses of SkTAddOffset and other private Skia functions
Bug: skbug.com/13983
Change-Id: Ic99990667de25aa0a2e84f76ff0145d158dbef49
diff --git a/libs/hwui/jni/Graphics.cpp b/libs/hwui/jni/Graphics.cpp
index ae2e974..f5cd793 100644
--- a/libs/hwui/jni/Graphics.cpp
+++ b/libs/hwui/jni/Graphics.cpp
@@ -8,7 +8,6 @@
#include <nativehelper/JNIHelp.h>
#include "GraphicsJNI.h"
-#include "include/private/SkTemplates.h" // SkTAddOffset
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkColorSpace.h"
@@ -21,6 +20,7 @@
#include "SkTypes.h"
#include <cutils/ashmem.h>
#include <hwui/Canvas.h>
+#include <log/log.h>
using namespace android;
@@ -490,7 +490,7 @@
void GraphicsJNI::set_metrics(JNIEnv* env, jobject metrics, const SkFontMetrics& skmetrics) {
if (metrics == nullptr) return;
- SkASSERT(env->IsInstanceOf(metrics, gFontMetrics_class));
+ LOG_FATAL_IF(!env->IsInstanceOf(metrics, gFontMetrics_class));
env->SetFloatField(metrics, gFontMetrics_top, SkScalarToFloat(skmetrics.fTop));
env->SetFloatField(metrics, gFontMetrics_ascent, SkScalarToFloat(skmetrics.fAscent));
env->SetFloatField(metrics, gFontMetrics_descent, SkScalarToFloat(skmetrics.fDescent));
@@ -504,7 +504,7 @@
int leading = SkScalarRoundToInt(skmetrics.fLeading);
if (metrics) {
- SkASSERT(env->IsInstanceOf(metrics, gFontMetricsInt_class));
+ LOG_FATAL_IF(!env->IsInstanceOf(metrics, gFontMetricsInt_class));
env->SetIntField(metrics, gFontMetricsInt_top, SkScalarFloorToInt(skmetrics.fTop));
env->SetIntField(metrics, gFontMetricsInt_ascent, ascent);
env->SetIntField(metrics, gFontMetricsInt_descent, descent);
@@ -713,7 +713,9 @@
mSkiaBitmap->info().height());
for (int y = 0; y < rowsToCopy; y++) {
memcpy(dst, mSkiaBitmap->getAddr(0, y), bytesToCopy);
- dst = SkTAddOffset<void>(dst, dstRowBytes);
+ // Cast to bytes in order to apply the dstRowBytes offset correctly.
+ dst = reinterpret_cast<void*>(
+ reinterpret_cast<uint8_t*>(dst) + dstRowBytes);
}
recycledPixels->notifyPixelsChanged();
recycledPixels->unref();
diff --git a/libs/hwui/jni/Mesh.h b/libs/hwui/jni/Mesh.h
index 7a73f2d..61c2260 100644
--- a/libs/hwui/jni/Mesh.h
+++ b/libs/hwui/jni/Mesh.h
@@ -20,6 +20,7 @@
#include <SkMesh.h>
#include <jni.h>
+#include <log/log.h>
#include <utility>
#include "graphics_jni_helpers.h"
@@ -186,23 +187,24 @@
std::enable_if_t<std::is_trivially_copyable<T>::value, MeshUniform> operator=(
const T& val) {
if (!fVar) {
- SkDEBUGFAIL("Assigning to missing variable");
+ LOG_FATAL("Assigning to missing variable");
} else if (sizeof(val) != fVar->sizeInBytes()) {
- SkDEBUGFAIL("Incorrect value size");
+ LOG_FATAL("Incorrect value size");
} else {
- memcpy(SkTAddOffset<void>(fOwner->writableUniformData(), fVar->offset), &val,
- szeof(val));
+ void* dst = reinterpret_cast<void*>(
+ reinterpret_cast<uint8_t*>(fOwner->writableUniformData()) + fVar->offset);
+ memcpy(dst, &val, sizeof(val));
}
}
MeshUniform& operator=(const SkMatrix& val) {
if (!fVar) {
- SkDEBUGFAIL("Assigning to missing variable");
+ LOG_FATAL("Assigning to missing variable");
} else if (fVar->sizeInBytes() != 9 * sizeof(float)) {
- SkDEBUGFAIL("Incorrect value size");
+ LOG_FATAL("Incorrect value size");
} else {
- float* data =
- SkTAddOffset<float>(fOwner->writableUniformData(), (ptrdiff_t)fVar->offset);
+ float* data = reinterpret_cast<float*>(
+ reinterpret_cast<uint8_t*>(fOwner->writableUniformData()) + fVar->offset);
data[0] = val.get(0);
data[1] = val.get(3);
data[2] = val.get(6);
@@ -220,14 +222,15 @@
bool set(const T val[], const int count) {
static_assert(std::is_trivially_copyable<T>::value, "Value must be trivial copyable");
if (!fVar) {
- SkDEBUGFAIL("Assigning to missing variable");
+ LOG_FATAL("Assigning to missing variable");
return false;
} else if (sizeof(T) * count != fVar->sizeInBytes()) {
- SkDEBUGFAIL("Incorrect value size");
+ LOG_FATAL("Incorrect value size");
return false;
} else {
- memcpy(SkTAddOffset<void>(fOwner->writableUniformData(), fVar->offset), val,
- sizeof(T) * count);
+ void* dst = reinterpret_cast<void*>(
+ reinterpret_cast<uint8_t*>(fOwner->writableUniformData()) + fVar->offset);
+ memcpy(dst, val, sizeof(T) * count);
}
return true;
}