blob: 54bf5adc3ace1aacd0efba0947808f32ae7b1055 [file] [log] [blame]
Greg Daniel8cd3edf2017-01-09 14:15:41 -05001/*
2 * Copyright (C) 2017 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 "Layer.h"
20
21#include "Texture.h"
22
23namespace android {
24namespace uirenderer {
25
26// Forward declarations
27class Caches;
28
29/**
30 * A layer has dimensions and is backed by an OpenGL texture or FBO.
31 */
32class GlLayer : public Layer {
33public:
34 GlLayer(RenderState& renderState, uint32_t layerWidth, uint32_t layerHeight);
35 virtual ~GlLayer();
36
37 uint32_t getWidth() const override {
38 return texture.mWidth;
39 }
40
41 uint32_t getHeight() const override {
42 return texture.mHeight;
43 }
44
45 void setSize(uint32_t width, uint32_t height) override {
46 texture.updateSize(width, height, texture.internalFormat(), texture.format(),
47 texture.target());
48 }
49
50 void setBlend(bool blend) override {
51 texture.blend = blend;
52 }
53
54 bool isBlend() const override {
55 return texture.blend;
56 }
57
58 inline GLuint getTextureId() const {
59 return texture.id();
60 }
61
62 inline Texture& getTexture() {
63 return texture;
64 }
65
66 inline GLenum getRenderTarget() const {
67 return texture.target();
68 }
69
70 inline void setRenderTarget(GLenum renderTarget) {
71 texture.mTarget = renderTarget;
72 }
73
74 inline bool isRenderable() const {
75 return texture.target() != GL_NONE;
76 }
77
78 void setWrap(GLenum wrap, bool bindTexture = false, bool force = false) {
79 texture.setWrap(wrap, bindTexture, force);
80 }
81
82 void setFilter(GLenum filter, bool bindTexture = false, bool force = false) {
83 texture.setFilter(filter, bindTexture, force);
84 }
85
86 void bindTexture() const;
87 void generateTexture();
88
89 /**
90 * When the caller frees the texture itself, the caller
91 * must call this method to tell this layer that it lost
92 * the texture.
93 */
94 void clearTexture();
95
96 /**
97 * Lost the GL context but the layer is still around, mark it invalid internally
98 * so the dtor knows not to do any GL work
99 */
100 void onGlContextLost();
101
102private:
103 Caches& caches;
104
105 /**
106 * The texture backing this layer.
107 */
108 Texture texture;
109}; // struct GlLayer
110
111}; // namespace uirenderer
112}; // namespace android