blob: 85ddaff995038174dc4939dee74ae3181c022191 [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:
sergeyv3e9999b2017-01-19 15:37:02 -080034 GlLayer(RenderState& renderState, uint32_t layerWidth, uint32_t layerHeight,
35 SkColorFilter* colorFilter, int alpha, SkBlendMode mode, bool blend);
Greg Daniel8cd3edf2017-01-09 14:15:41 -050036 virtual ~GlLayer();
37
38 uint32_t getWidth() const override {
39 return texture.mWidth;
40 }
41
42 uint32_t getHeight() const override {
43 return texture.mHeight;
44 }
45
46 void setSize(uint32_t width, uint32_t height) override {
47 texture.updateSize(width, height, texture.internalFormat(), texture.format(),
48 texture.target());
49 }
50
51 void setBlend(bool blend) override {
52 texture.blend = blend;
53 }
54
55 bool isBlend() const override {
56 return texture.blend;
57 }
58
59 inline GLuint getTextureId() const {
60 return texture.id();
61 }
62
63 inline Texture& getTexture() {
64 return texture;
65 }
66
67 inline GLenum getRenderTarget() const {
68 return texture.target();
69 }
70
71 inline void setRenderTarget(GLenum renderTarget) {
72 texture.mTarget = renderTarget;
73 }
74
75 inline bool isRenderable() const {
76 return texture.target() != GL_NONE;
77 }
78
79 void setWrap(GLenum wrap, bool bindTexture = false, bool force = false) {
80 texture.setWrap(wrap, bindTexture, force);
81 }
82
83 void setFilter(GLenum filter, bool bindTexture = false, bool force = false) {
84 texture.setFilter(filter, bindTexture, force);
85 }
86
87 void bindTexture() const;
88 void generateTexture();
89
90 /**
Greg Daniel8cd3edf2017-01-09 14:15:41 -050091 * Lost the GL context but the layer is still around, mark it invalid internally
92 * so the dtor knows not to do any GL work
93 */
94 void onGlContextLost();
95
96private:
97 Caches& caches;
98
99 /**
100 * The texture backing this layer.
101 */
102 Texture texture;
103}; // struct GlLayer
104
105}; // namespace uirenderer
106}; // namespace android