Home | History | Annotate | Download | only in hwui
      1 /*
      2  * Copyright (C) 2010 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 #pragma once
     18 
     19 #include <utils/RefBase.h>
     20 
     21 #include <SkBlendMode.h>
     22 #include <SkColorFilter.h>
     23 #include <SkColorSpace.h>
     24 #include <SkPaint.h>
     25 #include <SkImage.h>
     26 #include <SkMatrix.h>
     27 #include <system/graphics.h>
     28 
     29 namespace android {
     30 namespace uirenderer {
     31 
     32 ///////////////////////////////////////////////////////////////////////////////
     33 // Layers
     34 ///////////////////////////////////////////////////////////////////////////////
     35 
     36 class RenderState;
     37 
     38 /**
     39  * A layer has dimensions and is backed by a backend specific texture or framebuffer.
     40  */
     41 class Layer : public VirtualLightRefBase {
     42 public:
     43     Layer(RenderState& renderState, sk_sp<SkColorFilter>, int alpha, SkBlendMode mode);
     44 
     45     ~Layer();
     46 
     47     uint32_t getWidth() const { return mWidth; }
     48 
     49     uint32_t getHeight() const { return mHeight; }
     50 
     51     void setSize(uint32_t width, uint32_t height) { mWidth = width; mHeight = height; }
     52 
     53     void setBlend(bool blend) { mBlend = blend; }
     54 
     55     bool isBlend() const { return mBlend; }
     56 
     57     inline void setForceFilter(bool forceFilter) { this->forceFilter = forceFilter; }
     58 
     59     inline bool getForceFilter() const { return forceFilter; }
     60 
     61     inline void setAlpha(int alpha) { this->alpha = alpha; }
     62 
     63     inline void setAlpha(int alpha, SkBlendMode mode) {
     64         this->alpha = alpha;
     65         this->mode = mode;
     66     }
     67 
     68     inline int getAlpha() const { return alpha; }
     69 
     70     SkBlendMode getMode() const;
     71 
     72     inline sk_sp<SkColorFilter> getColorFilter() const { return mColorFilter; }
     73 
     74     void setColorFilter(sk_sp<SkColorFilter> filter) { mColorFilter = filter; };
     75 
     76     inline SkMatrix& getTexTransform() { return texTransform; }
     77 
     78     inline SkMatrix& getTransform() { return transform; }
     79 
     80     /**
     81      * Posts a decStrong call to the appropriate thread.
     82      * Thread-safe.
     83      */
     84     void postDecStrong();
     85 
     86     inline void setImage(const sk_sp<SkImage>& image) { this->layerImage = image; }
     87 
     88     inline sk_sp<SkImage> getImage() const { return this->layerImage; }
     89 
     90 protected:
     91 
     92     RenderState& mRenderState;
     93 
     94 private:
     95     /**
     96      * Color filter used to draw this layer. Optional.
     97      */
     98     sk_sp<SkColorFilter> mColorFilter;
     99 
    100     /**
    101      * Indicates raster data backing the layer is scaled, requiring filtration.
    102      */
    103     bool forceFilter = false;
    104 
    105     /**
    106      * Opacity of the layer.
    107      */
    108     int alpha;
    109 
    110     /**
    111      * Blending mode of the layer.
    112      */
    113     SkBlendMode mode;
    114 
    115     /**
    116      * Optional texture coordinates transform.
    117      */
    118     SkMatrix texTransform;
    119 
    120     /**
    121      * Optional transform.
    122      */
    123     SkMatrix transform;
    124 
    125     /**
    126      * An image backing the layer.
    127      */
    128     sk_sp<SkImage> layerImage;
    129 
    130     /**
    131      * layer width.
    132      */
    133     uint32_t mWidth = 0;
    134 
    135     /**
    136      * layer height.
    137      */
    138     uint32_t mHeight = 0;
    139 
    140     /**
    141      * enable blending
    142      */
    143     bool mBlend = false;
    144 
    145 };  // struct Layer
    146 
    147 }  // namespace uirenderer
    148 }  // namespace android
    149