2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <cutils/log.h>
23 namespace uirenderer {
25 extern pthread_t gGpuThread;
27 #define ASSERT_GPU_THREAD() LOG_ALWAYS_FATAL_IF( \
28 !pthread_equal(gGpuThread, pthread_self()), \
29 "Error, %p of type %d (size=%d) used on wrong thread! cur thread %lu " \
30 "!= gpu thread %lu", this, static_cast<int>(mType), mSize, \
31 pthread_self(), gGpuThread)
33 enum class GpuObjectType {
41 class GpuMemoryTracker {
43 GpuObjectType objectType() { return mType; }
44 int objectSize() { return mSize; }
46 static void onGLContextCreated();
47 static void onGLContextDestroyed();
49 static void dump(std::ostream& stream);
50 static int getInstanceCount(GpuObjectType type);
51 static int getTotalSize(GpuObjectType type);
52 static void onFrameCompleted();
55 GpuMemoryTracker(GpuObjectType type) : mType(type) {
57 startTrackingObject();
65 void notifySizeChanged(int newSize);
68 void startTrackingObject();
69 void stopTrackingObject();
75 } // namespace uirenderer
76 } // namespace android;