Home | History | Annotate | Download | only in hwui
      1 /*
      2  * Copyright (C) 2011 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 #ifndef ANDROID_HWUI_LAYER_RENDERER_H
     18 #define ANDROID_HWUI_LAYER_RENDERER_H
     19 
     20 #include <cutils/compiler.h>
     21 
     22 #include "OpenGLRenderer.h"
     23 #include "Layer.h"
     24 
     25 #include <SkBitmap.h>
     26 
     27 namespace android {
     28 namespace uirenderer {
     29 
     30 class RenderState;
     31 
     32 ///////////////////////////////////////////////////////////////////////////////
     33 // Defines
     34 ///////////////////////////////////////////////////////////////////////////////
     35 
     36 // Debug
     37 #if DEBUG_LAYER_RENDERER
     38     #define LAYER_RENDERER_LOGD(...) ALOGD(__VA_ARGS__)
     39 #else
     40     #define LAYER_RENDERER_LOGD(...)
     41 #endif
     42 
     43 ///////////////////////////////////////////////////////////////////////////////
     44 // Renderer
     45 ///////////////////////////////////////////////////////////////////////////////
     46 
     47 class LayerRenderer: public OpenGLRenderer {
     48 public:
     49     LayerRenderer(RenderState& renderState, Layer* layer);
     50     virtual ~LayerRenderer();
     51 
     52     virtual void onViewportInitialized() { /* do nothing */ }
     53     virtual status_t prepareDirty(float left, float top, float right, float bottom, bool opaque);
     54     virtual status_t clear(float left, float top, float right, float bottom, bool opaque);
     55     virtual void finish();
     56 
     57     static Layer* createTextureLayer(RenderState& renderState);
     58     static Layer* createRenderLayer(RenderState& renderState, uint32_t width, uint32_t height);
     59     static bool resizeLayer(Layer* layer, uint32_t width, uint32_t height);
     60     static void updateTextureLayer(Layer* layer, uint32_t width, uint32_t height,
     61             bool isOpaque, bool forceFilter, GLenum renderTarget, float* textureTransform);
     62     static void destroyLayer(Layer* layer);
     63     static bool copyLayer(RenderState& renderState, Layer* layer, SkBitmap* bitmap);
     64 
     65     static void flushLayer(RenderState& renderState, Layer* layer);
     66 
     67 protected:
     68     virtual void ensureStencilBuffer();
     69     virtual bool hasLayer() const;
     70     virtual Region* getRegion() const;
     71     virtual GLuint getTargetFbo() const;
     72     virtual bool suppressErrorChecks() const;
     73 
     74 private:
     75     void generateMesh();
     76 
     77     Layer* mLayer;
     78 }; // class LayerRenderer
     79 
     80 }; // namespace uirenderer
     81 }; // namespace android
     82 
     83 #endif // ANDROID_HWUI_LAYER_RENDERER_H
     84