Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 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 Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 18 | |
| 19 | using namespace android; |
| 20 | using namespace android::renderscript; |
| 21 | |
| 22 | ObjectBase::ObjectBase() |
| 23 | { |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 24 | mUserRefCount = 0; |
| 25 | mSysRefCount = 0; |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 26 | mName = NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | ObjectBase::~ObjectBase() |
| 30 | { |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 31 | //LOGV("~ObjectBase %p ref %i", this, mRefCount); |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 32 | rsAssert(!mUserRefCount); |
| 33 | rsAssert(!mSysRefCount); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 36 | void ObjectBase::incUserRef() const |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 37 | { |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 38 | mUserRefCount ++; |
Jason Sams | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 39 | //LOGV("ObjectBase %p inc ref %i", this, mRefCount); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 42 | void ObjectBase::incSysRef() const |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 43 | { |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 44 | mSysRefCount ++; |
| 45 | //LOGV("ObjectBase %p inc ref %i", this, mRefCount); |
| 46 | } |
| 47 | |
| 48 | void ObjectBase::decUserRef() const |
| 49 | { |
| 50 | rsAssert(mUserRefCount > 0); |
| 51 | mUserRefCount --; |
Jason Sams | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 52 | //LOGV("ObjectBase %p dec ref %i", this, mRefCount); |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 53 | 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 | |
| 63 | void ObjectBase::decSysRef() const |
| 64 | { |
| 65 | rsAssert(mSysRefCount > 0); |
| 66 | mSysRefCount --; |
| 67 | //LOGV("ObjectBase %p dec ref %i", this, mRefCount); |
| 68 | if (!(mSysRefCount | mUserRefCount)) { |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 69 | 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 Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 74 | delete this; |
| 75 | } |
| 76 | } |
| 77 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 78 | void 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 Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 87 | |
| 88 | void 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 | |