blob: c0ab895260abd6f1dee96f5ecc7fff6d5b3cbf9e [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#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
32namespace android {
33namespace uirenderer {
34
35GlLayer::GlLayer(RenderState& renderState, uint32_t layerWidth, uint32_t layerHeight)
36 : Layer(renderState, Api::OpenGL)
37 , caches(Caches::getInstance())
38 , texture(caches) {
39 texture.mWidth = layerWidth;
40 texture.mHeight = layerHeight;
41}
42
43GlLayer::~GlLayer() {
44 if (texture.mId) {
45 texture.deleteTexture();
46 }
47}
48
49void GlLayer::onGlContextLost() {
50 texture.deleteTexture();
51}
52
53void GlLayer::bindTexture() const {
54 if (texture.mId) {
55 caches.textureState().bindTexture(texture.target(), texture.mId);
56 }
57}
58
59void GlLayer::generateTexture() {
60 if (!texture.mId) {
61 glGenTextures(1, &texture.mId);
62 }
63}
64
65void GlLayer::clearTexture() {
66 // There's a rare possibility that Caches could have been destroyed already
67 // since this method is queued up as a task.
68 // Since this is a reset method, treat this as non-fatal.
69 if (caches.isInitialized()) {
70 caches.textureState().unbindTexture(texture.mId);
71 }
72 texture.mId = 0;
73}
74
75}; // namespace uirenderer
76}; // namespace android