blob: 1b091914f318629cef0f83f7cb0a01ab2e983a8f [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
John Reck1bcacfd2017-11-03 10:12:19 -070038 uint32_t getWidth() const override { return texture.mWidth; }
Greg Daniel8cd3edf2017-01-09 14:15:41 -050039
John Reck1bcacfd2017-11-03 10:12:19 -070040 uint32_t getHeight() const override { return texture.mHeight; }
Greg Daniel8cd3edf2017-01-09 14:15:41 -050041
42 void setSize(uint32_t width, uint32_t height) override {
Romain Guycaaaa662017-03-27 00:40:21 -070043 texture.updateLayout(width, height, texture.internalFormat(), texture.format(),
John Reck1bcacfd2017-11-03 10:12:19 -070044 texture.target());
Greg Daniel8cd3edf2017-01-09 14:15:41 -050045 }
46
John Reck1bcacfd2017-11-03 10:12:19 -070047 void setBlend(bool blend) override { texture.blend = blend; }
Greg Daniel8cd3edf2017-01-09 14:15:41 -050048
John Reck1bcacfd2017-11-03 10:12:19 -070049 bool isBlend() const override { return texture.blend; }
Greg Daniel8cd3edf2017-01-09 14:15:41 -050050
John Reck1bcacfd2017-11-03 10:12:19 -070051 inline GLuint getTextureId() const { return texture.id(); }
Greg Daniel8cd3edf2017-01-09 14:15:41 -050052
John Reck1bcacfd2017-11-03 10:12:19 -070053 inline Texture& getTexture() { return texture; }
Greg Daniel8cd3edf2017-01-09 14:15:41 -050054
John Reck1bcacfd2017-11-03 10:12:19 -070055 inline GLenum getRenderTarget() const { return texture.target(); }
Greg Daniel8cd3edf2017-01-09 14:15:41 -050056
John Reck1bcacfd2017-11-03 10:12:19 -070057 inline bool isRenderable() const { return texture.target() != GL_NONE; }
Greg Daniel8cd3edf2017-01-09 14:15:41 -050058
Chris Craik09df8872017-02-14 12:37:49 -080059 void setRenderTarget(GLenum renderTarget);
Greg Daniel8cd3edf2017-01-09 14:15:41 -050060
Greg Daniel8cd3edf2017-01-09 14:15:41 -050061 void generateTexture();
62
63 /**
Greg Daniel8cd3edf2017-01-09 14:15:41 -050064 * Lost the GL context but the layer is still around, mark it invalid internally
65 * so the dtor knows not to do any GL work
66 */
67 void onGlContextLost();
68
69private:
70 Caches& caches;
71
72 /**
73 * The texture backing this layer.
74 */
75 Texture texture;
John Reck1bcacfd2017-11-03 10:12:19 -070076}; // struct GlLayer
Greg Daniel8cd3edf2017-01-09 14:15:41 -050077
John Reck1bcacfd2017-11-03 10:12:19 -070078}; // namespace uirenderer
79}; // namespace android