Layer.h revision 0bb5667b4ef91fefd0500fae0186789d15d54e0e
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_UI_LAYER_H
18#define ANDROID_UI_LAYER_H
19
20#include <sys/types.h>
21
22#include <GLES2/gl2.h>
23
24#include <SkXfermode.h>
25
26#include "Rect.h"
27
28namespace android {
29namespace uirenderer {
30
31/**
32 * Dimensions of a layer.
33 */
34struct LayerSize {
35    LayerSize(): width(0), height(0), id(0) { }
36    LayerSize(const uint32_t width, const uint32_t height): width(width), height(height), id(0) { }
37    LayerSize(const LayerSize& size): width(size.width), height(size.height), id(size.id) { }
38
39    uint32_t width;
40    uint32_t height;
41
42    // Incremental id used by the layer cache to store multiple
43    // LayerSize with the same dimensions
44    uint32_t id;
45
46    bool operator<(const LayerSize& rhs) const {
47        if (id != 0 && rhs.id != 0 && id != rhs.id) {
48            return id < rhs.id;
49        }
50        if (width == rhs.width) {
51            return height < rhs.height;
52        }
53        return width < rhs.width;
54    }
55
56    bool operator==(const LayerSize& rhs) const {
57        return id == rhs.id && width == rhs.width && height == rhs.height;
58    }
59}; // struct LayerSize
60
61/**
62 * A layer has dimensions and is backed by an OpenGL texture.
63 */
64struct Layer {
65    /**
66     * Coordinates of the layer.
67     */
68    Rect layer;
69    /**
70     * Name of the texture used to render the layer.
71     */
72    GLuint texture;
73    /**
74     * Opacity of the layer.
75     */
76    int alpha;
77    /**
78     * Blending mode of the layer.
79     */
80    SkXfermode::Mode mode;
81    /**
82     * Indicates whether this layer should be blended.
83     */
84    bool blend;
85    /**
86     * Indicates whether this layer has been used already.
87     */
88    bool empty;
89}; // struct Layer
90
91}; // namespace uirenderer
92}; // namespace android
93
94#endif // ANDROID_UI_LAYER_H
95