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 | #include "GlLayer.h" |
| 18 | |
| 19 | #include "Caches.h" |
| 20 | #include "RenderNode.h" |
| 21 | #include "renderstate/RenderState.h" |
| 22 | #include "utils/TraceUtils.h" |
| 23 | |
| 24 | #include <utils/Log.h> |
| 25 | |
| 26 | #define ATRACE_LAYER_WORK(label) \ |
| 27 | ATRACE_FORMAT("%s HW Layer DisplayList %s %ux%u", \ |
| 28 | label, \ |
| 29 | (renderNode.get() != NULL) ? renderNode->getName() : "", \ |
| 30 | getWidth(), getHeight()) |
| 31 | |
| 32 | namespace android { |
| 33 | namespace uirenderer { |
| 34 | |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 35 | GlLayer::GlLayer(RenderState& renderState, uint32_t layerWidth, uint32_t layerHeight, |
| 36 | SkColorFilter* colorFilter, int alpha, SkBlendMode mode, bool blend) |
| 37 | : Layer(renderState, Api::OpenGL, colorFilter, alpha, mode) |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 38 | , caches(Caches::getInstance()) |
| 39 | , texture(caches) { |
| 40 | texture.mWidth = layerWidth; |
| 41 | texture.mHeight = layerHeight; |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 42 | texture.blend = blend; |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | GlLayer::~GlLayer() { |
sergeyv | 00eb43d | 2017-02-13 14:34:15 -0800 | [diff] [blame] | 46 | // There's a rare possibility that Caches could have been destroyed already |
| 47 | // since this method is queued up as a task. |
| 48 | // Since this is a reset method, treat this as non-fatal. |
| 49 | if (caches.isInitialized() && texture.mId) { |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 50 | texture.deleteTexture(); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | void GlLayer::onGlContextLost() { |
| 55 | texture.deleteTexture(); |
| 56 | } |
| 57 | |
Chris Craik | 09df887 | 2017-02-14 12:37:49 -0800 | [diff] [blame] | 58 | void GlLayer::setRenderTarget(GLenum renderTarget) { |
| 59 | if (renderTarget != getRenderTarget()) { |
| 60 | // new render target: bind with new target, and update filter/wrap |
| 61 | texture.mTarget = renderTarget; |
| 62 | if (texture.mId) { |
| 63 | caches.textureState().bindTexture(texture.target(), texture.mId); |
| 64 | } |
| 65 | texture.setFilter(GL_NEAREST, false, true); |
| 66 | texture.setWrap(GL_CLAMP_TO_EDGE, false, true); |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
| 70 | void GlLayer::generateTexture() { |
| 71 | if (!texture.mId) { |
| 72 | glGenTextures(1, &texture.mId); |
| 73 | } |
| 74 | } |
| 75 | |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 76 | }; // namespace uirenderer |
| 77 | }; // namespace android |