blob: 9f70fdae6790c2fe2c8bd80fa8d117a1536002a7 [file] [log] [blame]
John Reck867c43d2018-08-30 16:47:59 +00001/*
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 sk_sp<SkColorFilter> colorFilter, int alpha, SkBlendMode mode, bool blend);
36 virtual ~GlLayer();
37
38 uint32_t getWidth() const override { return texture.mWidth; }
39
40 uint32_t getHeight() const override { return texture.mHeight; }
41
42 void setSize(uint32_t width, uint32_t height) override {
43 texture.updateLayout(width, height, texture.internalFormat(), texture.format(),
44 texture.target());
45 }
46
47 void setBlend(bool blend) override { texture.blend = blend; }
48
49 bool isBlend() const override { return texture.blend; }
50
51 inline GLuint getTextureId() const { return texture.id(); }
52
53 inline GLenum getRenderTarget() const { return texture.target(); }
54
55 void setRenderTarget(GLenum renderTarget);
56
57 void generateTexture();
58
59 /**
60 * Lost the GL context but the layer is still around, mark it invalid internally
61 * so the dtor knows not to do any GL work
62 */
63 void onGlContextLost();
64
65private:
66 Caches& caches;
67
68 /**
69 * The texture backing this layer.
70 */
71 Texture texture;
72}; // struct GlLayer
73
74}; // namespace uirenderer
75}; // namespace android