blob: fad9440be73ff23307a26d8d9ae09da7d7c36884 [file] [log] [blame]
John Reck3b202512014-06-23 13:13:08 -07001/*
2 * Copyright (C) 2014 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 */
John Reck1bcacfd2017-11-03 10:12:19 -070016#include "renderstate/RenderState.h"
John Reck3b202512014-06-23 13:13:08 -070017
Derek Sollenberger28a4d992018-09-20 13:37:24 -040018#include "renderthread/RenderThread.h"
19#include "GpuMemoryTracker.h"
Romain Guycaaaa662017-03-27 00:40:21 -070020
John Reck3b202512014-06-23 13:13:08 -070021namespace android {
22namespace uirenderer {
23
Derek Sollenberger28a4d992018-09-20 13:37:24 -040024RenderState::RenderState(renderthread::RenderThread& thread) : mRenderThread(thread) {
John Reck0e89e2b2014-10-31 14:49:06 -070025 mThreadId = pthread_self();
John Reck3b202512014-06-23 13:13:08 -070026}
27
Stan Iliev564ca3e2018-09-04 22:00:00 +000028void RenderState::onContextCreated() {
Greg Daniel45ec62b2017-01-04 14:27:00 -050029 GpuMemoryTracker::onGpuContextCreated();
30}
31
Stan Iliev564ca3e2018-09-04 22:00:00 +000032void RenderState::onContextDestroyed() {
Derek Sollenberger5a5a6482018-09-19 13:52:13 -040033 for(auto callback : mContextCallbacks) {
34 callback->onContextDestroyed();
35 }
Greg Daniel45ec62b2017-01-04 14:27:00 -050036 GpuMemoryTracker::onGpuContextDestroyed();
37}
38
John Reck0e89e2b2014-10-31 14:49:06 -070039void RenderState::postDecStrong(VirtualLightRefBase* object) {
John Recka55b5d62016-01-14 15:09:10 -080040 if (pthread_equal(mThreadId, pthread_self())) {
41 object->decStrong(nullptr);
42 } else {
John Reckf8441e62017-10-23 13:10:41 -070043 mRenderThread.queue().post([object]() { object->decStrong(nullptr); });
John Recka55b5d62016-01-14 15:09:10 -080044 }
John Reck0e89e2b2014-10-31 14:49:06 -070045}
46
Chris Craik6c15ffa2015-02-02 13:50:55 -080047///////////////////////////////////////////////////////////////////////////////
48// Render
49///////////////////////////////////////////////////////////////////////////////
50
John Reck3b202512014-06-23 13:13:08 -070051} /* namespace uirenderer */
52} /* namespace android */