Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 23 | namespace android { |
| 24 | namespace uirenderer { |
| 25 | |
| 26 | // Forward declarations |
| 27 | class Caches; |
| 28 | |
| 29 | /** |
| 30 | * A layer has dimensions and is backed by an OpenGL texture or FBO. |
| 31 | */ |
| 32 | class GlLayer : public Layer { |
| 33 | public: |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 34 | GlLayer(RenderState& renderState, uint32_t layerWidth, uint32_t layerHeight, |
Derek Sollenberger | 551d08e | 2018-04-20 16:13:31 -0400 | [diff] [blame] | 35 | sk_sp<SkColorFilter> colorFilter, int alpha, SkBlendMode mode, bool blend); |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 36 | virtual ~GlLayer(); |
| 37 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 38 | uint32_t getWidth() const override { return texture.mWidth; } |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 39 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 40 | uint32_t getHeight() const override { return texture.mHeight; } |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 41 | |
| 42 | void setSize(uint32_t width, uint32_t height) override { |
Romain Guy | caaaa66 | 2017-03-27 00:40:21 -0700 | [diff] [blame] | 43 | texture.updateLayout(width, height, texture.internalFormat(), texture.format(), |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 44 | texture.target()); |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 45 | } |
| 46 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 47 | void setBlend(bool blend) override { texture.blend = blend; } |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 48 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 49 | bool isBlend() const override { return texture.blend; } |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 50 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 51 | inline GLuint getTextureId() const { return texture.id(); } |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 52 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 53 | inline Texture& getTexture() { return texture; } |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 54 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 55 | inline GLenum getRenderTarget() const { return texture.target(); } |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 56 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 57 | inline bool isRenderable() const { return texture.target() != GL_NONE; } |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 58 | |
Chris Craik | 09df887 | 2017-02-14 12:37:49 -0800 | [diff] [blame] | 59 | void setRenderTarget(GLenum renderTarget); |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 60 | |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 61 | void generateTexture(); |
| 62 | |
| 63 | /** |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 64 | * 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 | |
| 69 | private: |
| 70 | Caches& caches; |
| 71 | |
| 72 | /** |
| 73 | * The texture backing this layer. |
| 74 | */ |
| 75 | Texture texture; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 76 | }; // struct GlLayer |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 77 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 78 | }; // namespace uirenderer |
| 79 | }; // namespace android |