OSDN Git Service

Revert "Deleting objects on the wrong thread is a silly idea Bug #7195815"
[android-x86/frameworks-base.git] / libs / hwui / Layer.cpp
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 "OpenGLRenderer.h"
23 #include "Caches.h"
24
25 namespace android {
26 namespace uirenderer {
27
28 Layer::Layer(const uint32_t layerWidth, const uint32_t layerHeight) {
29     mesh = NULL;
30     meshIndices = NULL;
31     meshElementCount = 0;
32     cacheable = true;
33     textureLayer = false;
34     renderTarget = GL_TEXTURE_2D;
35     texture.width = layerWidth;
36     texture.height = layerHeight;
37     colorFilter = NULL;
38     deferredUpdateScheduled = false;
39     renderer = NULL;
40     displayList = NULL;
41     fbo = 0;
42     Caches::getInstance().resourceCache.incrementRefcount(this);
43 }
44
45 Layer::~Layer() {
46     if (mesh) delete mesh;
47     if (meshIndices) delete meshIndices;
48     if (colorFilter) Caches::getInstance().resourceCache.decrementRefcount(colorFilter);
49     if (fbo) Caches::getInstance().fboCache.put(fbo);
50     deleteTexture();
51 }
52
53 void Layer::freeResourcesLocked() {
54     if (colorFilter) {
55         Caches::getInstance().resourceCache.decrementRefcountLocked(colorFilter);
56         colorFilter = NULL;
57     }
58 }
59
60 void Layer::setPaint(SkPaint* paint) {
61     OpenGLRenderer::getAlphaAndModeDirect(paint, &alpha, &mode);
62 }
63
64 void Layer::setColorFilter(SkiaColorFilter* filter) {
65     if (colorFilter) {
66         Caches::getInstance().resourceCache.decrementRefcount(colorFilter);
67     }
68     colorFilter = filter;
69     if (colorFilter) {
70         Caches::getInstance().resourceCache.incrementRefcount(colorFilter);
71     }
72 }
73
74
75
76 }; // namespace uirenderer
77 }; // namespace android