Layer.cpp revision 5bb3c730f5ebd2a0db1b02a8981c6fdbea6c1a2e
1/*
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"
22#include "LayerRenderer.h"
23#include "OpenGLRenderer.h"
24#include "Caches.h"
25
26namespace android {
27namespace uirenderer {
28
29Layer::Layer(const uint32_t layerWidth, const uint32_t layerHeight) {
30    mesh = NULL;
31    meshIndices = NULL;
32    meshElementCount = 0;
33    cacheable = true;
34    dirty = false;
35    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;
44    debugDrawUpdate = false;
45    Caches::getInstance().resourceCache.incrementRefcount(this);
46}
47
48Layer::~Layer() {
49    if (mesh) delete mesh;
50    if (meshIndices) delete meshIndices;
51    if (colorFilter) Caches::getInstance().resourceCache.decrementRefcount(colorFilter);
52    removeFbo();
53    deleteTexture();
54}
55
56void Layer::removeFbo() {
57    if (fbo) {
58        LayerRenderer::flushLayer(this);
59        Caches::getInstance().fboCache.put(fbo);
60        fbo = 0;
61    }
62}
63
64void Layer::setPaint(SkPaint* paint) {
65    OpenGLRenderer::getAlphaAndModeDirect(paint, &alpha, &mode);
66}
67
68void Layer::setColorFilter(SkiaColorFilter* filter) {
69    if (colorFilter) {
70        Caches::getInstance().resourceCache.decrementRefcount(colorFilter);
71    }
72    colorFilter = filter;
73    if (colorFilter) {
74        Caches::getInstance().resourceCache.incrementRefcount(colorFilter);
75    }
76}
77
78
79
80}; // namespace uirenderer
81}; // namespace android
82