openjfx/8/master/rt: a3f860f81cf8 (original) (raw)
OpenJDK / openjfx / 8 / master / rt
changeset 1829:a3f860f81cf8
RT-25496 Optimize ImageView bounds
Martin Sladecek martin.sladecek@oracle.com | |
---|---|
date | Fri, 26 Oct 2012 13:10:55 +0200 |
parents | 15023603f35c |
children | 3626aad4f2a5 |
files | javafx-ui-common/src/javafx/scene/image/ImageView.java javafx-ui-common/test/unit/javafx/scene/image/ImageViewTest.java test-stub-toolkit/src/com/sun/javafx/pgstub/StubImageView.java |
diffstat | 3 files changed, 72 insertions(+), 97 deletions(-)[+] [-] javafx-ui-common/src/javafx/scene/image/ImageView.java 119 javafx-ui-common/test/unit/javafx/scene/image/ImageViewTest.java 16 test-stub-toolkit/src/com/sun/javafx/pgstub/StubImageView.java 34 |
line wrap: on
line diff
--- a/javafx-ui-common/src/javafx/scene/image/ImageView.java Fri Oct 26 11:58:32 2012 +0200 +++ b/javafx-ui-common/src/javafx/scene/image/ImageView.java Fri Oct 26 13:10:55 2012 +0200 @@ -210,6 +210,7 @@ } if (dimensionChanged) { impl_geomChanged();
invalidateWidthHeight();[](#l1.7) }[](#l1.8) impl_markDirty(DirtyBits.NODE_CONTENTS);[](#l1.9) }[](#l1.10)
@@ -286,6 +287,7 @@ public void invalidated(Observable valueModel) { impl_markDirty(DirtyBits.NODE_CONTENTS); impl_geomChanged();
}; /** @@ -398,6 +400,7 @@ protected void invalidated() { impl_markDirty(DirtyBits.NODE_VIEWPORT); impl_geomChanged();invalidateWidthHeight();[](#l1.15) }[](#l1.16)
invalidateWidthHeight();[](#l1.23) }[](#l1.24)
@Override @@ -445,6 +448,7 @@ protected void invalidated() { impl_markDirty(DirtyBits.NODE_VIEWPORT); impl_geomChanged();
invalidateWidthHeight();[](#l1.31) }[](#l1.32)
@Override @@ -509,6 +513,7 @@ protected void invalidated() { impl_markDirty(DirtyBits.NODE_VIEWPORT); impl_geomChanged();
invalidateWidthHeight();[](#l1.39) }[](#l1.40)
@Override @@ -612,6 +617,7 @@ protected void invalidated() { impl_markDirty(DirtyBits.NODE_VIEWPORT); impl_geomChanged();
invalidateWidthHeight();[](#l1.47) }[](#l1.48)
@Override @@ -659,75 +665,63 @@ */ @Deprecated @Override public BaseBounds impl_computeGeomBounds(BaseBounds bounds, BaseTransform tx) {
recomputeWidthHeight();[](#l1.55)
// need to figure out the width/height to use for computing bounds[](#l1.57)
bounds = bounds.deriveWithNewBounds((float)getX(), (float)getY(), 0.0f,[](#l1.58)
(float)(getX() + destWidth), (float)(getY() + destHeight), 0.0f);[](#l1.59)
bounds = tx.transform(bounds, bounds);[](#l1.60)
return bounds;[](#l1.61)
- }
- private boolean validWH;
- private void recomputeWidthHeight() {
if (validWH) {[](#l1.71)
return;[](#l1.72)
}[](#l1.73)
Image localImage = getImage();[](#l1.74)
Rectangle2D localViewport = getViewport();[](#l1.75)
Image localImage = getImage();[](#l1.79)
if (localImage != null) {[](#l1.80)
if (localViewport != null && localViewport.getWidth() > 0 && localViewport.getHeight() > 0) {[](#l1.81)
w = localViewport.getWidth();[](#l1.82)
h = localViewport.getHeight();[](#l1.83)
} else if (localImage != null) {[](#l1.84) w = localImage.getWidth();[](#l1.85) h = localImage.getHeight();[](#l1.86) }[](#l1.87)
+ double localFitWidth = getFitWidth(); double localFitHeight = getFitHeight();
double newW = localFitWidth;[](#l1.91)
double newH = localFitHeight;[](#l1.92)
double vw = 0;[](#l1.93)
double vh = 0;[](#l1.94)
Rectangle2D localViewport = getViewport();[](#l1.95)
if (localViewport != null) {[](#l1.96)
vw = localViewport.getWidth();[](#l1.97)
vh = localViewport.getHeight();[](#l1.98)
}[](#l1.99)
if (vw > 0 && vh > 0) {[](#l1.101)
w = vw;[](#l1.102)
h = vh;[](#l1.103)
}[](#l1.104)
if (localFitWidth <= 0.0 && localFitHeight <= 0.0) {[](#l1.106)
newW = w;[](#l1.107)
newH = h;[](#l1.108)
} else if (isPreserveRatio()) {[](#l1.109)
if (localFitWidth <= 0.0) {[](#l1.110)
newW = (h > 0) ? w * (localFitHeight / h) : 0;[](#l1.111)
newH = localFitHeight;[](#l1.112)
} else if (localFitHeight <= 0.0) {[](#l1.113)
newW = localFitWidth;[](#l1.114)
newH = (w > 0) ? h * (localFitWidth / w) : 0;[](#l1.115)
if (isPreserveRatio() && w > 0 && h > 0 && (localFitWidth > 0 || localFitHeight > 0)) {[](#l1.116)
if (localFitWidth <= 0 || (localFitHeight > 0 && localFitWidth * h > localFitHeight * w)) {[](#l1.117)
w = w * localFitHeight / h;[](#l1.118)
h = localFitHeight;[](#l1.119) } else {[](#l1.120)
if (w == 0.0)[](#l1.121)
w = localFitWidth;[](#l1.122)
if (h == 0.0)[](#l1.123)
h = localFitHeight;[](#l1.124)
double scale = Math.min(localFitWidth / w, localFitHeight / h);[](#l1.125)
newW = w * scale;[](#l1.126)
newH = h * scale;[](#l1.127)
h = h * localFitWidth / w;[](#l1.128)
w = localFitWidth;[](#l1.129) }[](#l1.130)
} else if (getFitHeight() <= 0.0) {[](#l1.131)
newH = h;[](#l1.132)
} else if (getFitWidth() <= 0.0) {[](#l1.133)
newW = w;[](#l1.134)
}[](#l1.135)
if (newH < 1) {[](#l1.136)
newH = 1;[](#l1.137)
}[](#l1.138)
if (newW < 1) {[](#l1.139)
newW = 1;[](#l1.140)
} else {[](#l1.141)
if (localFitWidth > 0f) {[](#l1.142)
w = localFitWidth;[](#l1.143)
}[](#l1.144)
if (localFitHeight > 0f) {[](#l1.145)
h = localFitHeight;[](#l1.146)
}[](#l1.147) }[](#l1.148)
// Store these values for use later in impl_computeContains() to support // Node.contains().
destWidth = newW;[](#l1.152)
destHeight = newH;[](#l1.153)
destWidth = w;[](#l1.154)
destHeight = h;[](#l1.155)
w = newW;[](#l1.157)
h = newH;[](#l1.158)
bounds = bounds.deriveWithNewBounds((float)getX(), (float)getY(), 0.0f,[](#l1.160)
(float)(getX() + w), (float)(getY() + h), 0.0f);[](#l1.161)
bounds = tx.transform(bounds, bounds);[](#l1.162)
return bounds;[](#l1.163)
recomputeWidthHeight();[](#l1.173) // Local Note bounds contain test is already done by the caller.[](#l1.174) // (Node.contains()).[](#l1.175)
@@ -843,19 +839,18 @@ } void updateViewport() { -
recomputeWidthHeight();[](#l1.182) if (getImage() == null || getImage().impl_getPlatformImage() == null) {[](#l1.183) return;[](#l1.184) }[](#l1.185)
Rectangle2D localViewport = getViewport(); if (localViewport != null) {
getPGImageView().setViewport((float)getFitWidth(), (float)getFitHeight(),[](#l1.189)
(float)localViewport.getMinX(), (float)localViewport.getMinY(),[](#l1.190)
(float)localViewport.getWidth(), (float)localViewport.getHeight(), isPreserveRatio());[](#l1.191)
getPGImageView().setViewport((float)localViewport.getMinX(), (float)localViewport.getMinY(),[](#l1.192)
(float)localViewport.getWidth(), (float)localViewport.getHeight(),[](#l1.193)
(float)destWidth, (float)destHeight);[](#l1.194) } else {[](#l1.195)
getPGImageView().setViewport((float)getFitWidth(), (float)getFitHeight(), 0, 0, 0, 0,[](#l1.196)
isPreserveRatio());[](#l1.197)
} @@ -875,11 +870,11 @@ if (impl_isDirty(DirtyBits.NODE_SMOOTH)) { getPGImageView().setSmooth(isSmooth()); }getPGImageView().setViewport(0, 0, 0, 0, (float)destWidth, (float)destHeight);[](#l1.198) }[](#l1.199)
if (impl_isDirty(DirtyBits.NODE_VIEWPORT)) {[](#l1.206)
updateViewport();[](#l1.207)
}[](#l1.208) if (impl_isDirty(DirtyBits.NODE_CONTENTS)) {[](#l1.209) getPGImageView().setImage(getImage()!= null? getImage().impl_getPlatformImage():null);[](#l1.210)
}[](#l1.211)
// The NG part expects this to be called when image changes[](#l1.212)
}if (impl_isDirty(DirtyBits.NODE_VIEWPORT) || impl_isDirty(DirtyBits.NODE_CONTENTS)) {[](#l1.213) updateViewport();[](#l1.214) }[](#l1.215)
--- a/javafx-ui-common/test/unit/javafx/scene/image/ImageViewTest.java Fri Oct 26 11:58:32 2012 +0200 +++ b/javafx-ui-common/test/unit/javafx/scene/image/ImageViewTest.java Fri Oct 26 13:10:55 2012 +0200 @@ -82,22 +82,6 @@ } @Test
- public void testPropertyPropagation_fitWidth() throws Exception {
NodeTest.testDoublePropertyPropagation(imageView, "fitWidth", 100, 200);[](#l2.8)
- }
- @Test
- public void testPropertyPropagation_fitHeight() throws Exception {
NodeTest.testDoublePropertyPropagation(imageView, "fitHeight", 100, 200);[](#l2.13)
- }
- @Test
- public void testPropertyPropagation_preserveRatio() throws Exception {
NodeTest.testBooleanPropertyPropagation([](#l2.18)
imageView, "preserveRatio", true, false);[](#l2.19)
- }
- @Test public void testPropertyPropagation_image() throws Exception { NodeTest.testObjectPropertyPropagation( imageView, "image", "image",
--- a/test-stub-toolkit/src/com/sun/javafx/pgstub/StubImageView.java Fri Oct 26 11:58:32 2012 +0200 +++ b/test-stub-toolkit/src/com/sun/javafx/pgstub/StubImageView.java Fri Oct 26 13:10:55 2012 +0200 @@ -40,10 +40,9 @@ private float y; private boolean smooth;
@Override public void setImage(Object image) { @@ -73,13 +72,11 @@ } @Override
- public void setViewport(float fitWidth, float fitHeight,
float vx, float vy, float vw, float vh,[](#l3.21)
boolean preserveRatio) {[](#l3.22)
this.fitWidth = fitWidth;[](#l3.23)
this.fitHeight = fitHeight;[](#l3.24)
- public void setViewport(float vx, float vy, float vw, float vh,
float cw, float ch) {[](#l3.26) this.viewport = new Rectangle2D(vx, vy, vw, vh);[](#l3.27)
this.preserveRatio = preserveRatio;[](#l3.28)
this.cw = cw;[](#l3.29)
} @Override @@ -89,19 +86,18 @@ public boolean isSmooth() { return this.smooth; }this.ch = ch;[](#l3.30)