Skip to content

Commit

Permalink
8148129: Implement Accelerated composition for WebView
Browse files Browse the repository at this point in the history
Reviewed-by: kcr, mbilla, arapte
  • Loading branch information
arajkumar committed Sep 5, 2018
1 parent d67a4c3 commit cdb3a30
Show file tree
Hide file tree
Showing 36 changed files with 634 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.sun.javafx.geom.Rectangle;
import com.sun.javafx.geom.Shape;
import com.sun.javafx.geom.transform.BaseTransform;
import com.sun.javafx.geom.transform.GeneralTransform3D;
import com.sun.javafx.scene.text.GlyphList;
import com.sun.javafx.sg.prism.NGCamera;
import com.sun.javafx.sg.prism.NGLightBase;
Expand All @@ -57,6 +58,7 @@ public void setTransform3D(double mxx, double mxy, double mxz, double mxt,
public void scale(float sx, float sy);
public void scale(float sx, float sy, float sz);

public void setPerspectiveTransform(GeneralTransform3D perspectiveTransform);
public void setCamera(NGCamera camera);
public NGCamera getCameraNoClone();
public void setDepthTest(boolean depthTest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,27 @@ protected void updateTexture(int texUnit, Texture tex) {

@Override
protected void updateShaderTransform(Shader shader, BaseTransform xform) {
if (xform == null) {
xform = BaseTransform.IDENTITY_TRANSFORM;
}

final GeneralTransform3D perspectiveTransform = getPerspectiveTransformNoClone();
int res;
if (xform == null || xform.isIdentity()) {
if (xform.isIdentity() && perspectiveTransform.isIdentity()) {
res = nResetTransform(pContext);
} else {
} else if (perspectiveTransform.isIdentity()) {
res = nSetTransform(pContext,
xform.getMxx(), xform.getMxy(), xform.getMxz(), xform.getMxt(),
xform.getMyx(), xform.getMyy(), xform.getMyz(), xform.getMyt(),
xform.getMzx(), xform.getMzy(), xform.getMzz(), xform.getMzt(),
0.0, 0.0, 0.0, 1.0);
} else {
scratchTx.setIdentity().mul(xform).mul(perspectiveTransform);
res = nSetTransform(pContext,
scratchTx.get(0), scratchTx.get(1), scratchTx.get(2), scratchTx.get(3),
scratchTx.get(4), scratchTx.get(5), scratchTx.get(6), scratchTx.get(7),
scratchTx.get(8), scratchTx.get(9), scratchTx.get(10), scratchTx.get(11),
scratchTx.get(12), scratchTx.get(13), scratchTx.get(14), scratchTx.get(15));
}
validate(res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,12 @@ protected void updateShaderTransform(Shader shader, BaseTransform xform) {
}

scratchTx.set(projViewTx);
updateRawMatrix(scratchTx.mul(xform));
final GeneralTransform3D perspectiveTransform = getPerspectiveTransformNoClone();
if (perspectiveTransform.isIdentity()) {
updateRawMatrix(scratchTx.mul(xform));
} else {
updateRawMatrix(scratchTx.mul(xform).mul(perspectiveTransform));
}

ES2Shader es2shader = (ES2Shader) shader;
es2shader.setMatrix("mvpMatrix", rawMatrix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.sun.javafx.font.FontStrike;
import com.sun.javafx.geom.RectBounds;
import com.sun.javafx.geom.transform.BaseTransform;
import com.sun.javafx.geom.transform.GeneralTransform3D;
import com.sun.javafx.image.ByteToBytePixelConverter;
import com.sun.javafx.image.impl.ByteGray;
import com.sun.javafx.sg.prism.NGCamera;
Expand Down Expand Up @@ -70,6 +71,8 @@ public abstract class BaseContext {
private Texture wrapRectTex;
private Texture ovalTex;

private final GeneralTransform3D perspectiveTransform = new GeneralTransform3D();

// TODO: need to dispose these when the context is disposed... (RT-27421)
private final Map<FontStrike, GlyphCache>
greyGlyphCaches = new HashMap<FontStrike, GlyphCache>();
Expand Down Expand Up @@ -119,6 +122,18 @@ public void drawQuads(float coordArray[], byte colorArray[], int numVertices) {
renderQuads(coordArray, colorArray, numVertices);
}

protected GeneralTransform3D getPerspectiveTransformNoClone() {
return perspectiveTransform;
}

protected void setPerspectiveTransform(GeneralTransform3D transform) {
if (transform == null) {
perspectiveTransform.setIdentity();
} else {
perspectiveTransform.set(transform);
}
}

protected abstract void renderQuads(float coordArray[], byte colorArray[], int numVertices);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.sun.javafx.geom.Shape;
import com.sun.javafx.geom.transform.Affine3D;
import com.sun.javafx.geom.transform.BaseTransform;
import com.sun.javafx.geom.transform.GeneralTransform3D;
import com.sun.javafx.sg.prism.NGCamera;
import com.sun.javafx.sg.prism.NodePath;
import com.sun.prism.BasicStroke;
Expand Down Expand Up @@ -137,6 +138,11 @@ public BaseTransform getTransformNoClone() {
return transform3D;
}

@Override
public void setPerspectiveTransform(GeneralTransform3D transform) {
context.setPerspectiveTransform(transform);
}

public void setTransform(BaseTransform transform) {
if (transform == null) {
transform3D.setToIdentity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.sun.javafx.geom.Rectangle;
import com.sun.javafx.geom.transform.Affine3D;
import com.sun.javafx.geom.transform.BaseTransform;
import com.sun.javafx.geom.transform.GeneralTransform3D;
import com.sun.javafx.sg.prism.NGCamera;
import com.sun.prism.CompositeMode;
import com.sun.prism.PixelFormat;
Expand Down Expand Up @@ -193,6 +194,12 @@ public static class State {
private boolean lastState3D = false;
}

@Override
protected void setPerspectiveTransform(GeneralTransform3D transform) {
state.isXformValid = false;
super.setPerspectiveTransform(transform);
}

protected void resetLastClip(State state) {
state.lastClip = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.sun.javafx.geom.Shape;
import com.sun.javafx.geom.transform.Affine2D;
import com.sun.javafx.geom.transform.BaseTransform;
import com.sun.javafx.geom.transform.GeneralTransform3D;
import com.sun.javafx.scene.text.GlyphList;
import com.sun.javafx.sg.prism.NGCamera;
import com.sun.javafx.sg.prism.NGLightBase;
Expand Down Expand Up @@ -1272,6 +1273,10 @@ public NGCamera getCameraNoClone() {
throw new UnsupportedOperationException("Not supported yet.");
}

public void setPerspectiveTransform(GeneralTransform3D transform) {
}


public boolean isDepthBuffer() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.sun.javafx.geom.Shape;
import com.sun.javafx.geom.transform.Affine2D;
import com.sun.javafx.geom.transform.BaseTransform;
import com.sun.javafx.geom.transform.GeneralTransform3D;
import com.sun.javafx.geom.transform.NoninvertibleTransformException;
import com.sun.javafx.scene.text.GlyphList;
import com.sun.javafx.sg.prism.NGCamera;
Expand Down Expand Up @@ -199,6 +200,9 @@ public void scale(float sx, float sy, float sz) {
public void setCamera(NGCamera camera) {
}

public void setPerspectiveTransform(GeneralTransform3D transform) {
}

public NGCamera getCameraNoClone() {
throw new UnsupportedOperationException("getCameraNoClone: unimp");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.sun.prism.Graphics;
import com.sun.scenario.effect.DropShadow;
import com.sun.webkit.graphics.WCImage;
import com.sun.webkit.graphics.WCTransform;

final class WCBufferedContext extends WCGraphicsPrismContext {

Expand Down Expand Up @@ -203,6 +204,11 @@ private boolean trIntersectsClip(RectBounds bounds, BaseTransform tx) {
super.saveState();
}

@Override public void setTransform(WCTransform tm) {
init();
super.setTransform(tm);
}

private void init() {
if (!isInitialized) {
BaseTransform t = PrismGraphicsManager.getPixelScaleTransform();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.sun.javafx.geom.transform.Affine2D;
import com.sun.javafx.geom.transform.Affine3D;
import com.sun.javafx.geom.transform.BaseTransform;
import com.sun.javafx.geom.transform.GeneralTransform3D;
import com.sun.javafx.logging.PlatformLogger;
import com.sun.javafx.logging.PlatformLogger.Level;
import com.sun.javafx.scene.text.GlyphList;
Expand Down Expand Up @@ -516,7 +517,9 @@ public void fillRect(final float x, final float y, final float w, final float h,
@Override void doPaint(Graphics g) {
Paint paint = (rgba != null) ? createColor(rgba) : state.getPaintNoClone();
DropShadow shadow = state.getShadowNoClone();
if (shadow != null) {
// TextureMapperJava::drawSolidColor calls fillRect with perspective
// projection.
if (shadow != null || !state.getPerspectiveTransformNoClone().isIdentity()) {
final NGRectangle node = new NGRectangle();
node.updateRectangle(x, y, w, h, 0, 0);
render(g, shadow, paint, null, node);
Expand Down Expand Up @@ -1181,6 +1184,7 @@ private static final class ContextState {

private DropShadow shadow;
private Affine3D xform;
private GeneralTransform3D perspectiveTransform;
private Layer layer;
private int compositeOperation;

Expand All @@ -1190,6 +1194,7 @@ private ContextState() {
stroke.setPaint(Color.BLACK);
alpha = 1.0f;
xform = new Affine3D();
perspectiveTransform = new GeneralTransform3D();
compositeOperation = COMPOSITE_SOURCE_OVER;
}

Expand All @@ -1201,6 +1206,7 @@ private ContextState(ContextState state) {
clip = new Rectangle(clip);
}
xform = new Affine3D(state.getTransformNoClone());
perspectiveTransform = new GeneralTransform3D().set(state.getPerspectiveTransformNoClone());
setShadow(state.getShadowNoClone());
setLayer(state.getLayerNoClone());
setAlpha(state.getAlpha());
Expand All @@ -1214,8 +1220,8 @@ protected ContextState clone() {
}

private void apply(Graphics g) {
//TODO: Verify if we need to apply more properties from state
g.setTransform(getTransformNoClone());
g.setPerspectiveTransform(getPerspectiveTransformNoClone());
g.setClipRect(getClipNoClone());
g.setExtraAlpha(getAlpha());
}
Expand Down Expand Up @@ -1310,10 +1316,18 @@ private Affine3D getTransformNoClone() {
return xform;
}

private GeneralTransform3D getPerspectiveTransformNoClone() {
return perspectiveTransform;
}

private void setTransform(final Affine3D at) {
this.xform.setTransform(at);
}

private void setPerspectiveTransform(final GeneralTransform3D gt) {
this.perspectiveTransform.set(gt);
}

private void concatTransform(Affine3D at) {
xform.concatenate(at);
}
Expand Down Expand Up @@ -1790,9 +1804,15 @@ public void fillPath(final WCPath path) {
}
}

public void setPerspectiveTransform(WCTransform tm) {
final GeneralTransform3D at = new GeneralTransform3D().set(tm.getMatrix());
state.setPerspectiveTransform(at);
resetCachedGraphics();
}

public void setTransform(WCTransform tm) {
double m[] = tm.getMatrix();
Affine3D at = new Affine3D(new Affine2D(m[0], m[1], m[2], m[3], m[4], m[5]));
final double m[] = tm.getMatrix();
final Affine3D at = new Affine3D(new Affine2D(m[0], m[1], m[2], m[3], m[4], m[5]));
if (state.getLayerNoClone() == null) {
at.preConcatenate(baseTransform);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.sun.prism.ResourceFactoryListener;
import com.sun.prism.Texture;
import com.sun.prism.paint.Color;
import com.sun.webkit.graphics.WCCamera;
import com.sun.webkit.graphics.WCGraphicsContext;
import com.sun.webkit.graphics.WCGraphicsManager;
import com.sun.webkit.graphics.WCPageBackBuffer;
Expand All @@ -54,6 +55,8 @@ private static RTTexture createTexture(int w, int h) {

public WCGraphicsContext createGraphics() {
Graphics g = texture.createGraphics();
// Make use of custom camera created for WebKit.
g.setCamera(WCCamera.INSTANCE);
g.scale(pixelScale, pixelScale);
return WCGraphicsManager.getGraphicsManager().createGraphicsContext(g);
}
Expand Down
11 changes: 9 additions & 2 deletions modules/javafx.web/src/main/java/com/sun/webkit/WebPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package com.sun.webkit;

import javafx.application.ConditionalFeature;
import javafx.application.Platform;
import com.sun.glass.utils.NativeLibLoader;
import com.sun.javafx.logging.PlatformLogger;
import com.sun.javafx.logging.PlatformLogger.Level;
Expand Down Expand Up @@ -145,8 +147,13 @@ public final class WebPage {
final boolean useDFGJIT = Boolean.valueOf(System.getProperty(
"com.sun.webkit.useDFGJIT", "true"));

// TODO: Enable CSS3D by default once it is stabilized.
boolean useCSS3D = Boolean.valueOf(System.getProperty(
"com.sun.webkit.useCSS3D", "false"));
useCSS3D = useCSS3D && Platform.isSupported(ConditionalFeature.SCENE3D);

// Initialize WTF, WebCore and JavaScriptCore.
twkInitWebCore(useJIT, useDFGJIT);
twkInitWebCore(useJIT, useDFGJIT, useCSS3D);
return null;
});

Expand Down Expand Up @@ -2529,7 +2536,7 @@ int test_getFramesCount() {
// Native methods
// *************************************************************************

private static native void twkInitWebCore(boolean useJIT, boolean useDFGJIT);
private static native void twkInitWebCore(boolean useJIT, boolean useDFGJIT, boolean useCSS3D);
private native long twkCreatePage(boolean editable);
private native void twkInit(long pPage, boolean usePlugins, float devicePixelScale);
private native void twkDestroyPage(long pPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public final class GraphicsDecoder {
@Native public final static int SET_LINE_JOIN = 53;
@Native public final static int SET_MITER_LIMIT = 54;
@Native public final static int SET_TEXT_MODE = 55;
@Native public final static int SET_PERSPECTIVE_TRANSFORM = 56;

private final static PlatformLogger log =
PlatformLogger.getLogger(GraphicsDecoder.class.getName());
Expand Down Expand Up @@ -326,6 +327,13 @@ static void decode(WCGraphicsManager gm, WCGraphicsContext gc, BufferData bdata)
buf.getFloat(), buf.getFloat(), buf.getFloat(),
buf.getFloat(), buf.getFloat(), buf.getFloat()));
break;
case SET_PERSPECTIVE_TRANSFORM:
gc.setPerspectiveTransform(new WCTransform(
buf.getFloat(), buf.getFloat(), buf.getFloat(), buf.getFloat(),
buf.getFloat(), buf.getFloat(), buf.getFloat(), buf.getFloat(),
buf.getFloat(), buf.getFloat(), buf.getFloat(), buf.getFloat(),
buf.getFloat(), buf.getFloat(), buf.getFloat(), buf.getFloat()));
break;
case SET_TRANSFORM:
gc.setTransform(new WCTransform(
buf.getFloat(), buf.getFloat(), buf.getFloat(),
Expand Down
Loading

0 comments on commit cdb3a30

Please sign in to comment.