Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 22df5b6e authored by Patrick Williams's avatar Patrick Williams
Browse files

Remove implicit sp construction

Bug: 393217449
Flag: EXEMPT refactor
Test: presubmits
Change-Id: Icd8ea1cb3a6704c04b4c42f9c405bb68d31ee835
parent 2723c553
Loading
Loading
Loading
Loading
+24 −23
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#undef ANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION // TODO:remove this and fix code

#define LOG_TAG "BLASTBufferQueue"

@@ -131,13 +130,13 @@ static jlong nativeCreate(JNIEnv* env, jclass clazz, jstring jName,
}

static void nativeDestroy(JNIEnv* env, jclass clazz, jlong ptr) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    queue->decStrong((void*)nativeCreate);
}

static jobject nativeGetSurface(JNIEnv* env, jclass clazz, jlong ptr,
                                jboolean includeSurfaceControlHandle) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    return android_view_Surface_createFromSurface(env,
                                                  queue->getSurface(includeSurfaceControlHandle));
}
@@ -166,7 +165,7 @@ static bool nativeSyncNextTransaction(JNIEnv* env, jclass clazz, jlong ptr, jobj
                                      jboolean acquireSingleBuffer) {
    LOG_ALWAYS_FATAL_IF(!callback, "callback passed in to syncNextTransaction must not be NULL");

    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    JavaVM* vm = nullptr;
    LOG_ALWAYS_FATAL_IF(env->GetJavaVM(&vm) != JNI_OK, "Unable to get Java VM");

@@ -186,51 +185,53 @@ static bool nativeSyncNextTransaction(JNIEnv* env, jclass clazz, jlong ptr, jobj
}

static void nativeStopContinuousSyncTransaction(JNIEnv* env, jclass clazz, jlong ptr) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    queue->stopContinuousSyncTransaction();
}

static void nativeClearSyncTransaction(JNIEnv* env, jclass clazz, jlong ptr) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    queue->clearSyncTransaction();
}

static void nativeUpdate(JNIEnv* env, jclass clazz, jlong ptr, jlong surfaceControl, jlong width,
static void nativeUpdate(JNIEnv* env, jclass clazz, jlong ptr, jlong surfaceControlPtr, jlong width,
                         jlong height, jint format) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    queue->update(reinterpret_cast<SurfaceControl*>(surfaceControl), width, height, format);
    auto queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto surfaceControl = SpFromRawPtr<SurfaceControl>(surfaceControlPtr);
    queue->update(surfaceControl, width, height, format);
}

static void nativeMergeWithNextTransaction(JNIEnv*, jclass clazz, jlong ptr, jlong transactionPtr,
                                           jlong framenumber) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionPtr);
    queue->mergeWithNextTransaction(transaction, CC_UNLIKELY(framenumber < 0) ? 0 : framenumber);
}

static jlong nativeGetLastAcquiredFrameNum(JNIEnv* env, jclass clazz, jlong ptr) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    return queue->getLastAcquiredFrameNum();
}

static void nativeApplyPendingTransactions(JNIEnv* env, jclass clazz, jlong ptr, jlong frameNum) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    queue->applyPendingTransactions(frameNum);
}

static bool nativeIsSameSurfaceControl(JNIEnv* env, jclass clazz, jlong ptr, jlong surfaceControl) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    return queue->isSameSurfaceControl(reinterpret_cast<SurfaceControl*>(surfaceControl));
static bool nativeIsSameSurfaceControl(JNIEnv* env, jclass clazz, jlong ptr,
                                       jlong surfaceControlPtr) {
    auto queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto surfaceControl = SpFromRawPtr<SurfaceControl>(surfaceControlPtr);
    return queue->isSameSurfaceControl(surfaceControl);
}

