switch over to SkVertices object, and stop using deprecated methods.

This allows Skia to remove
  SK_SUPPORT_LEGACY_CANVAS_VERTICES
  SK_SUPPORT_LEGACY_BITMAP_SETPIXELREF
  SK_SUPPORT_LEGACY_PIXELREFFACTORY

Test: Existing CTS cover these changes

Running CtsGraphicsTestCases, there were 6 failures w/ and w/o this CL.
None of the 6 seems related to this CL.

Change-Id: I724082357d9f6cb699770df3c0b9ef555b957697
This commit is contained in:
Mike Reed
2017-04-04 15:32:04 -04:00
parent 06d6b4d9b0
commit 826deefda5
9 changed files with 29 additions and 54 deletions

View File

@@ -209,8 +209,7 @@ public:
}
mBitmap->reconfigure(info, bitmap->rowBytes(), ctable);
mBitmap->ref();
bitmap->setPixelRef(mBitmap)->unref();
bitmap->setPixelRef(sk_ref_sp(mBitmap), 0, 0);
// since we're already allocated, we lockPixels right away
// HeapAllocator behaves this way too

View File

@@ -516,8 +516,7 @@ bool RecyclingClippingPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTab
// skbug.com/4538: We also need to make sure that the rowBytes on the pixel ref
// match the rowBytes on the bitmap.
bitmap->setInfo(bitmap->info(), rowBytes);
mRecycledBitmap->ref();
bitmap->setPixelRef(mRecycledBitmap)->unref();
bitmap->setPixelRef(sk_ref_sp(mRecycledBitmap), 0, 0);
// Make sure that the recycled bitmap has the correct alpha type.
mRecycledBitmap->setAlphaType(bitmap->alphaType());

View File

@@ -28,6 +28,7 @@
#include "SkDrawFilter.h"
#include "SkGraphics.h"
#include "SkRegion.h"
#include "SkVertices.h"
namespace android {
@@ -311,15 +312,15 @@ static void drawPath(JNIEnv* env, jobject, jlong canvasHandle, jlong pathHandle,
}
static void drawVertices(JNIEnv* env, jobject, jlong canvasHandle,
jint modeHandle, jint vertexCount,
jint modeHandle, jint floatCount,
jfloatArray jverts, jint vertIndex,
jfloatArray jtexs, jint texIndex,
jintArray jcolors, jint colorIndex,
jshortArray jindices, jint indexIndex,
jint indexCount, jlong paintHandle) {
AutoJavaFloatArray vertA(env, jverts, vertIndex + vertexCount);
AutoJavaFloatArray texA(env, jtexs, texIndex + vertexCount);
AutoJavaIntArray colorA(env, jcolors, colorIndex + vertexCount);
AutoJavaFloatArray vertA(env, jverts, vertIndex + floatCount);
AutoJavaFloatArray texA(env, jtexs, texIndex + floatCount);
AutoJavaIntArray colorA(env, jcolors, colorIndex + floatCount);
AutoJavaShortArray indexA(env, jindices, indexIndex + indexCount);
const float* verts = vertA.ptr() + vertIndex;
@@ -334,10 +335,15 @@ static void drawVertices(JNIEnv* env, jobject, jlong canvasHandle,
indices = (const uint16_t*)(indexA.ptr() + indexIndex);
}
SkCanvas::VertexMode mode = static_cast<SkCanvas::VertexMode>(modeHandle);
int vertexCount = floatCount >> 1; // 2 floats per SkPoint
SkVertices::VertexMode mode = static_cast<SkVertices::VertexMode>(modeHandle);
const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
get_canvas(canvasHandle)->drawVertices(mode, vertexCount, verts, texs, colors,
indices, indexCount, *paint);
get_canvas(canvasHandle)->drawVertices(SkVertices::MakeCopy(mode, vertexCount,
reinterpret_cast<const SkPoint*>(verts),
reinterpret_cast<const SkPoint*>(texs),
reinterpret_cast<const SkColor*>(colors),
indexCount, indices).get(),
SkBlendMode::kModulate, *paint);
}
static void drawNinePatch(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle,

View File

@@ -168,9 +168,7 @@ public:
virtual void drawArc(float left, float top, float right, float bottom,
float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) override;
virtual void drawPath(const SkPath& path, const SkPaint& paint) override;
virtual void drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
const float* verts, const float* tex, const int* colors,
const uint16_t* indices, int indexCount, const SkPaint& paint) override
virtual void drawVertices(const SkVertices*, SkBlendMode, const SkPaint& paint) override
{ /* RecordingCanvas does not support drawVertices(); ignore */ }
virtual void drawVectorDrawable(VectorDrawableRoot* tree) override;

View File

@@ -515,17 +515,8 @@ void SkiaCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
mCanvas->drawPath(path, paint);
}
void SkiaCanvas::drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
const float* verts, const float* texs, const int* colors,
const uint16_t* indices, int indexCount, const SkPaint& paint) {
#ifndef SK_SCALAR_IS_FLOAT
SkDEBUGFAIL("SkScalar must be a float for these conversions to be valid");
#endif
const int ptCount = vertexCount >> 1;
mCanvas->drawVertices(SkVertices::MakeCopy(vertexMode, ptCount, (SkPoint*)verts,
(SkPoint*)texs, (SkColor*)colors,
indexCount, indices),
SkBlendMode::kModulate, paint);
void SkiaCanvas::drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) {
mCanvas->drawVertices(vertices, mode, paint);
}
// ----------------------------------------------------------------------------
@@ -566,7 +557,7 @@ void SkiaCanvas::drawBitmapMesh(Bitmap& hwuiBitmap, int meshWidth, int meshHeigh
if (colors) {
flags |= SkVertices::kHasColors_BuilderFlag;
}
SkVertices::Builder builder(SkCanvas::kTriangles_VertexMode, ptCount, indexCount, flags);
SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, ptCount, indexCount, flags);
memcpy(builder.positions(), vertices, ptCount * sizeof(SkPoint));
if (colors) {
memcpy(builder.colors(), colors, ptCount * sizeof(SkColor));

View File

@@ -117,9 +117,7 @@ public:
virtual void drawArc(float left, float top, float right, float bottom,
float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) override;
virtual void drawPath(const SkPath& path, const SkPaint& paint) override;
virtual void drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
const float* verts, const float* tex, const int* colors,
const uint16_t* indices, int indexCount, const SkPaint& paint) override;
virtual void drawVertices(const SkVertices*, SkBlendMode, const SkPaint& paint) override;
virtual void drawBitmap(Bitmap& bitmap, float left, float top, const SkPaint* paint) override;
virtual void drawBitmap(Bitmap& bitmap, const SkMatrix& matrix, const SkPaint* paint) override;

