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 #include "RenderScript.h" 18 #include "rsCppInternal.h" 19 20 using namespace android; 21 using namespace RSC; 22 getID() const23void * BaseObj::getID() const { 24 if (mID == nullptr) { 25 ALOGE("Internal error: Object id 0."); 26 } 27 return mID; 28 } 29 getObjID(sp<const BaseObj> o)30void * BaseObj::getObjID(sp<const BaseObj> o) { 31 return o == nullptr ? nullptr : o->getID(); 32 } 33 34 BaseObj(void * id,sp<RS> rs)35BaseObj::BaseObj(void *id, sp<RS> rs) { 36 mRS = rs.get(); 37 mID = id; 38 } 39 checkValid()40void BaseObj::checkValid() { 41 if (mID == 0) { 42 ALOGE("Invalid object."); 43 } 44 } 45 ~BaseObj()46BaseObj::~BaseObj() { 47 if (mRS && mRS->getContext()) { 48 RS::dispatch->ObjDestroy(mRS->getContext(), mID); 49 } 50 mRS = nullptr; 51 mID = nullptr; 52 } 53 updateFromNative()54void BaseObj::updateFromNative() { 55 const char *name = nullptr; 56 RS::dispatch->GetName(mRS->getContext(), mID, &name); 57 mName = name; 58 } 59 equals(sp<const BaseObj> obj)60bool BaseObj::equals(sp<const BaseObj> obj) { 61 // Early-out check to see if both BaseObjs are actually the same 62 if (this == obj.get()) 63 return true; 64 return mID == obj->mID; 65 } 66