static void nativeSetTransactionHangCallback(JNIEnv* env, jclass clazz, jlong ptr,
                                             jobject transactionHangCallback) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    if (transactionHangCallback == nullptr) {
        queue->setTransactionHangCallback(nullptr);
    } else {
        sp<TransactionHangCallbackWrapper> wrapper =
                new TransactionHangCallbackWrapper{env, transactionHangCallback};
        auto wrapper = sp<TransactionHangCallbackWrapper>::make(env, transactionHangCallback);
        queue->setTransactionHangCallback(
                [wrapper](const std::string& reason) { wrapper->onTransactionHang(reason); });
    }
@@ -238,26 +239,26 @@ static void nativeSetTransactionHangCallback(JNIEnv* env, jclass clazz, jlong pt

static jobject nativeGatherPendingTransactions(JNIEnv* env, jclass clazz, jlong ptr,
                                               jlong frameNum) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    SurfaceComposerClient::Transaction* transaction = queue->gatherPendingTransactions(frameNum);
    return env->NewObject(gTransactionClassInfo.clazz, gTransactionClassInfo.ctor,
                          reinterpret_cast<jlong>(transaction));
}

static void nativeSetApplyToken(JNIEnv* env, jclass clazz, jlong ptr, jobject applyTokenObject) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    sp<IBinder> token(ibinderForJavaObject(env, applyTokenObject));
    return queue->setApplyToken(std::move(token));
}

static void nativeSetWaitForBufferReleaseCallback(JNIEnv* env, jclass clazz, jlong ptr,
                                                  jobject waitForBufferReleaseCallback) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    auto queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    if (waitForBufferReleaseCallback == nullptr) {
        queue->setWaitForBufferReleaseCallback(nullptr);
    } else {
        sp<WaitForBufferReleaseCallbackWrapper> wrapper =
                new WaitForBufferReleaseCallbackWrapper{env, waitForBufferReleaseCallback};
        auto wrapper =
                sp<WaitForBufferReleaseCallbackWrapper>::make(env, waitForBufferReleaseCallback);
        queue->setWaitForBufferReleaseCallback([wrapper](const nsecs_t durationNanos) {
            wrapper->onWaitForBufferRelease(durationNanos);
        });
+0 −1
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#undef ANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION // TODO:remove this and fix code

#define LOG_TAG "InputWindowHandle"

+67 −70

File changed.

Preview size limit exceeded, changes collapsed.

+3 −5
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#undef ANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION // TODO:remove this and fix code

#define LOG_TAG "ScreenCapture"
// #define LOG_NDEBUG 0
@@ -37,6 +36,7 @@
namespace android {

using gui::CaptureArgs;
using gui::IScreenCaptureListener;

static struct {
    jfieldID pixelFormat;
@@ -216,8 +216,7 @@ static jint nativeCaptureDisplay(JNIEnv* env, jclass clazz, jobject displayCaptu
        return BAD_VALUE;
    }

    sp<gui::IScreenCaptureListener> captureListener =
            reinterpret_cast<gui::IScreenCaptureListener*>(screenCaptureListenerObject);
    auto captureListener = SpFromRawPtr<IScreenCaptureListener>(screenCaptureListenerObject);
    return ScreenshotClient::captureDisplay(captureArgs, captureListener);
}

@@ -236,8 +235,7 @@ static jint nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerCaptureA
    layerCaptureArgs.childrenOnly =
            env->GetBooleanField(layerCaptureArgsObject, gLayerCaptureArgsClassInfo.childrenOnly);

    sp<gui::IScreenCaptureListener> captureListener =
            reinterpret_cast<gui::IScreenCaptureListener*>(screenCaptureListenerObject);
    auto captureListener = SpFromRawPtr<IScreenCaptureListener>(screenCaptureListenerObject);
    return ScreenshotClient::captureLayers(layerCaptureArgs, captureListener, sync);
}

+5 −0
Original line number Diff line number Diff line
@@ -91,6 +91,11 @@ static inline void DieIfException(JNIEnv* env, const char* message) {
    }
}

template <typename T>
inline sp<T> SpFromRawPtr(jlong ptr) {
    return sp<T>::fromExisting(reinterpret_cast<T*>(ptr));
}

}  // namespace android

#endif  // CORE_JNI_HELPERS