1 /* 2 * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /* 27 * This file was originally generated by JSLC 28 * and then hand edited for performance. 29 */ 30 31 package com.sun.scenario.effect.impl.sw.sse; 32 33 import com.sun.scenario.effect.Effect; 34 import com.sun.scenario.effect.FilterContext; 35 import com.sun.scenario.effect.ImageData; 36 import com.sun.scenario.effect.impl.HeapImage; 37 import com.sun.scenario.effect.impl.Renderer; 38 import com.sun.javafx.geom.Rectangle; 39 import com.sun.javafx.geom.transform.BaseTransform; 40 import com.sun.scenario.effect.impl.state.BoxRenderState; 41 42 public class SSEBoxShadowPeer extends SSEEffectPeer<BoxRenderState> { 43 44 public SSEBoxShadowPeer(FilterContext fctx, Renderer r, String uniqueName) { 45 super(fctx, r, uniqueName); 46 } 47 48 @Override 49 public ImageData filter(Effect effect, 50 BoxRenderState brstate, 51 BaseTransform transform, 52 Rectangle outputClip, 53 ImageData... inputs) 54 { 55 setRenderState(brstate); 56 // NOTE: for now, all input images must be TYPE_INT_ARGB_PRE 57 58 // Calculate the amount the image grows on each iteration (size-1) 59 boolean horizontal = (getPass() == 0); 60 int hinc = horizontal ? brstate.getBoxPixelSize(0) - 1 : 0; 61 int vinc = horizontal ? 0 : brstate.getBoxPixelSize(1) - 1; 62 if (hinc < 0) hinc = 0; 63 if (vinc < 0) vinc = 0; 64 int iterations = brstate.getBlurPasses(); 65 float spread = brstate.getSpread(); 66 if (horizontal && (iterations < 1 || (hinc < 1 && vinc < 1))) { 67 inputs[0].addref(); 68 return inputs[0]; 69 } 70 // Calculate the amount the image will grow through the full operation 71 // Always upgrade to the next even amount of growth 72 int growx = (hinc * iterations + 1) & (~0x1); 73 int growy = (vinc * iterations + 1) & (~0x1); 74 75 // Assert: rstate.getEffectTransformSpace() == UserSpace 76 // NOTE: We could still have a transformed ImageData for other reasons... 77 HeapImage src = (HeapImage)inputs[0].getUntransformedImage(); 78 Rectangle srcr = inputs[0].getUntransformedBounds(); 79 80 HeapImage cur = src; 81 int curw = srcr.width; 82 int curh = srcr.height; 83 int curscan = cur.getScanlineStride(); 84 int[] curPixels = cur.getPixelArray(); 85 86 int finalw = curw + growx; 87 int finalh = curh + growy; 88 boolean force = !horizontal; 89 while (force || curw < finalw || curh < finalh) { 90 int neww = curw + hinc; 91 int newh = curh + vinc; 92 if (neww > finalw) neww = finalw; 93 if (newh > finalh) newh = finalh; 94 HeapImage dst = (HeapImage)getRenderer().getCompatibleImage(neww, newh); 95 int newscan = dst.getScanlineStride(); 96 int[] newPixels = dst.getPixelArray(); 97 if (iterations == 0) { 98 // The last "fixup" iteration of 2 should have no spread. 99 spread = 0f; 100 } 101 if (horizontal) { 102 filterHorizontalBlack(newPixels, neww, newh, newscan, 103 curPixels, curw, curh, curscan, 104 spread); 105 } else if (neww < finalw || newh < finalh) { 106 // Use BLACK for shadow color until very last pass 107 filterVerticalBlack(newPixels, neww, newh, newscan, 108 curPixels, curw, curh, curscan, 109 spread); 110 } else { 111 float shadowColor[] = 112 brstate.getShadowColor().getPremultipliedRGBComponents(); 113 if (shadowColor[3] == 1f && 114 shadowColor[0] == 0f && 115 shadowColor[1] == 0f && 116 shadowColor[2] == 0f) 117 { 118 filterVerticalBlack(newPixels, neww, newh, newscan, 119 curPixels, curw, curh, curscan, 120 spread); 121 } else { 122 filterVertical(newPixels, neww, newh, newscan, 123 curPixels, curw, curh, curscan, 124 spread, shadowColor); 125 } 126 } 127 if (cur != src) { 128 getRenderer().releaseCompatibleImage(cur); 129 } 130 iterations--; 131 force = false; 132 cur = dst; 133 curw = neww; 134 curh = newh; 135 curPixels = newPixels; 136 curscan = newscan; 137 } 138 139 Rectangle dstBounds = 140 new Rectangle(srcr.x - growx/2, srcr.y - growy/2, curw, curh); 141 return new ImageData(getFilterContext(), cur, dstBounds, inputs[0].getTransform()); 142 } 143 144 private static native void 145 filterHorizontalBlack(int dstPixels[], int dstw, int dsth, int dstscan, 146 int srcPixels[], int srcw, int srch, int srcscan, 147 float spread); 148 149 private static native void 150 filterVerticalBlack(int dstPixels[], int dstw, int dsth, int dstscan, 151 int srcPixels[], int srcw, int srch, int srcscan, 152 float spread); 153 154 private static native void 155 filterVertical(int dstPixels[], int dstw, int dsth, int dstscan, 156 int srcPixels[], int srcw, int srch, int srcscan, 157 float spread, float shadowColor[]); 158 }