Merge "Fix fading edge effect from impacting neighboring pixels" into qt-dev am: 9fdd35e9aa
am: a538b561fb
Change-Id: Ibee5ae82eba94822f0526890e785cb0124100d63
This commit is contained in:
@@ -22024,23 +22024,27 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
|||||||
}
|
}
|
||||||
|
|
||||||
saveCount = canvas.getSaveCount();
|
saveCount = canvas.getSaveCount();
|
||||||
|
int topSaveCount = -1;
|
||||||
|
int bottomSaveCount = -1;
|
||||||
|
int leftSaveCount = -1;
|
||||||
|
int rightSaveCount = -1;
|
||||||
|
|
||||||
int solidColor = getSolidColor();
|
int solidColor = getSolidColor();
|
||||||
if (solidColor == 0) {
|
if (solidColor == 0) {
|
||||||
if (drawTop) {
|
if (drawTop) {
|
||||||
canvas.saveUnclippedLayer(left, top, right, top + length);
|
topSaveCount = canvas.saveUnclippedLayer(left, top, right, top + length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drawBottom) {
|
if (drawBottom) {
|
||||||
canvas.saveUnclippedLayer(left, bottom - length, right, bottom);
|
bottomSaveCount = canvas.saveUnclippedLayer(left, bottom - length, right, bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drawLeft) {
|
if (drawLeft) {
|
||||||
canvas.saveUnclippedLayer(left, top, left + length, bottom);
|
leftSaveCount = canvas.saveUnclippedLayer(left, top, left + length, bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drawRight) {
|
if (drawRight) {
|
||||||
canvas.saveUnclippedLayer(right - length, top, right, bottom);
|
rightSaveCount = canvas.saveUnclippedLayer(right - length, top, right, bottom);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
scrollabilityCache.setFadeColor(solidColor);
|
scrollabilityCache.setFadeColor(solidColor);
|
||||||
@@ -22057,21 +22061,19 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
|||||||
final Matrix matrix = scrollabilityCache.matrix;
|
final Matrix matrix = scrollabilityCache.matrix;
|
||||||
final Shader fade = scrollabilityCache.shader;
|
final Shader fade = scrollabilityCache.shader;
|
||||||
|
|
||||||
if (drawTop) {
|
// must be restored in the reverse order that they were saved
|
||||||
matrix.setScale(1, fadeHeight * topFadeStrength);
|
if (drawRight) {
|
||||||
matrix.postTranslate(left, top);
|
matrix.setScale(1, fadeHeight * rightFadeStrength);
|
||||||
|
matrix.postRotate(90);
|
||||||
|
matrix.postTranslate(right, top);
|
||||||
fade.setLocalMatrix(matrix);
|
fade.setLocalMatrix(matrix);
|
||||||
p.setShader(fade);
|
p.setShader(fade);
|
||||||
canvas.drawRect(left, top, right, top + length, p);
|
if (solidColor == 0) {
|
||||||
}
|
canvas.restoreUnclippedLayer(rightSaveCount, p);
|
||||||
|
|
||||||
if (drawBottom) {
|
} else {
|
||||||
matrix.setScale(1, fadeHeight * bottomFadeStrength);
|
canvas.drawRect(right - length, top, right, bottom, p);
|
||||||
matrix.postRotate(180);
|
}
|
||||||
matrix.postTranslate(left, bottom);
|
|
||||||
fade.setLocalMatrix(matrix);
|
|
||||||
p.setShader(fade);
|
|
||||||
canvas.drawRect(left, bottom - length, right, bottom, p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drawLeft) {
|
if (drawLeft) {
|
||||||
@@ -22080,16 +22082,36 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
|||||||
matrix.postTranslate(left, top);
|
matrix.postTranslate(left, top);
|
||||||
fade.setLocalMatrix(matrix);
|
fade.setLocalMatrix(matrix);
|
||||||
p.setShader(fade);
|
p.setShader(fade);
|
||||||
|
if (solidColor == 0) {
|
||||||
|
canvas.restoreUnclippedLayer(leftSaveCount, p);
|
||||||
|
} else {
|
||||||
canvas.drawRect(left, top, left + length, bottom, p);
|
canvas.drawRect(left, top, left + length, bottom, p);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (drawRight) {
|
if (drawBottom) {
|
||||||
matrix.setScale(1, fadeHeight * rightFadeStrength);
|
matrix.setScale(1, fadeHeight * bottomFadeStrength);
|
||||||
matrix.postRotate(90);
|
matrix.postRotate(180);
|
||||||
matrix.postTranslate(right, top);
|
matrix.postTranslate(left, bottom);
|
||||||
fade.setLocalMatrix(matrix);
|
fade.setLocalMatrix(matrix);
|
||||||
p.setShader(fade);
|
p.setShader(fade);
|
||||||
canvas.drawRect(right - length, top, right, bottom, p);
|
if (solidColor == 0) {
|
||||||
|
canvas.restoreUnclippedLayer(bottomSaveCount, p);
|
||||||
|
} else {
|
||||||
|
canvas.drawRect(left, bottom - length, right, bottom, p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drawTop) {
|
||||||
|
matrix.setScale(1, fadeHeight * topFadeStrength);
|
||||||
|
matrix.postTranslate(left, top);
|
||||||
|
fade.setLocalMatrix(matrix);
|
||||||
|
p.setShader(fade);
|
||||||
|
if (solidColor == 0) {
|
||||||
|
canvas.restoreUnclippedLayer(topSaveCount, p);
|
||||||
|
} else {
|
||||||
|
canvas.drawRect(left, top, right, top + length, p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas.restoreToCount(saveCount);
|
canvas.restoreToCount(saveCount);
|
||||||
|
|||||||
@@ -106,6 +106,11 @@ static jint saveUnclippedLayer(jlong canvasHandle, jint l, jint t, jint r, jint
|
|||||||
return reinterpret_cast<jint>(get_canvas(canvasHandle)->saveUnclippedLayer(l, t, r, b));
|
return reinterpret_cast<jint>(get_canvas(canvasHandle)->saveUnclippedLayer(l, t, r, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void restoreUnclippedLayer(jlong canvasHandle, jint saveCount, jlong paintHandle) {
|
||||||
|
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
|
||||||
|
get_canvas(canvasHandle)->restoreUnclippedLayer(saveCount, *paint);
|
||||||
|
}
|
||||||
|
|
||||||
static bool restore(jlong canvasHandle) {
|
static bool restore(jlong canvasHandle) {
|
||||||
Canvas* canvas = get_canvas(canvasHandle);
|
Canvas* canvas = get_canvas(canvasHandle);
|
||||||
if (canvas->getSaveCount() <= 1) {
|
if (canvas->getSaveCount() <= 1) {
|
||||||
@@ -668,6 +673,7 @@ static const JNINativeMethod gMethods[] = {
|
|||||||
{"nSaveLayer","(JFFFFJI)I", (void*) CanvasJNI::saveLayer},
|
{"nSaveLayer","(JFFFFJI)I", (void*) CanvasJNI::saveLayer},
|
||||||
{"nSaveLayerAlpha","(JFFFFII)I", (void*) CanvasJNI::saveLayerAlpha},
|
{"nSaveLayerAlpha","(JFFFFII)I", (void*) CanvasJNI::saveLayerAlpha},
|
||||||
{"nSaveUnclippedLayer","(JIIII)I", (void*) CanvasJNI::saveUnclippedLayer},
|
{"nSaveUnclippedLayer","(JIIII)I", (void*) CanvasJNI::saveUnclippedLayer},
|
||||||
|
{"nRestoreUnclippedLayer","(JIJ)V", (void*) CanvasJNI::restoreUnclippedLayer},
|
||||||
{"nGetSaveCount","(J)I", (void*) CanvasJNI::getSaveCount},
|
{"nGetSaveCount","(J)I", (void*) CanvasJNI::getSaveCount},
|
||||||
{"nRestore","(J)Z", (void*) CanvasJNI::restore},
|
{"nRestore","(J)Z", (void*) CanvasJNI::restore},
|
||||||
{"nRestoreToCount","(JI)V", (void*) CanvasJNI::restoreToCount},
|
{"nRestoreToCount","(JI)V", (void*) CanvasJNI::restoreToCount},
|
||||||
|
|||||||
@@ -558,6 +558,16 @@ public class Canvas extends BaseCanvas {
|
|||||||
return nSaveUnclippedLayer(mNativeCanvasWrapper, left, top, right, bottom);
|
return nSaveUnclippedLayer(mNativeCanvasWrapper, left, top, right, bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
* @param saveCount The save level to restore to.
|
||||||
|
* @param paint This is copied and is applied to the area within the unclipped layer's
|
||||||
|
* bounds (i.e. equivalent to a drawPaint()) before restore() is called.
|
||||||
|
*/
|
||||||
|
public void restoreUnclippedLayer(int saveCount, Paint paint) {
|
||||||
|
nRestoreUnclippedLayer(mNativeCanvasWrapper, saveCount, paint.getNativeInstance());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper version of saveLayer() that takes 4 values rather than a RectF.
|
* Helper version of saveLayer() that takes 4 values rather than a RectF.
|
||||||
*
|
*
|
||||||
@@ -1398,6 +1408,9 @@ public class Canvas extends BaseCanvas {
|
|||||||
@CriticalNative
|
@CriticalNative
|
||||||
private static native int nSaveUnclippedLayer(long nativeCanvas, int l, int t, int r, int b);
|
private static native int nSaveUnclippedLayer(long nativeCanvas, int l, int t, int r, int b);
|
||||||
@CriticalNative
|
@CriticalNative
|
||||||
|
private static native void nRestoreUnclippedLayer(long nativeCanvas, int saveCount,
|
||||||
|
long nativePaint);
|
||||||
|
@CriticalNative
|
||||||
private static native boolean nRestore(long canvasHandle);
|
private static native boolean nRestore(long canvasHandle);
|
||||||
@CriticalNative
|
@CriticalNative
|
||||||
private static native void nRestoreToCount(long canvasHandle, int saveCount);
|
private static native void nRestoreToCount(long canvasHandle, int saveCount);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ X(ClipRect)
|
|||||||
X(ClipRRect)
|
X(ClipRRect)
|
||||||
X(ClipRegion)
|
X(ClipRegion)
|
||||||
X(DrawPaint)
|
X(DrawPaint)
|
||||||
|
X(DrawBehind)
|
||||||
X(DrawPath)
|
X(DrawPath)
|
||||||
X(DrawRect)
|
X(DrawRect)
|
||||||
X(DrawRegion)
|
X(DrawRegion)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "SkAndroidFrameworkUtils.h"
|
#include "SkAndroidFrameworkUtils.h"
|
||||||
#include "SkCanvas.h"
|
#include "SkCanvas.h"
|
||||||
|
#include "SkCanvasPriv.h"
|
||||||
#include "SkData.h"
|
#include "SkData.h"
|
||||||
#include "SkDrawShadowInfo.h"
|
#include "SkDrawShadowInfo.h"
|
||||||
#include "SkImage.h"
|
#include "SkImage.h"
|
||||||
@@ -187,6 +188,12 @@ struct DrawPaint final : Op {
|
|||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
void draw(SkCanvas* c, const SkMatrix&) const { c->drawPaint(paint); }
|
void draw(SkCanvas* c, const SkMatrix&) const { c->drawPaint(paint); }
|
||||||
};
|
};
|
||||||
|
struct DrawBehind final : Op {
|
||||||
|
static const auto kType = Type::DrawBehind;
|
||||||
|
DrawBehind(const SkPaint& paint) : paint(paint) {}
|
||||||
|
SkPaint paint;
|
||||||
|
void draw(SkCanvas* c, const SkMatrix&) const { SkCanvasPriv::DrawBehind(c, paint); }
|
||||||
|
};
|
||||||
struct DrawPath final : Op {
|
struct DrawPath final : Op {
|
||||||
static const auto kType = Type::DrawPath;
|
static const auto kType = Type::DrawPath;
|
||||||
DrawPath(const SkPath& path, const SkPaint& paint) : path(path), paint(paint) {}
|
DrawPath(const SkPath& path, const SkPaint& paint) : path(path), paint(paint) {}
|
||||||
@@ -565,6 +572,9 @@ void DisplayListData::clipRegion(const SkRegion& region, SkClipOp op) {
|
|||||||
void DisplayListData::drawPaint(const SkPaint& paint) {
|
void DisplayListData::drawPaint(const SkPaint& paint) {
|
||||||
this->push<DrawPaint>(0, paint);
|
this->push<DrawPaint>(0, paint);
|
||||||
}
|
}
|
||||||
|
void DisplayListData::drawBehind(const SkPaint& paint) {
|
||||||
|
this->push<DrawBehind>(0, paint);
|
||||||
|
}
|
||||||
void DisplayListData::drawPath(const SkPath& path, const SkPaint& paint) {
|
void DisplayListData::drawPath(const SkPath& path, const SkPaint& paint) {
|
||||||
this->push<DrawPath>(0, path, paint);
|
this->push<DrawPath>(0, path, paint);
|
||||||
}
|
}
|
||||||
@@ -834,6 +844,9 @@ void RecordingCanvas::onClipRegion(const SkRegion& region, SkClipOp op) {
|
|||||||
void RecordingCanvas::onDrawPaint(const SkPaint& paint) {
|
void RecordingCanvas::onDrawPaint(const SkPaint& paint) {
|
||||||
fDL->drawPaint(paint);
|
fDL->drawPaint(paint);
|
||||||
}
|
}
|
||||||
|
void RecordingCanvas::onDrawBehind(const SkPaint& paint) {
|
||||||
|
fDL->drawBehind(paint);
|
||||||
|
}
|
||||||
void RecordingCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
|
void RecordingCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
|
||||||
fDL->drawPath(path, paint);
|
fDL->drawPath(path, paint);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ private:
|
|||||||
void clipRegion(const SkRegion&, SkClipOp);
|
void clipRegion(const SkRegion&, SkClipOp);
|
||||||
|
|
||||||
void drawPaint(const SkPaint&);
|
void drawPaint(const SkPaint&);
|
||||||
|
void drawBehind(const SkPaint&);
|
||||||
void drawPath(const SkPath&, const SkPaint&);
|
void drawPath(const SkPath&, const SkPaint&);
|
||||||
void drawRect(const SkRect&, const SkPaint&);
|
void drawRect(const SkRect&, const SkPaint&);
|
||||||
void drawRegion(const SkRegion&, const SkPaint&);
|
void drawRegion(const SkRegion&, const SkPaint&);
|
||||||
@@ -157,6 +158,7 @@ public:
|
|||||||
void onClipRegion(const SkRegion&, SkClipOp) override;
|
void onClipRegion(const SkRegion&, SkClipOp) override;
|
||||||
|
|
||||||
void onDrawPaint(const SkPaint&) override;
|
void onDrawPaint(const SkPaint&) override;
|
||||||
|
void onDrawBehind(const SkPaint&) override;
|
||||||
void onDrawPath(const SkPath&, const SkPaint&) override;
|
void onDrawPath(const SkPath&, const SkPaint&) override;
|
||||||
void onDrawRect(const SkRect&, const SkPaint&) override;
|
void onDrawRect(const SkRect&, const SkPaint&) override;
|
||||||
void onDrawRegion(const SkRegion&, const SkPaint&) override;
|
void onDrawRegion(const SkRegion&, const SkPaint&) override;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <SkAndroidFrameworkUtils.h>
|
#include <SkAndroidFrameworkUtils.h>
|
||||||
#include <SkAnimatedImage.h>
|
#include <SkAnimatedImage.h>
|
||||||
|
#include <SkCanvasPriv.h>
|
||||||
#include <SkCanvasStateUtils.h>
|
#include <SkCanvasStateUtils.h>
|
||||||
#include <SkColorFilter.h>
|
#include <SkColorFilter.h>
|
||||||
#include <SkDeque.h>
|
#include <SkDeque.h>
|
||||||
@@ -191,6 +192,18 @@ int SkiaCanvas::saveUnclippedLayer(int left, int top, int right, int bottom) {
|
|||||||
return SkAndroidFrameworkUtils::SaveBehind(mCanvas, &bounds);
|
return SkAndroidFrameworkUtils::SaveBehind(mCanvas, &bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SkiaCanvas::restoreUnclippedLayer(int restoreCount, const SkPaint& paint) {
|
||||||
|
|
||||||
|
while (mCanvas->getSaveCount() > restoreCount + 1) {
|
||||||
|
this->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mCanvas->getSaveCount() == restoreCount + 1) {
|
||||||
|
SkCanvasPriv::DrawBehind(mCanvas, *filterPaint(paint));
|
||||||
|
this->restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SkiaCanvas::Clip {
|
class SkiaCanvas::Clip {
|
||||||
public:
|
public:
|
||||||
Clip(const SkRect& rect, SkClipOp op, const SkMatrix& m)
|
Clip(const SkRect& rect, SkClipOp op, const SkMatrix& m)
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ public:
|
|||||||
virtual int save(SaveFlags::Flags flags) override;
|
virtual int save(SaveFlags::Flags flags) override;
|
||||||
virtual void restore() override;
|
virtual void restore() override;
|
||||||
virtual void restoreToCount(int saveCount) override;
|
virtual void restoreToCount(int saveCount) override;
|
||||||
|
virtual void restoreUnclippedLayer(int saveCount, const SkPaint& paint) override;
|
||||||
|
|
||||||
virtual int saveLayer(float left, float top, float right, float bottom, const SkPaint* paint,
|
virtual int saveLayer(float left, float top, float right, float bottom, const SkPaint* paint,
|
||||||
SaveFlags::Flags flags) override;
|
SaveFlags::Flags flags) override;
|
||||||
|
|||||||
@@ -191,6 +191,7 @@ public:
|
|||||||
virtual int save(SaveFlags::Flags flags) = 0;
|
virtual int save(SaveFlags::Flags flags) = 0;
|
||||||
virtual void restore() = 0;
|
virtual void restore() = 0;
|
||||||
virtual void restoreToCount(int saveCount) = 0;
|
virtual void restoreToCount(int saveCount) = 0;
|
||||||
|
virtual void restoreUnclippedLayer(int saveCount, const SkPaint& paint) = 0;
|
||||||
|
|
||||||
virtual int saveLayer(float left, float top, float right, float bottom, const SkPaint* paint,
|
virtual int saveLayer(float left, float top, float right, float bottom, const SkPaint* paint,
|
||||||
SaveFlags::Flags flags) = 0;
|
SaveFlags::Flags flags) = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user