blob: 973e15f0900cc8ee81db2446d927d7e786fca27d [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 Sams221a4b12012-02-22 15:22:41 -080017#include "RenderScript.h"
Tim Murrayeeaf7142013-09-09 15:03:50 -070018#include "rsCppInternal.h"
Jason Sams221a4b12012-02-22 15:22:41 -080019
Chih-Hung Hsiehdfcfabf2016-11-04 15:55:18 -070020using android::RSC::BaseObj;
Jason Sams69cccdf2012-04-02 19:11:49 -070021
Jason Sams221a4b12012-02-22 15:22:41 -080022void * BaseObj::getID() const {
Chris Wailes44bef6f2014-08-12 13:51:10 -070023 if (mID == nullptr) {
Jason Sams221a4b12012-02-22 15:22:41 -080024 ALOGE("Internal error: Object id 0.");
25 }
26 return mID;
27}
28
Chih-Hung Hsieh45768e12016-08-10 12:32:11 -070029void * BaseObj::getObjID(const sp<const BaseObj>& o) {
Chris Wailes44bef6f2014-08-12 13:51:10 -070030 return o == nullptr ? nullptr : o->getID();
Jason Samsb2e3dc52012-02-23 17:14:39 -080031}
32
33
Tim Murray84bf2b82012-10-31 16:03:16 -070034BaseObj::BaseObj(void *id, sp<RS> rs) {
Tim Murray35609072013-12-03 11:36:03 -080035 mRS = rs.get();
Jason Sams221a4b12012-02-22 15:22:41 -080036 mID = id;
37}
38
39void BaseObj::checkValid() {
40 if (mID == 0) {
41 ALOGE("Invalid object.");
42 }
43}
44
45BaseObj::~BaseObj() {
Tim Murray35609072013-12-03 11:36:03 -080046 if (mRS && mRS->getContext()) {
47 RS::dispatch->ObjDestroy(mRS->getContext(), mID);
48 }
Chris Wailes44bef6f2014-08-12 13:51:10 -070049 mRS = nullptr;
50 mID = nullptr;
Jason Sams221a4b12012-02-22 15:22:41 -080051}
52
53void BaseObj::updateFromNative() {
Chris Wailes44bef6f2014-08-12 13:51:10 -070054 const char *name = nullptr;
Tim Murray4a92d122013-07-22 10:56:18 -070055 RS::dispatch->GetName(mRS->getContext(), mID, &name);
Jason Sams221a4b12012-02-22 15:22:41 -080056 mName = name;
57}
58
Chih-Hung Hsieh45768e12016-08-10 12:32:11 -070059bool BaseObj::equals(const sp<const BaseObj>& obj) {
Miao Wangcf067b82015-09-14 18:27:17 -070060 // Early-out check to see if both BaseObjs are actually the same.
Tim Murray89daad62013-07-29 14:30:02 -070061 if (this == obj.get())
Jason Sams221a4b12012-02-22 15:22:41 -080062 return true;
63 return mID == obj->mID;
64}