205 lines
8.6 KiB
C++
205 lines
8.6 KiB
C++
|
|
/* Copyright Statement:
|
||
|
|
*
|
||
|
|
* This software/firmware and related documentation ("MediaTek Software") are
|
||
|
|
* protected under relevant copyright laws. The information contained herein is
|
||
|
|
* confidential and proprietary to MediaTek Inc. and/or its licensors. Without
|
||
|
|
* the prior written permission of MediaTek inc. and/or its licensors, any
|
||
|
|
* reproduction, modification, use or disclosure of MediaTek Software, and
|
||
|
|
* information contained herein, in whole or in part, shall be strictly
|
||
|
|
* prohibited.
|
||
|
|
*
|
||
|
|
* MediaTek Inc. (C) 2021. All rights reserved.
|
||
|
|
*
|
||
|
|
* BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
|
||
|
|
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
|
||
|
|
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
|
||
|
|
* ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
|
||
|
|
* WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
|
||
|
|
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
|
||
|
|
* NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
|
||
|
|
* RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
|
||
|
|
* INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
|
||
|
|
* TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
|
||
|
|
* RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
|
||
|
|
* OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
|
||
|
|
* SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
|
||
|
|
* RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
|
||
|
|
* STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
|
||
|
|
* ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
|
||
|
|
* RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
|
||
|
|
* MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
|
||
|
|
* CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
|
||
|
|
*
|
||
|
|
* The following software/firmware and/or related documentation ("MediaTek
|
||
|
|
* Software") have been modified by MediaTek Inc. All revisions are subject to
|
||
|
|
* any receiver's applicable license agreements with MediaTek Inc.
|
||
|
|
*/
|
||
|
|
|
||
|
|
//#define LOG_NDEBUG 0
|
||
|
|
#undef LOG_TAG
|
||
|
|
#define LOG_TAG "RenderEngine"
|
||
|
|
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
|
||
|
|
|
||
|
|
#include "../skia/SkiaGLRenderEngine.h"
|
||
|
|
|
||
|
|
#include <EGL/egl.h>
|
||
|
|
#include <EGL/eglext.h>
|
||
|
|
#include <GrContextOptions.h>
|
||
|
|
#include <SkCanvas.h>
|
||
|
|
#include <SkColorFilter.h>
|
||
|
|
#include <SkColorMatrix.h>
|
||
|
|
#include <SkColorSpace.h>
|
||
|
|
#include <SkGraphics.h>
|
||
|
|
#include <SkImage.h>
|
||
|
|
#include <SkImageFilters.h>
|
||
|
|
#include <SkRegion.h>
|
||
|
|
#include <SkShadowUtils.h>
|
||
|
|
#include <SkSurface.h>
|
||
|
|
#include <android-base/stringprintf.h>
|
||
|
|
#include <gl/GrGLInterface.h>
|
||
|
|
#include <gui/TraceUtils.h>
|
||
|
|
#include <gui/HdrMetadata.h>
|
||
|
|
#include <sync/sync.h>
|
||
|
|
#include <ui/BlurRegion.h>
|
||
|
|
#include <ui/DebugUtils.h>
|
||
|
|
#include <ui/GraphicBuffer.h>
|
||
|
|
#include <utils/Trace.h>
|
||
|
|
#include <ui/gralloc_extra.h>
|
||
|
|
|
||
|
|
namespace android {
|
||
|
|
namespace renderengine {
|
||
|
|
namespace skia {
|
||
|
|
|
||
|
|
#ifdef MTK_SKIP_SKIA_EXTERNAL_TEXTURE_CACHE
|
||
|
|
bool SkiaRenderEngine::isSkipExternalTexureCache(const sp<GraphicBuffer>& buffer){
|
||
|
|
GRALLOC_EXTRA_RESULT result = GRALLOC_EXTRA_OK;
|
||
|
|
int ion_fd = -1;
|
||
|
|
int status = 0;
|
||
|
|
bool videoPqEnable = false;
|
||
|
|
if (!mSkipExternalTexture) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
result = gralloc_extra_query(buffer->handle, GRALLOC_EXTRA_GET_ION_FD, &ion_fd);
|
||
|
|
if ((GRALLOC_EXTRA_OK == result) && (-1 != ion_fd)) {
|
||
|
|
gralloc_extra_ion_sf_info_t sf_info;
|
||
|
|
result = gralloc_extra_query(buffer->handle, GRALLOC_EXTRA_GET_IOCTL_ION_SF_INFO, &sf_info);
|
||
|
|
if (GRALLOC_EXTRA_OK == result) {
|
||
|
|
status = sf_info.status2;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
videoPqEnable = (status & GRALLOC_EXTRA_MASK2_VIDEO_PQ) == GRALLOC_EXTRA_BIT2_VIDEO_PQ_ON;
|
||
|
|
bool isThreaded = mRenderEngineType == RenderEngineType::SKIA_GL_THREADED ||
|
||
|
|
mRenderEngineType == RenderEngineType::SKIA_VK_THREADED;
|
||
|
|
if (videoPqEnable && isThreaded) {
|
||
|
|
// skia externel texture only when MTK VP && RE is threaded
|
||
|
|
// otherwise go AOSP flow
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
std::shared_ptr<AutoBackendTexture::LocalRef> SkiaRenderEngine::getOrCreateBackendTexture(
|
||
|
|
const sp<GraphicBuffer>& buffer, bool isOutputBuffer, bool * outSkipUpdate) {
|
||
|
|
// Do not lookup the buffer in the cache for protected contexts with the SkiaVk back-end
|
||
|
|
*outSkipUpdate = false;
|
||
|
|
if (mRenderEngineType == RenderEngineType::SKIA_GL_THREADED ||
|
||
|
|
(mRenderEngineType == RenderEngineType::SKIA_VK_THREADED && !isProtected())) {
|
||
|
|
#ifndef MTK_AOSP_DISPLAY_BUGFIX
|
||
|
|
if (const auto& it = mTextureCache.find(buffer->getId()); it != mTextureCache.end()) {
|
||
|
|
#else
|
||
|
|
if (const auto& it = mTextureCache.find(buffer->getId()); it != mTextureCache.end() \
|
||
|
|
&& it->second->isOutputBuffer() == isOutputBuffer) {
|
||
|
|
#endif
|
||
|
|
return it->second;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
auto imageTextureRef = std::make_shared<AutoBackendTexture::LocalRef>(getActiveGrContext(),
|
||
|
|
buffer->toAHardwareBuffer(),
|
||
|
|
isOutputBuffer, mTextureCleanupMgr);
|
||
|
|
if (isSkipExternalTexureCache(buffer)) {
|
||
|
|
*outSkipUpdate = true;
|
||
|
|
const bool isProtectedBuffer = buffer->getUsage() & GRALLOC_USAGE_PROTECTED;
|
||
|
|
if (isProtectedBuffer ||
|
||
|
|
(mRenderEngineType == RenderEngineType::SKIA_VK_THREADED && isProtected())) {
|
||
|
|
// follow AOSP flow, follow rule of mapExternalTextureBuffer
|
||
|
|
} else {
|
||
|
|
auto& cache = mTextureCache;
|
||
|
|
mGraphicBufferExternalRefs[buffer->getId()]++;
|
||
|
|
if (const auto& iter = cache.find(buffer->getId()); iter == cache.end()) {
|
||
|
|
cache.insert({buffer->getId(), imageTextureRef});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return imageTextureRef;
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef MTK_SF_PQ_MANAGEMENT
|
||
|
|
void SkiaRenderEngine::setDeviceInfo(const bool is_primary) {
|
||
|
|
mIsPrimary = is_primary;
|
||
|
|
//ALOGD("set mIsPrimary:%d", mIsPrimary);
|
||
|
|
}
|
||
|
|
|
||
|
|
bool SkiaRenderEngine::getAndClearDeviceInfo() {
|
||
|
|
bool is_primary = mIsPrimary;// get the current DeviceInfo
|
||
|
|
mIsPrimary = false;// clear to defualt value false
|
||
|
|
//ALOGD("getAndClear is_primary:%d", is_primary);
|
||
|
|
return is_primary;
|
||
|
|
}
|
||
|
|
|
||
|
|
void SkiaRenderEngine::updatePQFlag (const sp<GraphicBuffer>& buffer, const bool isHDR, const bool is_primary) {
|
||
|
|
GRALLOC_EXTRA_RESULT result = GRALLOC_EXTRA_OK;
|
||
|
|
int ion_fd = -1;
|
||
|
|
int status = 0;
|
||
|
|
bool videoPqEnable = false;
|
||
|
|
bool doraInterface = false;
|
||
|
|
bool mdpSupport = false;
|
||
|
|
ge_ai_pq_info_t pqInfo;
|
||
|
|
gralloc_extra_ion_sf_info_t sf_info;
|
||
|
|
result = gralloc_extra_query(buffer->handle, GRALLOC_EXTRA_GET_ION_FD, &ion_fd);
|
||
|
|
if ((GRALLOC_EXTRA_OK == result) && (-1 != ion_fd)) {
|
||
|
|
result = gralloc_extra_query(buffer->handle, GRALLOC_EXTRA_GET_IOCTL_ION_SF_INFO, &sf_info);
|
||
|
|
if (GRALLOC_EXTRA_OK == result) {
|
||
|
|
status = sf_info.status2;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
videoPqEnable = (status & GRALLOC_EXTRA_MASK2_VIDEO_PQ) == GRALLOC_EXTRA_BIT2_VIDEO_PQ_ON;
|
||
|
|
result = gralloc_extra_query(buffer->handle, GRALLOC_EXTRA_GET_AI_PQ_INFO, &pqInfo);
|
||
|
|
if (result != GRALLOC_EXTRA_OK) {
|
||
|
|
ALOGE("%s: get gralloc GRALLOC_EXTRA_GET_AI_PQ_INFO fail, return", __FUNCTION__);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
doraInterface = (pqInfo.param != 0);
|
||
|
|
if (videoPqEnable || doraInterface) {
|
||
|
|
int width = buffer->getWidth();
|
||
|
|
int height = buffer->getHeight();
|
||
|
|
buffer_handle_t handle = buffer->handle;
|
||
|
|
if (!width || !height || !handle || !mdpSupport) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
ALOGD("%s, is_primary:%d, isHDR: %d", __FUNCTION__, is_primary, isHDR);
|
||
|
|
if (is_primary && (!isHDR)) {
|
||
|
|
//ALOGD("set GPU_VIDEO_PQ_ON flg+);
|
||
|
|
result = gralloc_extra_sf_set_status2(&sf_info, GRALLOC_EXTRA_MASK2_GPU_VIDEO_PQ_MASK,
|
||
|
|
GRALLOC_EXTRA_BIT2_GPU_VIDEO_PQ_ON);
|
||
|
|
if (result != GRALLOC_EXTRA_OK) {
|
||
|
|
ALOGE("%s: update GRALLOC_EXTRA_BIT2_GPU_VIDEO_PQ_ON fail, return", __FUNCTION__);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
result = gralloc_extra_perform(handle, GRALLOC_EXTRA_SET_IOCTL_ION_SF_INFO, &sf_info);
|
||
|
|
if (result != GRALLOC_EXTRA_OK) {
|
||
|
|
ALOGE("%s: set GRALLOC_EXTRA_SET_IOCTL_ION_SF_INFO fail, return", __FUNCTION__);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
} // namespace skia
|
||
|
|
} // namespace renderengine
|
||
|
|
} // nam
|
||
|
|
|