Loading libs/hwui/RecordingCanvas.cpp +6 −3 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ #include "RecordingCanvas.h" #include <hwui/Paint.h> #include <GrRecordingContext.h> Loading Loading @@ -495,7 +496,7 @@ struct DrawVectorDrawable final : Op { sp<VectorDrawableRoot> mRoot; SkRect mBounds; SkPaint paint; Paint paint; BitmapPalette palette; }; Loading Loading @@ -833,7 +834,8 @@ constexpr color_transform_fn colorTransformForOp() { // TODO: We should be const. Or not. Or just use a different map // Unclear, but this is the quick fix const T* op = reinterpret_cast<const T*>(opRaw); transformPaint(transform, const_cast<SkPaint*>(&(op->paint)), op->palette); const SkPaint* paint = &op->paint; transformPaint(transform, const_cast<SkPaint*>(paint), op->palette); }; } else if Loading @@ -842,7 +844,8 @@ constexpr color_transform_fn colorTransformForOp() { // TODO: We should be const. Or not. Or just use a different map // Unclear, but this is the quick fix const T* op = reinterpret_cast<const T*>(opRaw); transformPaint(transform, const_cast<SkPaint*>(&(op->paint))); const SkPaint* paint = &op->paint; transformPaint(transform, const_cast<SkPaint*>(paint)); }; } else { Loading libs/hwui/SkiaCanvas.cpp +15 −24 Original line number Diff line number Diff line Loading @@ -182,7 +182,7 @@ int SkiaCanvas::saveUnclippedLayer(int left, int top, int right, int bottom) { return SkAndroidFrameworkUtils::SaveBehind(mCanvas, &bounds); } void SkiaCanvas::restoreUnclippedLayer(int restoreCount, const SkPaint& paint) { void SkiaCanvas::restoreUnclippedLayer(int restoreCount, const Paint& paint) { while (mCanvas->getSaveCount() > restoreCount + 1) { this->restore(); Loading Loading @@ -439,13 +439,13 @@ void SkiaCanvas::drawColor(int color, SkBlendMode mode) { mCanvas->drawColor(color, mode); } void SkiaCanvas::onFilterPaint(SkPaint& paint) { void SkiaCanvas::onFilterPaint(Paint& paint) { if (mPaintFilter) { mPaintFilter->filter(&paint); mPaintFilter->filterFullPaint(&paint); } } void SkiaCanvas::drawPaint(const SkPaint& paint) { void SkiaCanvas::drawPaint(const Paint& paint) { mCanvas->drawPaint(filterPaint(paint)); } Loading Loading @@ -552,9 +552,8 @@ void SkiaCanvas::drawVertices(const SkVertices* vertices, SkBlendMode mode, cons void SkiaCanvas::drawBitmap(Bitmap& bitmap, float left, float top, const Paint* paint) { auto image = bitmap.makeImage(); applyLooper(paint, [&](const SkPaint& p) { auto sampling = SkSamplingOptions(p.getFilterQuality()); mCanvas->drawImage(image, left, top, sampling, &p); applyLooper(paint, [&](const Paint& p) { mCanvas->drawImage(image, left, top, p.sampling(), &p); }); } Loading @@ -562,9 +561,8 @@ void SkiaCanvas::drawBitmap(Bitmap& bitmap, const SkMatrix& matrix, const Paint* auto image = bitmap.makeImage(); SkAutoCanvasRestore acr(mCanvas, true); mCanvas->concat(matrix); applyLooper(paint, [&](const SkPaint& p) { auto sampling = SkSamplingOptions(p.getFilterQuality()); mCanvas->drawImage(image, 0, 0, sampling, &p); applyLooper(paint, [&](const Paint& p) { mCanvas->drawImage(image, 0, 0, p.sampling(), &p); }); } Loading @@ -575,18 +573,12 @@ void SkiaCanvas::drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop, float s SkRect srcRect = SkRect::MakeLTRB(srcLeft, srcTop, srcRight, srcBottom); SkRect dstRect = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom); applyLooper(paint, [&](const SkPaint& p) { auto sampling = SkSamplingOptions(p.getFilterQuality()); mCanvas->drawImageRect(image, srcRect, dstRect, sampling, &p, applyLooper(paint, [&](const Paint& p) { mCanvas->drawImageRect(image, srcRect, dstRect, p.sampling(), &p, SkCanvas::kFast_SrcRectConstraint); }); } static SkFilterMode paintToFilter(const Paint* paint) { return paint && paint->isFilterBitmap() ? SkFilterMode::kLinear : SkFilterMode::kNearest; } void SkiaCanvas::drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight, const float* vertices, const int* colors, const Paint* paint) { const int ptCount = (meshWidth + 1) * (meshHeight + 1); Loading Loading @@ -668,13 +660,13 @@ void SkiaCanvas::drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight, if (paint) { pnt = *paint; } SkSamplingOptions sampling(paintToFilter(&pnt)); SkSamplingOptions sampling = pnt.sampling(); pnt.setShader(image->makeShader(sampling)); auto v = builder.detach(); applyLooper(&pnt, [&](const SkPaint& p) { applyLooper(&pnt, [&](const Paint& p) { SkPaint copy(p); auto s = SkSamplingOptions(p.getFilterQuality()); auto s = p.sampling(); if (s != sampling) { // applyLooper changed the quality? copy.setShader(image->makeShader(s)); Loading Loading @@ -707,9 +699,8 @@ void SkiaCanvas::drawNinePatch(Bitmap& bitmap, const Res_png_9patch& chunk, floa lattice.fBounds = nullptr; SkRect dst = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom); auto image = bitmap.makeImage(); applyLooper(paint, [&](const SkPaint& p) { auto filter = SkSamplingOptions(p.getFilterQuality()).filter; mCanvas->drawImageLattice(image.get(), lattice, dst, filter, &p); applyLooper(paint, [&](const Paint& p) { mCanvas->drawImageLattice(image.get(), lattice, dst, p.filterMode(), &p); }); } Loading libs/hwui/SkiaCanvas.h +11 −11 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include "VectorDrawable.h" #include "hwui/Canvas.h" #include "hwui/Paint.h" #include "hwui/BlurDrawLooper.h" #include <SkCanvas.h> #include "pipeline/skia/AnimatedDrawables.h" Loading Loading @@ -73,7 +74,7 @@ public: virtual int save(SaveFlags::Flags flags) override; virtual void restore() override; virtual void restoreToCount(int saveCount) override; virtual void restoreUnclippedLayer(int saveCount, const SkPaint& paint) override; virtual void restoreUnclippedLayer(int saveCount, const Paint& paint) override; virtual int saveLayer(float left, float top, float right, float bottom, const SkPaint* paint) override; virtual int saveLayerAlpha(float left, float top, float right, float bottom, int alpha) override; Loading @@ -99,7 +100,7 @@ public: virtual SkCanvasState* captureCanvasState() const override; virtual void drawColor(int color, SkBlendMode mode) override; virtual void drawPaint(const SkPaint& paint) override; virtual void drawPaint(const Paint& paint) override; virtual void drawPoint(float x, float y, const Paint& paint) override; virtual void drawPoints(const float* points, int count, const Paint& paint) override; Loading Loading @@ -167,10 +168,10 @@ protected: const Paint& paint, const SkPath& path, size_t start, size_t end) override; void onFilterPaint(SkPaint& paint); void onFilterPaint(Paint& paint); SkPaint filterPaint(const SkPaint& src) { SkPaint dst(src); Paint filterPaint(const Paint& src) { Paint dst(src); this->onFilterPaint(dst); return dst; } Loading @@ -179,21 +180,20 @@ protected: template <typename Proc> void applyLooper(const Paint* paint, Proc proc, void (*preFilter)(SkPaint&) = nullptr) { BlurDrawLooper* looper = paint ? paint->getLooper() : nullptr; const SkPaint* skpPtr = paint; SkPaint skp = skpPtr ? *skpPtr : SkPaint(); Paint pnt = paint ? *paint : Paint(); if (preFilter) { preFilter(skp); preFilter(pnt); } this->onFilterPaint(skp); this->onFilterPaint(pnt); if (looper) { looper->apply(skp, [&](SkPoint offset, const SkPaint& modifiedPaint) { looper->apply(pnt, [&](SkPoint offset, const Paint& modifiedPaint) { mCanvas->save(); mCanvas->translate(offset.fX, offset.fY); proc(modifiedPaint); mCanvas->restore(); }); } else { proc(skp); proc(pnt); } } Loading libs/hwui/VectorDrawable.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -463,10 +463,10 @@ void Tree::drawStaging(Canvas* outCanvas) { mStagingCache.dirty = false; } SkPaint skp; Paint skp; getPaintFor(&skp, mStagingProperties); Paint paint; paint.setFilterQuality(skp.getFilterQuality()); paint.setFilterBitmap(skp.isFilterBitmap()); paint.setColorFilter(skp.refColorFilter()); paint.setAlpha(skp.getAlpha()); outCanvas->drawBitmap(*mStagingCache.bitmap, 0, 0, mStagingCache.bitmap->width(), Loading @@ -476,9 +476,9 @@ void Tree::drawStaging(Canvas* outCanvas) { mStagingProperties.getBounds().bottom(), &paint); } void Tree::getPaintFor(SkPaint* outPaint, const TreeProperties& prop) const { void Tree::getPaintFor(Paint* outPaint, const TreeProperties& prop) const { // HWUI always draws VD with bilinear filtering. outPaint->setFilterQuality(kLow_SkFilterQuality); outPaint->setFilterBitmap(true); if (prop.getColorFilter() != nullptr) { outPaint->setColorFilter(sk_ref_sp(prop.getColorFilter())); } Loading libs/hwui/VectorDrawable.h +1 −1 Original line number Diff line number Diff line Loading @@ -648,7 +648,7 @@ public: */ void draw(SkCanvas* canvas, const SkRect& bounds, const SkPaint& paint); void getPaintFor(SkPaint* outPaint, const TreeProperties &props) const; void getPaintFor(Paint* outPaint, const TreeProperties &props) const; BitmapPalette computePalette(); void setAntiAlias(bool aa) { mRootNode->setAntiAlias(aa); } Loading Loading
libs/hwui/RecordingCanvas.cpp +6 −3 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ #include "RecordingCanvas.h" #include <hwui/Paint.h> #include <GrRecordingContext.h> Loading Loading @@ -495,7 +496,7 @@ struct DrawVectorDrawable final : Op { sp<VectorDrawableRoot> mRoot; SkRect mBounds; SkPaint paint; Paint paint; BitmapPalette palette; }; Loading Loading @@ -833,7 +834,8 @@ constexpr color_transform_fn colorTransformForOp() { // TODO: We should be const. Or not. Or just use a different map // Unclear, but this is the quick fix const T* op = reinterpret_cast<const T*>(opRaw); transformPaint(transform, const_cast<SkPaint*>(&(op->paint)), op->palette); const SkPaint* paint = &op->paint; transformPaint(transform, const_cast<SkPaint*>(paint), op->palette); }; } else if Loading @@ -842,7 +844,8 @@ constexpr color_transform_fn colorTransformForOp() { // TODO: We should be const. Or not. Or just use a different map // Unclear, but this is the quick fix const T* op = reinterpret_cast<const T*>(opRaw); transformPaint(transform, const_cast<SkPaint*>(&(op->paint))); const SkPaint* paint = &op->paint; transformPaint(transform, const_cast<SkPaint*>(paint)); }; } else { Loading
libs/hwui/SkiaCanvas.cpp +15 −24 Original line number Diff line number Diff line Loading @@ -182,7 +182,7 @@ int SkiaCanvas::saveUnclippedLayer(int left, int top, int right, int bottom) { return SkAndroidFrameworkUtils::SaveBehind(mCanvas, &bounds); } void SkiaCanvas::restoreUnclippedLayer(int restoreCount, const SkPaint& paint) { void SkiaCanvas::restoreUnclippedLayer(int restoreCount, const Paint& paint) { while (mCanvas->getSaveCount() > restoreCount + 1) { this->restore(); Loading Loading @@ -439,13 +439,13 @@ void SkiaCanvas::drawColor(int color, SkBlendMode mode) { mCanvas->drawColor(color, mode); } void SkiaCanvas::onFilterPaint(SkPaint& paint) { void SkiaCanvas::onFilterPaint(Paint& paint) { if (mPaintFilter) { mPaintFilter->filter(&paint); mPaintFilter->filterFullPaint(&paint); } } void SkiaCanvas::drawPaint(const SkPaint& paint) { void SkiaCanvas::drawPaint(const Paint& paint) { mCanvas->drawPaint(filterPaint(paint)); } Loading Loading @@ -552,9 +552,8 @@ void SkiaCanvas::drawVertices(const SkVertices* vertices, SkBlendMode mode, cons void SkiaCanvas::drawBitmap(Bitmap& bitmap, float left, float top, const Paint* paint) { auto image = bitmap.makeImage(); applyLooper(paint, [&](const SkPaint& p) { auto sampling = SkSamplingOptions(p.getFilterQuality()); mCanvas->drawImage(image, left, top, sampling, &p); applyLooper(paint, [&](const Paint& p) { mCanvas->drawImage(image, left, top, p.sampling(), &p); }); } Loading @@ -562,9 +561,8 @@ void SkiaCanvas::drawBitmap(Bitmap& bitmap, const SkMatrix& matrix, const Paint* auto image = bitmap.makeImage(); SkAutoCanvasRestore acr(mCanvas, true); mCanvas->concat(matrix); applyLooper(paint, [&](const SkPaint& p) { auto sampling = SkSamplingOptions(p.getFilterQuality()); mCanvas->drawImage(image, 0, 0, sampling, &p); applyLooper(paint, [&](const Paint& p) { mCanvas->drawImage(image, 0, 0, p.sampling(), &p); }); } Loading @@ -575,18 +573,12 @@ void SkiaCanvas::drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop, float s SkRect srcRect = SkRect::MakeLTRB(srcLeft, srcTop, srcRight, srcBottom); SkRect dstRect = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom); applyLooper(paint, [&](const SkPaint& p) { auto sampling = SkSamplingOptions(p.getFilterQuality()); mCanvas->drawImageRect(image, srcRect, dstRect, sampling, &p, applyLooper(paint, [&](const Paint& p) { mCanvas->drawImageRect(image, srcRect, dstRect, p.sampling(), &p, SkCanvas::kFast_SrcRectConstraint); }); } static SkFilterMode paintToFilter(const Paint* paint) { return paint && paint->isFilterBitmap() ? SkFilterMode::kLinear : SkFilterMode::kNearest; } void SkiaCanvas::drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight, const float* vertices, const int* colors, const Paint* paint) { const int ptCount = (meshWidth + 1) * (meshHeight + 1); Loading Loading @@ -668,13 +660,13 @@ void SkiaCanvas::drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight, if (paint) { pnt = *paint; } SkSamplingOptions sampling(paintToFilter(&pnt)); SkSamplingOptions sampling = pnt.sampling(); pnt.setShader(image->makeShader(sampling)); auto v = builder.detach(); applyLooper(&pnt, [&](const SkPaint& p) { applyLooper(&pnt, [&](const Paint& p) { SkPaint copy(p); auto s = SkSamplingOptions(p.getFilterQuality()); auto s = p.sampling(); if (s != sampling) { // applyLooper changed the quality? copy.setShader(image->makeShader(s)); Loading Loading @@ -707,9 +699,8 @@ void SkiaCanvas::drawNinePatch(Bitmap& bitmap, const Res_png_9patch& chunk, floa lattice.fBounds = nullptr; SkRect dst = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom); auto image = bitmap.makeImage(); applyLooper(paint, [&](const SkPaint& p) { auto filter = SkSamplingOptions(p.getFilterQuality()).filter; mCanvas->drawImageLattice(image.get(), lattice, dst, filter, &p); applyLooper(paint, [&](const Paint& p) { mCanvas->drawImageLattice(image.get(), lattice, dst, p.filterMode(), &p); }); } Loading
libs/hwui/SkiaCanvas.h +11 −11 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include "VectorDrawable.h" #include "hwui/Canvas.h" #include "hwui/Paint.h" #include "hwui/BlurDrawLooper.h" #include <SkCanvas.h> #include "pipeline/skia/AnimatedDrawables.h" Loading Loading @@ -73,7 +74,7 @@ public: virtual int save(SaveFlags::Flags flags) override; virtual void restore() override; virtual void restoreToCount(int saveCount) override; virtual void restoreUnclippedLayer(int saveCount, const SkPaint& paint) override; virtual void restoreUnclippedLayer(int saveCount, const Paint& paint) override; virtual int saveLayer(float left, float top, float right, float bottom, const SkPaint* paint) override; virtual int saveLayerAlpha(float left, float top, float right, float bottom, int alpha) override; Loading @@ -99,7 +100,7 @@ public: virtual SkCanvasState* captureCanvasState() const override; virtual void drawColor(int color, SkBlendMode mode) override; virtual void drawPaint(const SkPaint& paint) override; virtual void drawPaint(const Paint& paint) override; virtual void drawPoint(float x, float y, const Paint& paint) override; virtual void drawPoints(const float* points, int count, const Paint& paint) override; Loading Loading @@ -167,10 +168,10 @@ protected: const Paint& paint, const SkPath& path, size_t start, size_t end) override; void onFilterPaint(SkPaint& paint); void onFilterPaint(Paint& paint); SkPaint filterPaint(const SkPaint& src) { SkPaint dst(src); Paint filterPaint(const Paint& src) { Paint dst(src); this->onFilterPaint(dst); return dst; } Loading @@ -179,21 +180,20 @@ protected: template <typename Proc> void applyLooper(const Paint* paint, Proc proc, void (*preFilter)(SkPaint&) = nullptr) { BlurDrawLooper* looper = paint ? paint->getLooper() : nullptr; const SkPaint* skpPtr = paint; SkPaint skp = skpPtr ? *skpPtr : SkPaint(); Paint pnt = paint ? *paint : Paint(); if (preFilter) { preFilter(skp); preFilter(pnt); } this->onFilterPaint(skp); this->onFilterPaint(pnt); if (looper) { looper->apply(skp, [&](SkPoint offset, const SkPaint& modifiedPaint) { looper->apply(pnt, [&](SkPoint offset, const Paint& modifiedPaint) { mCanvas->save(); mCanvas->translate(offset.fX, offset.fY); proc(modifiedPaint); mCanvas->restore(); }); } else { proc(skp); proc(pnt); } } Loading
libs/hwui/VectorDrawable.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -463,10 +463,10 @@ void Tree::drawStaging(Canvas* outCanvas) { mStagingCache.dirty = false; } SkPaint skp; Paint skp; getPaintFor(&skp, mStagingProperties); Paint paint; paint.setFilterQuality(skp.getFilterQuality()); paint.setFilterBitmap(skp.isFilterBitmap()); paint.setColorFilter(skp.refColorFilter()); paint.setAlpha(skp.getAlpha()); outCanvas->drawBitmap(*mStagingCache.bitmap, 0, 0, mStagingCache.bitmap->width(), Loading @@ -476,9 +476,9 @@ void Tree::drawStaging(Canvas* outCanvas) { mStagingProperties.getBounds().bottom(), &paint); } void Tree::getPaintFor(SkPaint* outPaint, const TreeProperties& prop) const { void Tree::getPaintFor(Paint* outPaint, const TreeProperties& prop) const { // HWUI always draws VD with bilinear filtering. outPaint->setFilterQuality(kLow_SkFilterQuality); outPaint->setFilterBitmap(true); if (prop.getColorFilter() != nullptr) { outPaint->setColorFilter(sk_ref_sp(prop.getColorFilter())); } Loading
libs/hwui/VectorDrawable.h +1 −1 Original line number Diff line number Diff line Loading @@ -648,7 +648,7 @@ public: */ void draw(SkCanvas* canvas, const SkRect& bounds, const SkPaint& paint); void getPaintFor(SkPaint* outPaint, const TreeProperties &props) const; void getPaintFor(Paint* outPaint, const TreeProperties &props) const; BitmapPalette computePalette(); void setAntiAlias(bool aa) { mRootNode->setAntiAlias(aa); } Loading