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 #ifndef ANDROID_HWUI_PATCH_H
     18 #define ANDROID_HWUI_PATCH_H
     19 
     20 #include <sys/types.h>
     21 
     22 #include <GLES2/gl2.h>
     23 
     24 #include <utils/Vector.h>
     25 
     26 #include <androidfw/ResourceTypes.h>
     27 
     28 #include "Rect.h"
     29 #include "UvMapper.h"
     30 #include "Vertex.h"
     31 
     32 namespace android {
     33 namespace uirenderer {
     34 
     35 ///////////////////////////////////////////////////////////////////////////////
     36 // 9-patch structures
     37 ///////////////////////////////////////////////////////////////////////////////
     38 
     39 class Patch {
     40 public:
     41     Patch();
     42     ~Patch();
     43 
     44     /**
     45      * Returns the size of this patch's mesh in bytes.
     46      */
     47     uint32_t getSize() const;
     48 
     49     TextureVertex* vertices;
     50     uint32_t verticesCount;
     51     uint32_t indexCount;
     52     bool hasEmptyQuads;
     53     Vector<Rect> quads;
     54 
     55     GLintptr offset;
     56     GLintptr textureOffset;
     57 
     58     TextureVertex* createMesh(const float bitmapWidth, const float bitmapHeight,
     59             float width, float height, const Res_png_9patch* patch);
     60     TextureVertex* createMesh(const float bitmapWidth, const float bitmapHeight,
     61             float width, float height, const UvMapper& mapper, const Res_png_9patch* patch);
     62 
     63 private:
     64     void generateRow(const int32_t* xDivs, uint32_t xCount, TextureVertex*& vertex,
     65             float y1, float y2, float v1, float v2, float stretchX, float rescaleX,
     66             float width, float bitmapWidth, uint32_t& quadCount);
     67     void generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, float y2,
     68             float u1, float v1, float u2, float v2, uint32_t& quadCount);
     69 
     70     const uint32_t* mColors;
     71     UvMapper mUvMapper;
     72 }; // struct Patch
     73 
     74 }; // namespace uirenderer
     75 }; // namespace android
     76 
     77 #endif // ANDROID_HWUI_PATCH_H
     78