blob: 1d85b704e5ad78a2d05f440aa32bead5c3a9f893 [file] [log] [blame]
Chet Haased15ebf22012-09-05 11:40:29 -07001/*
2 * Copyright (C) 2012 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#define LOG_TAG "OpenGLRenderer"
18
19#include <utils/Log.h>
20
21#include "Layer.h"
Chet Haase98d3a642012-09-26 10:27:40 -070022#include "LayerRenderer.h"
Chet Haased15ebf22012-09-05 11:40:29 -070023#include "OpenGLRenderer.h"
24#include "Caches.h"
25
26namespace android {
27namespace uirenderer {
28
Chet Haase603f6de2012-09-14 15:31:25 -070029Layer::Layer(const uint32_t layerWidth, const uint32_t layerHeight) {
30 mesh = NULL;
31 meshIndices = NULL;
32 meshElementCount = 0;
33 cacheable = true;
Romain Guy7c25aab2012-10-18 15:05:02 -070034 dirty = false;
Chet Haase603f6de2012-09-14 15:31:25 -070035 textureLayer = false;
36 renderTarget = GL_TEXTURE_2D;
37 texture.width = layerWidth;
38 texture.height = layerHeight;
39 colorFilter = NULL;
40 deferredUpdateScheduled = false;
41 renderer = NULL;
42 displayList = NULL;
43 fbo = 0;
Romain Guy8ce00302013-01-15 18:51:42 -080044 stencil = 0;
Romain Guy5bb3c732012-11-29 17:52:58 -080045 debugDrawUpdate = false;
Chet Haase603f6de2012-09-14 15:31:25 -070046 Caches::getInstance().resourceCache.incrementRefcount(this);
47}
48
Chet Haased15ebf22012-09-05 11:40:29 -070049Layer::~Layer() {
50 if (mesh) delete mesh;
51 if (meshIndices) delete meshIndices;
52 if (colorFilter) Caches::getInstance().resourceCache.decrementRefcount(colorFilter);
Chet Haase98d3a642012-09-26 10:27:40 -070053 removeFbo();
Romain Guy8a137492012-09-25 15:49:03 -070054 deleteTexture();
Romain Guy97dc9172012-09-23 17:46:45 -070055}
56
Romain Guy8ce00302013-01-15 18:51:42 -080057void Layer::removeFbo(bool flush) {
58 if (stencil) {
59 // TODO: recycle & cache instead of simply deleting
60 GLuint previousFbo;
61 glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*) &previousFbo);
62 if (fbo != previousFbo) glBindFramebuffer(GL_FRAMEBUFFER, fbo);
63 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
64 if (fbo != previousFbo) glBindFramebuffer(GL_FRAMEBUFFER, previousFbo);
65
66 glDeleteRenderbuffers(1, &stencil);
67 stencil = 0;
68 }
69
Chet Haase98d3a642012-09-26 10:27:40 -070070 if (fbo) {
Romain Guy8ce00302013-01-15 18:51:42 -080071 if (flush) LayerRenderer::flushLayer(this);
72 // If put fails the cache will delete the FBO
Chet Haase98d3a642012-09-26 10:27:40 -070073 Caches::getInstance().fboCache.put(fbo);
74 fbo = 0;
Dave Burke56257af2012-09-25 20:30:09 -070075 }
76}
77
Chet Haased15ebf22012-09-05 11:40:29 -070078void Layer::setPaint(SkPaint* paint) {
79 OpenGLRenderer::getAlphaAndModeDirect(paint, &alpha, &mode);
80}
81
82void Layer::setColorFilter(SkiaColorFilter* filter) {
83 if (colorFilter) {
84 Caches::getInstance().resourceCache.decrementRefcount(colorFilter);
85 }
86 colorFilter = filter;
87 if (colorFilter) {
88 Caches::getInstance().resourceCache.incrementRefcount(colorFilter);
89 }
90}
91
Chet Haased15ebf22012-09-05 11:40:29 -070092}; // namespace uirenderer
93}; // namespace android