blob: cd2e57131c9f522ab93aaa541a3ff9d0b2d50fd8 [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"
Romain Guy8a137492012-09-25 15:49:03 -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;
34 textureLayer = false;
35 renderTarget = GL_TEXTURE_2D;
36 texture.width = layerWidth;
37 texture.height = layerHeight;
38 colorFilter = NULL;
39 deferredUpdateScheduled = false;
40 renderer = NULL;
41 displayList = NULL;
42 fbo = 0;
43 Caches::getInstance().resourceCache.incrementRefcount(this);
44}
45
Chet Haased15ebf22012-09-05 11:40:29 -070046Layer::~Layer() {
47 if (mesh) delete mesh;
48 if (meshIndices) delete meshIndices;
49 if (colorFilter) Caches::getInstance().resourceCache.decrementRefcount(colorFilter);
Romain Guy8a137492012-09-25 15:49:03 -070050 if (fbo) {
51 LayerRenderer::flushLayer(this);
52 Caches::getInstance().fboCache.put(fbo);
53 fbo = 0;
Romain Guy97dc9172012-09-23 17:46:45 -070054 }
Romain Guy8a137492012-09-25 15:49:03 -070055 deleteTexture();
Romain Guy97dc9172012-09-23 17:46:45 -070056}
57
Chet Haased15ebf22012-09-05 11:40:29 -070058void Layer::setPaint(SkPaint* paint) {
59 OpenGLRenderer::getAlphaAndModeDirect(paint, &alpha, &mode);
60}
61
62void Layer::setColorFilter(SkiaColorFilter* filter) {
63 if (colorFilter) {
64 Caches::getInstance().resourceCache.decrementRefcount(colorFilter);
65 }
66 colorFilter = filter;
67 if (colorFilter) {
68 Caches::getInstance().resourceCache.incrementRefcount(colorFilter);
69 }
70}
71
Chet Haased15ebf22012-09-05 11:40:29 -070072}; // namespace uirenderer
73}; // namespace android