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

Commit c1118823 authored by Xin Li's avatar Xin Li Committed by Gerrit Code Review
Browse files

Merge "DO NOT MERGE - Merge Android R QPR1"

parents 370181de 1b5a92da
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@
    <!-- basic system services -->
    <feature name="android.software.connectionservice" />
    <feature name="android.software.voice_recognizers" notLowRam="true" />
    <feature name="android.software.backup" />
    <feature name="android.software.home_screen" />
    <feature name="android.software.companion_device_setup" />
    <feature name="android.software.autofill" />
+1 −1
Original line number Diff line number Diff line
@@ -2685,7 +2685,7 @@ status_t Parcel::restartWrite(size_t desired)

    releaseObjects();

    if (data) {
    if (data || desired == 0) {
        LOG_ALLOC("Parcel %p: restart from %zu to %zu capacity", this, mDataCapacity, desired);
        if (mDataCapacity > desired) {
            gParcelGlobalAllocSize -= (mDataCapacity - desired);
+5 −1
Original line number Diff line number Diff line
@@ -132,7 +132,11 @@ public:
        OP_DEPRECATED_1 = 96,
        OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED = 97,
        OP_AUTO_REVOKE_MANAGED_BY_INSTALLER = 98,
        _NUM_OP = 99
        OP_NO_ISOLATED_STORAGE = 99,
        OP_PHONE_CALL_MICROPHONE = 100,
        OP_PHONE_CALL_CAMERA = 101,
        OP_RECORD_AUDIO_HOTWORD = 102,
        _NUM_OP = 103
    };

    AppOpsManager();
+57 −1
Original line number Diff line number Diff line
@@ -409,6 +409,23 @@ GLESRenderEngine::GLESRenderEngine(const RenderEngineCreationArgs& args, EGLDisp
    mImageManager = std::make_unique<ImageManager>(this);
    mImageManager->initThread();
    mDrawingBuffer = createFramebuffer();
    sp<GraphicBuffer> buf =
            new GraphicBuffer(1, 1, PIXEL_FORMAT_RGBA_8888, 1,
                              GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE, "placeholder");

    const status_t err = buf->initCheck();
    if (err != OK) {
        ALOGE("Error allocating placeholder buffer: %d", err);
        return;
    }
    mPlaceholderBuffer = buf.get();
    EGLint attributes[] = {
            EGL_NONE,
    };
    mPlaceholderImage = eglCreateImageKHR(mEGLDisplay, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
                                          mPlaceholderBuffer, attributes);
    ALOGE_IF(mPlaceholderImage == EGL_NO_IMAGE_KHR, "Failed to create placeholder image: %#x",
             eglGetError());
}

GLESRenderEngine::~GLESRenderEngine() {
@@ -423,6 +440,7 @@ GLESRenderEngine::~GLESRenderEngine() {
        eglDestroyImageKHR(mEGLDisplay, expired);
        DEBUG_EGL_IMAGE_TRACKER_DESTROY();
    }
    eglDestroyImageKHR(mEGLDisplay, mPlaceholderImage);
    mImageCache.clear();
    eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    eglTerminate(mEGLDisplay);
@@ -589,6 +607,9 @@ void GLESRenderEngine::genTextures(size_t count, uint32_t* names) {
}

void GLESRenderEngine::deleteTextures(size_t count, uint32_t const* names) {
    for (int i = 0; i < count; ++i) {
        mTextureView.erase(names[i]);
    }
    glDeleteTextures(count, names);
}

@@ -646,6 +667,7 @@ status_t GLESRenderEngine::bindExternalTextureBuffer(uint32_t texName,
        }

        bindExternalTextureImage(texName, *cachedImage->second);
        mTextureView.insert_or_assign(texName, buffer->getId());
    }

    // Wait for the new buffer to be ready.
@@ -887,7 +909,7 @@ void GLESRenderEngine::unbindFrameBuffer(Framebuffer* /*framebuffer*/) {
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

bool GLESRenderEngine::cleanupPostRender() {
bool GLESRenderEngine::cleanupPostRender(CleanupMode mode) {
    ATRACE_CALL();

    if (mPriorResourcesCleaned ||
@@ -896,6 +918,30 @@ bool GLESRenderEngine::cleanupPostRender() {
        return false;
    }

    // This is a bit of a band-aid fix for FrameCaptureProcessor, as we should
    // not need to keep memory around if we don't need to do so.
    if (mode == CleanupMode::CLEAN_ALL) {
        // TODO: SurfaceFlinger memory utilization may benefit from resetting
        // texture bindings as well. Assess if it does and there's no performance regression
        // when rebinding the same image data to the same texture, and if so then its mode
        // behavior can be tweaked.
        if (mPlaceholderImage != EGL_NO_IMAGE_KHR) {
            for (auto [textureName, bufferId] : mTextureView) {
                if (bufferId && mPlaceholderImage != EGL_NO_IMAGE_KHR) {
                    glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureName);
                    glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES,
                                                 static_cast<GLeglImageOES>(mPlaceholderImage));
                    mTextureView[textureName] = std::nullopt;
                    checkErrors();
                }
            }
        }
        {
            std::lock_guard<std::mutex> lock(mRenderingMutex);
            mImageCache.clear();
        }
    }

    // Bind the texture to placeholder so that backing image data can be freed.
    GLFramebuffer* glFramebuffer = static_cast<GLFramebuffer*>(getFramebufferForDrawing());
    glFramebuffer->allocateBuffers(1, 1, mPlaceholderDrawBuffer);
@@ -1622,6 +1668,16 @@ bool GLESRenderEngine::isImageCachedForTesting(uint64_t bufferId) {
    return cachedImage != mImageCache.end();
}

bool GLESRenderEngine::isTextureNameKnownForTesting(uint32_t texName) {
    const auto& entry = mTextureView.find(texName);
    return entry != mTextureView.end();
}

std::optional<uint64_t> GLESRenderEngine::getBufferIdForTextureNameForTesting(uint32_t texName) {
    const auto& entry = mTextureView.find(texName);
    return entry != mTextureView.end() ? entry->second : std::nullopt;
}

bool GLESRenderEngine::isFramebufferImageCachedForTesting(uint64_t bufferId) {
    std::lock_guard<std::mutex> lock(mFramebufferImageCacheMutex);
    return std::any_of(mFramebufferImageCache.cbegin(), mFramebufferImageCache.cend(),
+14 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ public:
                        const std::vector<const LayerSettings*>& layers,
                        ANativeWindowBuffer* buffer, const bool useFramebufferCache,
                        base::unique_fd&& bufferFence, base::unique_fd* drawFence) override;
    bool cleanupPostRender() override;
    bool cleanupPostRender(CleanupMode mode) override;

    EGLDisplay getEGLDisplay() const { return mEGLDisplay; }
    // Creates an output image for rendering to
@@ -86,6 +86,12 @@ public:
    // Test-only methods
    // Returns true iff mImageCache contains an image keyed by bufferId
    bool isImageCachedForTesting(uint64_t bufferId) EXCLUDES(mRenderingMutex);
    // Returns true iff texName was previously generated by RenderEngine and was
    // not destroyed.
    bool isTextureNameKnownForTesting(uint32_t texName);
    // Returns the buffer ID of the content bound to texName, or nullopt if no
    // such mapping exists.
    std::optional<uint64_t> getBufferIdForTextureNameForTesting(uint32_t texName);
    // Returns true iff mFramebufferImageCache contains an image keyed by bufferId
    bool isFramebufferImageCachedForTesting(uint64_t bufferId)
            EXCLUDES(mFramebufferImageCacheMutex);
@@ -225,6 +231,8 @@ private:

    // Cache of GL images that we'll store per GraphicBuffer ID
    std::unordered_map<uint64_t, std::unique_ptr<Image>> mImageCache GUARDED_BY(mRenderingMutex);
    std::unordered_map<uint32_t, std::optional<uint64_t>> mTextureView;

    // Mutex guarding rendering operations, so that:
    // 1. GL operations aren't interleaved, and
    // 2. Internal state related to rendering that is potentially modified by
@@ -238,6 +246,11 @@ private:
    // ensure that we align on a word. Allocating 16 bytes will provide a
    // guarantee that we don't clobber memory.
    uint32_t mPlaceholderDrawBuffer[4];
    // Placeholder buffer and image, similar to mPlaceholderDrawBuffer, but
    // instead these are intended for cleaning up texture memory with the
    // GL_TEXTURE_EXTERNAL_OES target.
    ANativeWindowBuffer* mPlaceholderBuffer = nullptr;
    EGLImage mPlaceholderImage = EGL_NO_IMAGE_KHR;
    sp<Fence> mLastDrawFence;
    // Store a separate boolean checking if prior resources were cleaned up, as
    // devices that don't support native sync fences can't rely on a last draw
Loading