diff options
author | 2017-04-04 15:32:04 -0400 | |
---|---|---|
committer | 2017-04-05 14:20:38 +0000 | |
commit | 826deefda55ead0036cdb0924bc14f17d2a85420 (patch) | |
tree | 200ec673d02e096b02a3991f8821816533b863ff | |
parent | 06d6b4d9b0cc895c7d28e56019213800d4d522cf (diff) |
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
-rw-r--r-- | core/jni/android/graphics/BitmapFactory.cpp | 3 | ||||
-rw-r--r-- | core/jni/android/graphics/Graphics.cpp | 3 | ||||
-rw-r--r-- | core/jni/android_graphics_Canvas.cpp | 20 | ||||
-rw-r--r-- | libs/hwui/RecordingCanvas.h | 4 | ||||
-rw-r--r-- | libs/hwui/SkiaCanvas.cpp | 15 | ||||
-rw-r--r-- | libs/hwui/SkiaCanvas.h | 4 | ||||
-rw-r--r-- | libs/hwui/SkiaCanvasProxy.cpp | 24 | ||||
-rw-r--r-- | libs/hwui/hwui/Bitmap.cpp | 4 | ||||
-rw-r--r-- | libs/hwui/hwui/Canvas.h | 6 |
9 files changed, 29 insertions, 54 deletions
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index 3dc1be6a26e3..2ee4dec6a58a 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -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 diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp index e66587a9d8fe..113bc190acf4 100644 --- a/core/jni/android/graphics/Graphics.cpp +++ b/core/jni/android/graphics/Graphics.cpp @@ -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()); diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp index 253daaa51d44..c0f719ed7abe 100644 --- a/core/jni/android_graphics_Canvas.cpp +++ b/core/jni/android_graphics_Canvas.cpp @@ -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, diff --git a/libs/hwui/RecordingCanvas.h b/libs/hwui/RecordingCanvas.h index 682f244659e4..ccdb4b0c1d8e 100644 --- a/libs/hwui/RecordingCanvas.h +++ b/libs/hwui/RecordingCanvas.h @@ -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; diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index d344528c01ef..434e01dc5445 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -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)); diff --git a/libs/hwui/SkiaCanvas.h b/libs/hwui/SkiaCanvas.h index c20c7dbad376..be958c4e655a 100644 --- a/libs/hwui/SkiaCanvas.h +++ b/libs/hwui/SkiaCanvas.h @@ -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; diff --git a/libs/hwui/SkiaCanvasProxy.cpp b/libs/hwui/SkiaCanvasProxy.cpp index 2e5a45ecbae9..34dddd169e96 100644 --- a/libs/hwui/SkiaCanvasProxy.cpp +++ b/libs/hwui/SkiaCanvasProxy.cpp @@ -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) { diff --git a/libs/hwui/hwui/Bitmap.cpp b/libs/hwui/hwui/Bitmap.cpp index eed5b242c1d2..7a8019a629c4 100644 --- a/libs/hwui/hwui/Bitmap.cpp +++ b/libs/hwui/hwui/Bitmap.cpp @@ -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); } diff --git a/libs/hwui/hwui/Canvas.h b/libs/hwui/hwui/Canvas.h index d6456006bd3e..ab768cf34d44 100644 --- a/libs/hwui/hwui/Canvas.h +++ b/libs/hwui/hwui/Canvas.h @@ -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, |