Stan Iliev | a683eb3 | 2018-09-04 15:42:18 +0000 | [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 | #include "GlLayer.h" |
| 18 | |
| 19 | #include "Caches.h" |
| 20 | #include "RenderNode.h" |
| 21 | #include "renderstate/RenderState.h" |
| 22 | |
| 23 | namespace android { |
| 24 | namespace uirenderer { |
| 25 | |
| 26 | GlLayer::GlLayer(RenderState& renderState, uint32_t layerWidth, uint32_t layerHeight, |
| 27 | sk_sp<SkColorFilter> colorFilter, int alpha, SkBlendMode mode, bool blend) |
| 28 | : Layer(renderState, Api::OpenGL, colorFilter, alpha, mode) |
| 29 | , caches(Caches::getInstance()) |
| 30 | , texture(caches) { |
| 31 | texture.mWidth = layerWidth; |
| 32 | texture.mHeight = layerHeight; |
| 33 | texture.blend = blend; |
| 34 | } |
| 35 | |
| 36 | GlLayer::~GlLayer() { |
| 37 | // There's a rare possibility that Caches could have been destroyed already |
| 38 | // since this method is queued up as a task. |
| 39 | // Since this is a reset method, treat this as non-fatal. |
| 40 | if (caches.isInitialized() && texture.mId) { |
| 41 | texture.deleteTexture(); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | void GlLayer::onGlContextLost() { |
| 46 | texture.deleteTexture(); |
| 47 | } |
| 48 | |
| 49 | void GlLayer::setRenderTarget(GLenum renderTarget) { |
| 50 | if (renderTarget != getRenderTarget()) { |
| 51 | // new render target: bind with new target, and update filter/wrap |
| 52 | texture.mTarget = renderTarget; |
| 53 | if (texture.mId) { |
| 54 | caches.textureState().bindTexture(texture.target(), texture.mId); |
| 55 | } |
| 56 | texture.setFilter(GL_NEAREST, false, true); |
| 57 | texture.setWrap(GL_CLAMP_TO_EDGE, false, true); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | void GlLayer::generateTexture() { |
| 62 | if (!texture.mId) { |
| 63 | glGenTextures(1, &texture.mId); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | }; // namespace uirenderer |
| 68 | }; // namespace android |