BaseObj.cpp revision b206acefa7ef03e02d3e8e161f8a1493329246b3
1/*
2 * Copyright (C) 2012 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#define LOG_TAG "libRS_cpp"
18
19#include "RenderScript.h"
20#include <rs.h>
21
22using namespace android;
23using namespace RSC;
24
25void * BaseObj::getID() const {
26    if (mID == NULL) {
27        ALOGE("Internal error: Object id 0.");
28    }
29    return mID;
30}
31
32void * BaseObj::getObjID(sp<const BaseObj> o) {
33    return o.get() == NULL ? NULL : o->getID();
34}
35
36
37BaseObj::BaseObj(void *id, sp<RS> rs) {
38    mRS = rs;
39    mID = id;
40}
41
42void BaseObj::checkValid() {
43    if (mID == 0) {
44        ALOGE("Invalid object.");
45    }
46}
47
48BaseObj::~BaseObj() {
49    rsObjDestroy(mRS->getContext(), mID);
50    mRS = NULL;
51    mID = NULL;
52}
53
54void BaseObj::updateFromNative() {
55    const char *name = NULL;
56    rsaGetName(mRS->getContext(), mID, &name);
57    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}
66