Home | History | Annotate | Download | only in skia
      1 /*
      2  * Copyright (C) 2016 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 "renderthread/CanvasContext.h"
     20 #include "FrameBuilder.h"
     21 #include "renderthread/IRenderPipeline.h"
     22 #include <SkSurface.h>
     23 
     24 namespace android {
     25 namespace uirenderer {
     26 namespace skiapipeline {
     27 
     28 class SkiaPipeline : public renderthread::IRenderPipeline {
     29 public:
     30     SkiaPipeline(renderthread::RenderThread& thread);
     31     virtual ~SkiaPipeline() {}
     32 
     33     TaskManager* getTaskManager() override;
     34 
     35     void onDestroyHardwareResources() override;
     36 
     37     bool pinImages(std::vector<SkImage*>& mutableImages) override;
     38     bool pinImages(LsaVector<sk_sp<Bitmap>>& images) override { return false; }
     39     void unpinImages() override;
     40 
     41     void renderLayers(const FrameBuilder::LightGeometry& lightGeometry,
     42             LayerUpdateQueue* layerUpdateQueue, bool opaque,
     43             const BakedOpRenderer::LightInfo& lightInfo) override;
     44 
     45     bool createOrUpdateLayer(RenderNode* node,
     46             const DamageAccumulator& damageAccumulator) override;
     47 
     48     void renderFrame(const LayerUpdateQueue& layers, const SkRect& clip,
     49             const std::vector< sp<RenderNode> >& nodes, bool opaque, const Rect &contentDrawBounds,
     50             sk_sp<SkSurface> surface);
     51 
     52     static void destroyLayer(RenderNode* node);
     53 
     54     static void prepareToDraw(const renderthread::RenderThread& thread, Bitmap* bitmap);
     55 
     56     static void renderLayersImpl(const LayerUpdateQueue& layers, bool opaque);
     57 
     58     static bool skpCaptureEnabled() { return false; }
     59 
     60     static float getLightRadius() {
     61         if (CC_UNLIKELY(Properties::overrideLightRadius > 0)) {
     62             return Properties::overrideLightRadius;
     63         }
     64         return mLightRadius;
     65     }
     66 
     67     static uint8_t getAmbientShadowAlpha() {
     68         if (CC_UNLIKELY(Properties::overrideAmbientShadowStrength >= 0)) {
     69             return Properties::overrideAmbientShadowStrength;
     70         }
     71         return mAmbientShadowAlpha;
     72     }
     73 
     74     static uint8_t getSpotShadowAlpha() {
     75         if (CC_UNLIKELY(Properties::overrideSpotShadowStrength >= 0)) {
     76             return Properties::overrideSpotShadowStrength;
     77         }
     78         return mSpotShadowAlpha;
     79     }
     80 
     81     static Vector3 getLightCenter() {
     82         if (CC_UNLIKELY(Properties::overrideLightPosY > 0 || Properties::overrideLightPosZ > 0)) {
     83             Vector3 adjustedLightCenter = mLightCenter;
     84             if (CC_UNLIKELY(Properties::overrideLightPosY > 0)) {
     85                 // negated since this shifts up
     86                 adjustedLightCenter.y = - Properties::overrideLightPosY;
     87             }
     88             if (CC_UNLIKELY(Properties::overrideLightPosZ > 0)) {
     89                 adjustedLightCenter.z = Properties::overrideLightPosZ;
     90             }
     91             return adjustedLightCenter;
     92         }
     93         return mLightCenter;
     94     }
     95 
     96     static void updateLighting(const FrameBuilder::LightGeometry& lightGeometry,
     97             const BakedOpRenderer::LightInfo& lightInfo) {
     98         mLightRadius = lightGeometry.radius;
     99         mAmbientShadowAlpha = lightInfo.ambientShadowAlpha;
    100         mSpotShadowAlpha = lightInfo.spotShadowAlpha;
    101         mLightCenter = lightGeometry.center;
    102     }
    103 
    104 protected:
    105     void dumpResourceCacheUsage() const;
    106 
    107     renderthread::RenderThread& mRenderThread;
    108 
    109 private:
    110     void renderFrameImpl(const LayerUpdateQueue& layers, const SkRect& clip,
    111             const std::vector< sp<RenderNode> >& nodes, bool opaque, const Rect &contentDrawBounds,
    112             SkCanvas* canvas);
    113 
    114     /**
    115      *  Debugging feature.  Draws a semi-transparent overlay on each pixel, indicating
    116      *  how many times it has been drawn.
    117      */
    118     void renderOverdraw(const LayerUpdateQueue& layers, const SkRect& clip,
    119             const std::vector< sp<RenderNode> >& nodes, const Rect &contentDrawBounds,
    120             sk_sp<SkSurface>);
    121 
    122     TaskManager mTaskManager;
    123     std::vector<sk_sp<SkImage>> mPinnedImages;
    124     static float mLightRadius;
    125     static uint8_t mAmbientShadowAlpha;
    126     static uint8_t mSpotShadowAlpha;
    127     static Vector3 mLightCenter;
    128 };
    129 
    130 } /* namespace skiapipeline */
    131 } /* namespace uirenderer */
    132 } /* namespace android */
    133