blob: 2541444488596c6b98fa617f2df651cf84d8b96c [file] [log] [blame]
Chet Haasedd78cca2010-10-22 18:59:26 -07001/*
2 * Copyright (C) 2010 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
Chet Haasedd78cca2010-10-22 18:59:26 -070017#include "Caches.h"
Chris Craik65fe5ee2015-01-26 18:06:29 -080018
Greg Daniel8cd3edf2017-01-09 14:15:41 -050019#include "GlLayer.h"
Chris Craik65fe5ee2015-01-26 18:06:29 -080020#include "Properties.h"
John Reck1bcacfd2017-11-03 10:12:19 -070021#include "renderstate/RenderState.h"
John Reckd7db4d72015-05-20 07:18:55 -070022#include "utils/GLUtils.h"
Chris Craik65fe5ee2015-01-26 18:06:29 -080023
John Reck6b507802015-11-03 10:09:59 -080024#include <cutils/properties.h>
Chris Craik65fe5ee2015-01-26 18:06:29 -080025#include <utils/Log.h>
26#include <utils/String8.h>
Chet Haasedd78cca2010-10-22 18:59:26 -070027
28namespace android {
Chet Haasedd78cca2010-10-22 18:59:26 -070029namespace uirenderer {
30
Chris Craik96a5c4c2015-01-27 15:46:35 -080031Caches* Caches::sInstance = nullptr;
32
Chet Haasedd78cca2010-10-22 18:59:26 -070033///////////////////////////////////////////////////////////////////////////////
Romain Guybdf76092011-07-18 15:00:43 -070034// Macros
35///////////////////////////////////////////////////////////////////////////////
36
37#if DEBUG_CACHE_FLUSH
John Reck1bcacfd2017-11-03 10:12:19 -070038#define FLUSH_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guybdf76092011-07-18 15:00:43 -070039#else
John Reck1bcacfd2017-11-03 10:12:19 -070040#define FLUSH_LOGD(...)
Romain Guybdf76092011-07-18 15:00:43 -070041#endif
42
43///////////////////////////////////////////////////////////////////////////////
Chet Haasedd78cca2010-10-22 18:59:26 -070044// Constructors/destructor
45///////////////////////////////////////////////////////////////////////////////
46
John Recke4c1e6c2018-05-24 16:27:35 -070047Caches::Caches(RenderState& renderState) : mInitialized(false) {
Chris Craik96a5c4c2015-01-27 15:46:35 -080048 INIT_LOGD("Creating OpenGL renderer caches");
Romain Guy8ff6b9e2011-11-09 20:10:18 -080049 init();
Romain Guyf9f00162013-05-09 11:50:12 -070050 initStaticProperties();
Chet Haasedd78cca2010-10-22 18:59:26 -070051}
52
Romain Guy3b748a42013-04-17 18:54:38 -070053bool Caches::init() {
54 if (mInitialized) return false;
Romain Guy8ff6b9e2011-11-09 20:10:18 -080055
John Reckfbc8df02014-11-14 16:18:41 -080056 ATRACE_NAME("Caches::init");
57
Chris Craikd41c4d82015-01-05 15:51:13 -080058 mRegionMesh = nullptr;
Romain Guy8ff6b9e2011-11-09 20:10:18 -080059
60 mInitialized = true;
Romain Guy3b748a42013-04-17 18:54:38 -070061
Chris Craik44eb2c02015-01-29 09:45:09 -080062 mPixelBufferState = new PixelBufferState();
63 mTextureState = new TextureState();
Chris Craik138c21f2016-04-28 16:59:42 -070064 mTextureState->constructTexture(*this);
Romain Guy8aa195d2013-06-04 18:00:09 -070065
Romain Guy3b748a42013-04-17 18:54:38 -070066 return true;
Romain Guy8ff6b9e2011-11-09 20:10:18 -080067}
68
Romain Guyf9f00162013-05-09 11:50:12 -070069void Caches::initStaticProperties() {
Romain Guyf9f00162013-05-09 11:50:12 -070070 // OpenGL ES 3.0+ specific features
John Reck1bcacfd2017-11-03 10:12:19 -070071 gpuPixelBuffersEnabled = extensions().hasPixelBufferObjects() &&
72 property_get_bool(PROPERTY_ENABLE_GPU_PIXEL_BUFFERS, true);
Romain Guyf9f00162013-05-09 11:50:12 -070073}
74
Romain Guy8ff6b9e2011-11-09 20:10:18 -080075void Caches::terminate() {
76 if (!mInitialized) return;
Sangkyu Lee441cc422015-12-11 16:05:10 +090077 mRegionMesh.reset(nullptr);
Romain Guy8ff6b9e2011-11-09 20:10:18 -080078
Romain Guy46bfc482013-08-16 18:38:29 -070079 clearGarbage();
80
Chris Craik44eb2c02015-01-29 09:45:09 -080081 delete mPixelBufferState;
82 mPixelBufferState = nullptr;
83 delete mTextureState;
84 mTextureState = nullptr;
Romain Guy8ff6b9e2011-11-09 20:10:18 -080085 mInitialized = false;
Romain Guy5b3b3522010-10-27 18:57:51 -070086}
87
88///////////////////////////////////////////////////////////////////////////////
Romain Guyfe48f652010-11-11 15:36:56 -080089// Memory management
90///////////////////////////////////////////////////////////////////////////////
91
John Recke170fb62018-05-07 08:12:07 -070092void Caches::clearGarbage() {}
Romain Guyfe48f652010-11-11 15:36:56 -080093
Romain Guybdf76092011-07-18 15:00:43 -070094void Caches::flush(FlushMode mode) {
Chet Haase6a2d17f2012-09-30 12:14:13 -070095 clearGarbage();
John Reck4ced2622014-09-19 10:10:19 -070096 glFinish();
John Reckd7db4d72015-05-20 07:18:55 -070097 // Errors during cleanup should be considered non-fatal, dump them and
98 // and move on. TODO: All errors or just errors like bad surface?
99 GLUtils::dumpGLErrors();
Romain Guybdf76092011-07-18 15:00:43 -0700100}
101
John Reck1bcacfd2017-11-03 10:12:19 -0700102}; // namespace uirenderer
103}; // namespace android