Home | History | Annotate | Download | only in shadow
      1 /*
      2  * Copyright (C) 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.view.shadow;
     18 
     19 /**
     20  * Model for ambient shadow rendering. Assumes light sources from centroid of the object.
     21  */
     22 class AmbientShadowConfig {
     23 
     24     private final int mWidth;
     25     private final int mHeight;
     26 
     27     private final float mEdgeScale;
     28     private final float mShadowBoundRatio;
     29     private final float mShadowStrength;
     30 
     31     private final float[] mPolygon;
     32 
     33     private final int mRays;
     34     private final int mLayers;
     35 
     36     private AmbientShadowConfig(Builder builder) {
     37         mEdgeScale = builder.mEdgeScale;
     38         mShadowBoundRatio = builder.mShadowBoundRatio;
     39         mShadowStrength = builder.mShadowStrength;
     40         mRays = builder.mRays;
     41         mLayers = builder.mLayers;
     42         mWidth = builder.mWidth;
     43         mHeight = builder.mHeight;
     44         mPolygon = builder.mPolygon;
     45     }
     46 
     47     public int getWidth() {
     48         return mWidth;
     49     }
     50 
     51     public int getHeight() {
     52         return mHeight;
     53     }
     54 
     55     /**
     56      * Returns scales intensity of the edge of the shadow (opacity) [0-100]
     57      */
     58     public float getEdgeScale() {
     59         return mEdgeScale;
     60     }
     61 
     62     /**
     63      * Returns scales the area (in xy) of the shadow [0-1]
     64      */
     65     public float getShadowBoundRatio() {
     66         return mShadowBoundRatio;
     67     }
     68 
     69     /**
     70      * Returns scales the intensity of the entire shadow (opacity) [0-1]
     71      */
     72     public float getShadowStrength() {
     73         return mShadowStrength;
     74     }
     75 
     76     /**
     77      * Returns opaque polygon to cast shadow
     78      */
     79     public float[] getPolygon() {
     80         return mPolygon;
     81     }
     82 
     83     /**
     84      * Returns # of rays to use in ray tracing. It determines the accuracy of outline (bounds) of
     85      * the shadow.
     86      */
     87     public int getRays() {
     88         return mRays;
     89     }
     90 
     91     /**
     92      * Returns # of layers. It determines the intensity of the pen-umbra.
     93      */
     94     public int getLayers() {
     95         return mLayers;
     96     }
     97 
     98     public static class Builder {
     99 
    100         private float mEdgeScale;
    101         private float mShadowBoundRatio;
    102         private float mShadowStrength;
    103         private int mRays;
    104         private int mLayers;
    105 
    106         private float[] mPolygon;
    107 
    108         private int mWidth;
    109         private int mHeight;
    110 
    111         public Builder setEdgeScale(float edgeScale) {
    112             mEdgeScale = edgeScale;
    113             return this;
    114         }
    115 
    116         public Builder setShadowBoundRatio(float shadowBoundRatio) {
    117             mShadowBoundRatio = shadowBoundRatio;
    118             return this;
    119         }
    120 
    121         public Builder setShadowStrength(float shadowStrength) {
    122             mShadowStrength = shadowStrength;
    123             return this;
    124         }
    125 
    126         public Builder setRays(int rays) {
    127             mRays = rays;
    128             return this;
    129         }
    130 
    131         public Builder setLayers(int layers) {
    132             mLayers = layers;
    133             return this;
    134         }
    135 
    136         public Builder setSize(int width, int height) {
    137             mWidth = width;
    138             mHeight = height;
    139             return this;
    140         }
    141 
    142         public Builder setPolygon(float[] polygon) {
    143             mPolygon = polygon;
    144             return this;
    145         }
    146 
    147         public AmbientShadowConfig build() {
    148             return new AmbientShadowConfig(this);
    149         }
    150     }
    151 }
    152