View File

@@ -183,20 +183,10 @@ void SkiaCanvasProxy::onDrawImageLattice(const SkImage* image, const Lattice& la
void SkiaCanvasProxy::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode bmode,
const SkPaint& paint) {
// TODO: should we pass through blendmode
if (mFilterHwuiCalls) {
return;
}
// convert the SkPoints into floats
static_assert(sizeof(SkPoint) == sizeof(float)*2, "SkPoint is no longer two floats");
const int floatCount = vertices->vertexCount() << 1;
const float* vArray = (const float*)vertices->positions();
const float* tArray = (const float*)vertices->texCoords();
const int* cArray = (const int*)vertices->colors();
// Can remove this cast after changing to SkVertices::VertexMode
SkCanvas::VertexMode vmode = static_cast<SkCanvas::VertexMode>(vertices->mode());
mCanvas->drawVertices(vmode, floatCount, vArray, tArray, cArray,
vertices->indices(), vertices->indexCount(), paint);
mCanvas->drawVertices(vertices, bmode, paint);
}
sk_sp<SkSurface> SkiaCanvasProxy::onNewSurface(const SkImageInfo&, const SkSurfaceProps&) {
@@ -470,19 +460,13 @@ void SkiaCanvasProxy::onDrawPatch(const SkPoint cubics[12], const SkColor colors
if (mFilterHwuiCalls) {
return;
}
SkPatchUtils::VertexData data;
SkMatrix matrix;
mCanvas->getMatrix(&matrix);
SkISize lod = SkPatchUtils::GetLevelOfDetail(cubics, &matrix);
// It automatically adjusts lodX and lodY in case it exceeds the number of indices.
// If it fails to generate the vertices, then we do not draw.
if (SkPatchUtils::getVertexData(&data, cubics, colors, texCoords, lod.width(), lod.height())) {
this->drawVertices(SkCanvas::kTriangles_VertexMode, data.fVertexCount, data.fPoints,
data.fTexCoords, data.fColors, bmode, data.fIndices, data.fIndexCount,
paint);
}
mCanvas->drawVertices(SkPatchUtils::MakeVertices(cubics, colors, texCoords,
lod.width(), lod.height()).get(),
bmode, paint);
}
void SkiaCanvasProxy::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle) {

View File

@@ -486,12 +486,12 @@ void Bitmap::getSkBitmap(SkBitmap* outBitmap) {
return;
}
outBitmap->setInfo(info(), rowBytes());
outBitmap->setPixelRef(this);
outBitmap->setPixelRef(sk_ref_sp(this), 0, 0);
}
void Bitmap::getSkBitmapForShaders(SkBitmap* outBitmap) {
outBitmap->setInfo(info(), rowBytes());
outBitmap->setPixelRef(this);
outBitmap->setPixelRef(sk_ref_sp(this), 0, 0);
outBitmap->setHasHardwareMipMap(mHasHardwareMipMap);
}

View File

@@ -27,6 +27,8 @@
#include <SkCanvas.h>
#include <SkMatrix.h>
class SkVertices;
namespace minikin {
class Layout;
}
@@ -214,9 +216,7 @@ public:
virtual void drawArc(float left, float top, float right, float bottom,
float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) = 0;
virtual void drawPath(const SkPath& path, const SkPaint& paint) = 0;
virtual void drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
const float* verts, const float* tex, const int* colors,
const uint16_t* indices, int indexCount, const SkPaint& paint) = 0;
virtual void drawVertices(const SkVertices*, SkBlendMode, const SkPaint& paint) = 0;
// Bitmap-based
virtual void drawBitmap(Bitmap& bitmap, float left, float top,