blob: 7e7afabe0550077579e01c0edb0764e4c13138e5 [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
2 * Copyright (C) 2009 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 "rsObjectBase.h"
Jason Sams326e0dd2009-05-22 14:03:28 -070018
19using namespace android;
20using namespace android::renderscript;
21
22ObjectBase::ObjectBase()
23{
Jason Sams9397e302009-08-27 20:23:34 -070024 mUserRefCount = 0;
25 mSysRefCount = 0;
Jason Samsa0a1b6f2009-06-10 15:04:38 -070026 mName = NULL;
Jason Sams326e0dd2009-05-22 14:03:28 -070027}
28
29ObjectBase::~ObjectBase()
30{
Jason Samse5ffb872009-08-09 17:01:55 -070031 //LOGV("~ObjectBase %p ref %i", this, mRefCount);
Jason Sams9397e302009-08-27 20:23:34 -070032 rsAssert(!mUserRefCount);
33 rsAssert(!mSysRefCount);
Jason Sams326e0dd2009-05-22 14:03:28 -070034}
35
Jason Sams9397e302009-08-27 20:23:34 -070036void ObjectBase::incUserRef() const
Jason Sams326e0dd2009-05-22 14:03:28 -070037{
Jason Sams9397e302009-08-27 20:23:34 -070038 mUserRefCount ++;
Jason Sams992a0b72009-06-23 12:22:47 -070039 //LOGV("ObjectBase %p inc ref %i", this, mRefCount);
Jason Sams326e0dd2009-05-22 14:03:28 -070040}
41
Jason Sams9397e302009-08-27 20:23:34 -070042void ObjectBase::incSysRef() const
Jason Sams326e0dd2009-05-22 14:03:28 -070043{
Jason Sams9397e302009-08-27 20:23:34 -070044 mSysRefCount ++;
45 //LOGV("ObjectBase %p inc ref %i", this, mRefCount);
46}
47
48void ObjectBase::decUserRef() const
49{
50 rsAssert(mUserRefCount > 0);
51 mUserRefCount --;
Jason Sams992a0b72009-06-23 12:22:47 -070052 //LOGV("ObjectBase %p dec ref %i", this, mRefCount);
Jason Sams9397e302009-08-27 20:23:34 -070053 if (!(mSysRefCount | mUserRefCount)) {
54 if (mName) {
55 LOGV("Deleting RS object %p, name %s", this, mName);
56 } else {
57 LOGV("Deleting RS object %p, no name", this);
58 }
59 delete this;
60 }
61}
62
63void ObjectBase::decSysRef() const
64{
65 rsAssert(mSysRefCount > 0);
66 mSysRefCount --;
67 //LOGV("ObjectBase %p dec ref %i", this, mRefCount);
68 if (!(mSysRefCount | mUserRefCount)) {
Jason Samsafcb25c2009-08-25 11:34:49 -070069 if (mName) {
70 LOGV("Deleting RS object %p, name %s", this, mName);
71 } else {
72 LOGV("Deleting RS object %p, no name", this);
73 }
Jason Sams326e0dd2009-05-22 14:03:28 -070074 delete this;
75 }
76}
77
Jason Samsa0a1b6f2009-06-10 15:04:38 -070078void ObjectBase::setName(const char *name)
79{
80 delete mName;
81 mName = NULL;
82 if (name) {
83 mName = new char[strlen(name) +1];
84 strcpy(mName, name);
85 }
86}
Jason Samsa4a54e42009-06-10 18:39:40 -070087
88void ObjectBase::setName(const char *name, uint32_t len)
89{
90 delete mName;
91 mName = NULL;
92 if (name) {
93 mName = new char[len + 1];
94 memcpy(mName, name, len);
95 mName[len] = 0;
96 }
97}
98