| John Reck | 867c43d | 2018-08-30 16:47:59 +0000 | [diff] [blame^] | 1 | /* | 
 | 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 |  | 
 | 17 | #include "Caches.h" | 
 | 18 |  | 
 | 19 | #include "GlLayer.h" | 
 | 20 | #include "Properties.h" | 
 | 21 | #include "renderstate/RenderState.h" | 
 | 22 | #include "utils/GLUtils.h" | 
 | 23 |  | 
 | 24 | #include <cutils/properties.h> | 
 | 25 | #include <utils/Log.h> | 
 | 26 | #include <utils/String8.h> | 
 | 27 |  | 
 | 28 | namespace android { | 
 | 29 | namespace uirenderer { | 
 | 30 |  | 
 | 31 | Caches* Caches::sInstance = nullptr; | 
 | 32 |  | 
 | 33 | /////////////////////////////////////////////////////////////////////////////// | 
 | 34 | // Macros | 
 | 35 | /////////////////////////////////////////////////////////////////////////////// | 
 | 36 |  | 
 | 37 | #if DEBUG_CACHE_FLUSH | 
 | 38 | #define FLUSH_LOGD(...) ALOGD(__VA_ARGS__) | 
 | 39 | #else | 
 | 40 | #define FLUSH_LOGD(...) | 
 | 41 | #endif | 
 | 42 |  | 
 | 43 | /////////////////////////////////////////////////////////////////////////////// | 
 | 44 | // Constructors/destructor | 
 | 45 | /////////////////////////////////////////////////////////////////////////////// | 
 | 46 |  | 
 | 47 | Caches::Caches(RenderState& renderState) : mInitialized(false) { | 
 | 48 |     INIT_LOGD("Creating OpenGL renderer caches"); | 
 | 49 |     init(); | 
 | 50 |     initStaticProperties(); | 
 | 51 | } | 
 | 52 |  | 
 | 53 | bool Caches::init() { | 
 | 54 |     if (mInitialized) return false; | 
 | 55 |  | 
 | 56 |     ATRACE_NAME("Caches::init"); | 
 | 57 |  | 
 | 58 |     mRegionMesh = nullptr; | 
 | 59 |  | 
 | 60 |     mInitialized = true; | 
 | 61 |  | 
 | 62 |     mPixelBufferState = new PixelBufferState(); | 
 | 63 |     mTextureState = new TextureState(); | 
 | 64 |     mTextureState->constructTexture(*this); | 
 | 65 |  | 
 | 66 |     return true; | 
 | 67 | } | 
 | 68 |  | 
 | 69 | void Caches::initStaticProperties() { | 
 | 70 |     // OpenGL ES 3.0+ specific features | 
 | 71 |     gpuPixelBuffersEnabled = extensions().hasPixelBufferObjects() && | 
 | 72 |                              property_get_bool(PROPERTY_ENABLE_GPU_PIXEL_BUFFERS, true); | 
 | 73 | } | 
 | 74 |  | 
 | 75 | void Caches::terminate() { | 
 | 76 |     if (!mInitialized) return; | 
 | 77 |     mRegionMesh.reset(nullptr); | 
 | 78 |  | 
 | 79 |     clearGarbage(); | 
 | 80 |  | 
 | 81 |     delete mPixelBufferState; | 
 | 82 |     mPixelBufferState = nullptr; | 
 | 83 |     delete mTextureState; | 
 | 84 |     mTextureState = nullptr; | 
 | 85 |     mInitialized = false; | 
 | 86 | } | 
 | 87 |  | 
 | 88 | /////////////////////////////////////////////////////////////////////////////// | 
 | 89 | // Memory management | 
 | 90 | /////////////////////////////////////////////////////////////////////////////// | 
 | 91 |  | 
 | 92 | void Caches::clearGarbage() {} | 
 | 93 |  | 
 | 94 | void Caches::flush(FlushMode mode) { | 
 | 95 |     clearGarbage(); | 
 | 96 |     glFinish(); | 
 | 97 |     // 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(); | 
 | 100 | } | 
 | 101 |  | 
 | 102 | };  // namespace uirenderer | 
 | 103 | };  // namespace android |