blob: d0102d06f3e613c982f2524d0889c0556748e727 [file] [log] [blame]
Jason Sams221a4b12012-02-22 15:22:41 -08001/*
Jason Sams69cccdf2012-04-02 19:11:49 -07002 * Copyright (C) 2012 The Android Open Source Project
Jason Sams221a4b12012-02-22 15:22:41 -08003 *
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
Jason Samsf1e6d222012-02-24 14:24:56 -080017#define LOG_TAG "libRS_cpp"
Jason Sams221a4b12012-02-22 15:22:41 -080018
Jason Sams221a4b12012-02-22 15:22:41 -080019#include "RenderScript.h"
Tim Murrayb206ace2013-02-13 14:52:20 -080020#include <rs.h>
Jason Sams221a4b12012-02-22 15:22:41 -080021
Jason Sams69cccdf2012-04-02 19:11:49 -070022using namespace android;
Tim Murray9eb7f4b2012-11-16 14:02:18 -080023using namespace RSC;
Jason Sams69cccdf2012-04-02 19:11:49 -070024
Jason Sams221a4b12012-02-22 15:22:41 -080025void * BaseObj::getID() const {
26 if (mID == NULL) {
27 ALOGE("Internal error: Object id 0.");
28 }
29 return mID;
30}
31
Jason Sams69cccdf2012-04-02 19:11:49 -070032void * BaseObj::getObjID(sp<const BaseObj> o) {
33 return o.get() == NULL ? NULL : o->getID();
Jason Samsb2e3dc52012-02-23 17:14:39 -080034}
35
36
Tim Murray84bf2b82012-10-31 16:03:16 -070037BaseObj::BaseObj(void *id, sp<RS> rs) {
Jason Sams221a4b12012-02-22 15:22:41 -080038 mRS = rs;
39 mID = id;
40}
41
42void BaseObj::checkValid() {
43 if (mID == 0) {
44 ALOGE("Invalid object.");
45 }
46}
47
48BaseObj::~BaseObj() {
Tim Murray84bf2b82012-10-31 16:03:16 -070049 rsObjDestroy(mRS->getContext(), mID);
Jason Sams221a4b12012-02-22 15:22:41 -080050 mRS = NULL;
51 mID = NULL;
52}
53
54void BaseObj::updateFromNative() {
55 const char *name = NULL;
Tim Murray84bf2b82012-10-31 16:03:16 -070056 rsaGetName(mRS->getContext(), mID, &name);
Jason Sams221a4b12012-02-22 15:22:41 -080057 mName = name;
58}
59
60bool BaseObj::equals(const BaseObj *obj) {
61 // Early-out check to see if both BaseObjs are actually the same
62 if (this == obj)
63 return true;
64 return mID == obj->mID;
65}