1 /* 2 * Copyright (c) 2009, 2013, 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.BoxShadow; 35 import com.sun.scenario.effect.FilterContext; 36 import com.sun.scenario.effect.ImageData; 37 import com.sun.scenario.effect.impl.HeapImage; 38 import com.sun.scenario.effect.impl.Renderer; 39 import com.sun.javafx.geom.Rectangle; 40 import com.sun.javafx.geom.transform.BaseTransform; 41 import com.sun.scenario.effect.impl.state.BoxRenderState; 42 43 public class SSEBoxShadowPeer extends SSEEffectPeer<BoxRenderState> { 44 45 public SSEBoxShadowPeer(FilterContext fctx, Renderer r, String uniqueName) { 46 super(fctx, r, uniqueName); 47 } 48 49 @Override 50 public ImageData filter(Effect effect, 51 BoxRenderState brstate, 52 BaseTransform transform, 53 Rectangle outputClip, 54 ImageData... inputs) 55 { 56 setRenderState(brstate); 57 // NOTE: for now, all input images must be TYPE_INT_ARGB_PRE 58 59 // Calculate the amount the image grows on each iteration (size-1) 60 boolean horizontal = (getPass() == 0); 61 int hinc = horizontal ? brstate.getBoxPixelSize(0) - 1 : 0; 62 int vinc = horizontal ? 0 : brstate.getBoxPixelSize(1) - 1; 63 if (hinc < 0) hinc = 0; 64 if (vinc < 0) vinc = 0; 65 int iterations = brstate.getBlurPasses(); 66 float spread = brstate.getSpread(); 67 if (horizontal && (iterations < 1 || (hinc < 1 && vinc < 1))) { 68 inputs[0].addref(); 69 return inputs[0]; 70 } 71 // Calculate the amount the image will grow through the full operation 72 // Always upgrade to the next even amount of growth 73 int growx = (hinc * iterations + 1) & (~0x1); 74 int growy = (vinc * iterations + 1) & (~0x1); 75 76 // Assert: rstate.getEffectTransformSpace() == UserSpace 77 // NOTE: We could still have a transformed ImageData for other reasons... 78 HeapImage src = (HeapImage)inputs[0].getUntransformedImage(); 79 Rectangle srcr = inputs[0].getUntransformedBounds(); 80 81 HeapImage cur = src; 82 int curw = srcr.width; 83 int curh = srcr.height; 84 int curscan = cur.getScanlineStride(); 85 int[] curPixels = cur.getPixelArray(); 86 87 int finalw = curw + growx; 88 int finalh = curh + growy; 89 boolean force = !horizontal; 90 while (force || curw < finalw || curh < finalh) { 91 int neww = curw + hinc; 92 int newh = curh + vinc; 93 if (neww > finalw) neww = finalw; 94 if (newh > finalh) newh = finalh; 95 HeapImage dst = (HeapImage)getRenderer().getCompatibleImage(neww, newh); 96 int newscan = dst.getScanlineStride(); 97 int[] newPixels = dst.getPixelArray(); 98 if (iterations == 0) { 99 // The last "fixup" iteration of 2 should have no spread. 100 spread = 0f; 101 } 102 if (horizontal) { 103 filterHorizontalBlack(newPixels, neww, newh, newscan, 104 curPixels, curw, curh, curscan, 105 spread); 106 } else if (neww < finalw || newh < finalh) { 107 // Use BLACK for shadow color until very last pass 108 filterVerticalBlack(newPixels, neww, newh, newscan, 109 curPixels, curw, curh, curscan, 110 spread); 111 } else { 112 float shadowColor[] = 113 brstate.getShadowColor().getPremultipliedRGBComponents(); 114 if (shadowColor[3] == 1f && 115 shadowColor[0] == 0f && 116 shadowColor[1] == 0f && 117 shadowColor[2] == 0f) 118 { 119 filterVerticalBlack(newPixels, neww, newh, newscan, 120 curPixels, curw, curh, curscan, 121 spread); 122 } else { 123 filterVertical(newPixels, neww, newh, newscan, 124 curPixels, curw, curh, curscan, 125 spread, shadowColor); 126 } 127 } 128 if (cur != src) { 129 getRenderer().releaseCompatibleImage(cur); 130 } 131 iterations--; 132 force = false; 133 cur = dst; 134 curw = neww; 135 curh = newh; 136 curPixels = newPixels; 137 curscan = newscan; 138 } 139 140 Rectangle dstBounds = 141 new Rectangle(srcr.x - growx/2, srcr.y - growy/2, curw, curh); 142 return new ImageData(getFilterContext(), cur, dstBounds); 143 } 144 145 private static native void 146 filterHorizontalBlack(int dstPixels[], int dstw, int dsth, int dstscan, 147 int srcPixels[], int srcw, int srch, int srcscan, 148 float spread); 149 150 private static native void 151 filterVerticalBlack(int dstPixels[], int dstw, int dsth, int dstscan, 152 int srcPixels[], int srcw, int srch, int srcscan, 153 float spread); 154 155 private static native void 156 filterVertical(int dstPixels[], int dstw, int dsth, int dstscan, 157 int srcPixels[], int srcw, int srch, int srcscan, 158 float spread, float shadowColor[]); 159 }