aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLingfeng Yang <lfy@google.com>2021-08-04 17:00:07 -0700
committerLingfeng Yang <lfy@google.com>2021-08-06 11:25:13 -0700
commit8be7045ae05577da0a0711138210d40b6619036e (patch)
tree7cd6631f44eeac1bfbcf1f7a6aad3698fa541cee
parent7575ebccf276ae6afdad7a0b589678cb59a1398e (diff)
downloadgoldfish-opengl-8be7045ae05577da0a0711138210d40b6619036e.tar.gz
Optimize mapper unlock()
- copying to dma from dma: skip if ptr is same - Always go down the DMA path for unlock() via never doing sub-region updates - skip unlock write if we didnt lock for write Bug: 189960317 Test: ./cts-tradefed run cts -m CtsViewTestCases -t android.view.cts.ASurfaceControlBackPressureTest#testSurfaceTransaction_setEnableBackPressure fails fewer frames Test: ./cts-tradefed run cts -m CtsNativeHardwareTestCases 100% Change-Id: I96fa3637c3b03d4177aa9edd2d1ff94845fc7a7b Merged-In: I96fa3637c3b03d4177aa9edd2d1ff94845fc7a7b
-rw-r--r--system/OpenglSystemCommon/HostConnection.h4
-rw-r--r--system/hals/Android.mk5
-rw-r--r--system/hals/cb_handle_30.h6
-rw-r--r--system/hals/mapper3.cpp86
4 files changed, 61 insertions, 40 deletions
diff --git a/system/OpenglSystemCommon/HostConnection.h b/system/OpenglSystemCommon/HostConnection.h
index 6d087148..31ca84cf 100644
--- a/system/OpenglSystemCommon/HostConnection.h
+++ b/system/OpenglSystemCommon/HostConnection.h
@@ -85,7 +85,9 @@ public:
}
virtual uint64_t lockAndWriteDma(void* data, uint32_t size) {
if (m_dmaPtr && m_dmaPhysAddr) {
- memcpy(m_dmaPtr, data, size);
+ if (data != m_dmaPtr) {
+ memcpy(m_dmaPtr, data, size);
+ }
return m_dmaPhysAddr;
} else if (m_dmaCxt) {
return writeGoldfishDma(data, size, m_dmaCxt);
diff --git a/system/hals/Android.mk b/system/hals/Android.mk
index 72ac6ceb..06fdc213 100644
--- a/system/hals/Android.mk
+++ b/system/hals/Android.mk
@@ -35,7 +35,7 @@ LOCAL_SHARED_LIBRARIES += \
libcutils \
libhidlbase \
liblog \
- libutils
+ libutils \
LOCAL_STATIC_LIBRARIES += libqemupipe.ranchu libGoldfishAddressSpace$(GOLDFISH_OPENGL_LIB_SUFFIX)
LOCAL_HEADER_LIBRARIES += libgralloc_cb.ranchu
@@ -75,7 +75,8 @@ LOCAL_SHARED_LIBRARIES += \
libhidlbase \
liblog \
libutils \
- libsync
+ libsync \
+ libandroidemu \
LOCAL_STATIC_LIBRARIES += libqemupipe.ranchu libGoldfishAddressSpace$(GOLDFISH_OPENGL_LIB_SUFFIX)
LOCAL_HEADER_LIBRARIES += libgralloc_cb.ranchu
diff --git a/system/hals/cb_handle_30.h b/system/hals/cb_handle_30.h
index 374008eb..7e5e73dd 100644
--- a/system/hals/cb_handle_30.h
+++ b/system/hals/cb_handle_30.h
@@ -53,7 +53,9 @@ struct cb_handle_30_t : public cb_handle_t {
p_mmapedOffset),
mmapedSize(p_mmapedSize),
bytesPerPixel(p_bytesPerPixel),
- stride(p_stride) {
+ stride(p_stride),
+ locked(0),
+ lockedUsage(0) {
numInts = CB_HANDLE_NUM_INTS(numFds);
}
@@ -76,6 +78,8 @@ struct cb_handle_30_t : public cb_handle_t {
uint32_t mmapedSize; // real allocation side
uint32_t bytesPerPixel;
uint32_t stride;
+ uint32_t locked;
+ uint32_t lockedUsage;
};
#endif // SYSTEM_HALS_CB_HANDLE_30_H
diff --git a/system/hals/mapper3.cpp b/system/hals/mapper3.cpp
index e74e76cd..0788a0a6 100644
--- a/system/hals/mapper3.cpp
+++ b/system/hals/mapper3.cpp
@@ -23,6 +23,10 @@
#include "FormatConversions.h"
#include "debug.h"
+#include "android/base/Tracing.h"
+
+#define ATRACE_TAG ATRACE_TAG_GRAPHICS
+
const int kOMX_COLOR_FormatYUV420Planar = 19;
using ::android::hardware::hidl_handle;
@@ -465,10 +469,14 @@ private: // **** impl ****
cb.lockedHeight = cb.height;
}
+ cb.locked = 1;
+ cb.lockedUsage = usage;
+
RETURN(Error3::NONE);
}
Error3 unlockImpl(void* raw) {
+ AEMU_SCOPED_TRACE("unlockImpl body");
if (!raw) {
RETURN_ERROR(Error3::BAD_BUFFER);
}
@@ -492,54 +500,60 @@ private: // **** impl ****
}
void unlockHostImpl(cb_handle_30_t& cb, char* const bufferBits) {
+ AEMU_SCOPED_TRACE("unlockHostImpl body");
const int bpp = glUtilsPixelBitSize(cb.glFormat, cb.glType) >> 3;
- const int left = cb.lockedLeft;
- const int top = cb.lockedTop;
- const int width = cb.lockedWidth;
- const int height = cb.lockedHeight;
- const uint32_t rgbSize = width * height * bpp;
- std::vector<char> convertedBuf;
+ const uint32_t lockedUsage = cb.lockedUsage;
+ const uint32_t rgbSize = cb.width * cb.height * bpp;
const char* bitsToSend;
uint32_t sizeToSend;
- if (gralloc_is_yuv_format(cb.format)) {
- bitsToSend = bufferBits;
- switch (static_cast<PixelFormat>(cb.format)) {
- case PixelFormat::YV12:
- get_yv12_offsets(width, height, nullptr, nullptr, &sizeToSend);
- break;
- case PixelFormat::YCBCR_420_888:
- get_yuv420p_offsets(width, height, nullptr, nullptr, &sizeToSend);
- break;
- default:
- CRASH("Unexpected format, switch is out of sync with gralloc_is_yuv_format");
- break;
+ const uint32_t usageSwWrite = (uint32_t)BufferUsage::CPU_WRITE_MASK;
+ uint32_t readOnly = (!(lockedUsage & usageSwWrite));
+
+ if (!readOnly) {
+ if (gralloc_is_yuv_format(cb.format)) {
+ bitsToSend = bufferBits;
+ switch (static_cast<PixelFormat>(cb.format)) {
+ case PixelFormat::YV12:
+ get_yv12_offsets(cb.width, cb.height, nullptr, nullptr, &sizeToSend);
+ break;
+ case PixelFormat::YCBCR_420_888:
+ get_yuv420p_offsets(cb.width, cb.height, nullptr, nullptr, &sizeToSend);
+ break;
+ default:
+ CRASH("Unexpected format, switch is out of sync with gralloc_is_yuv_format");
+ break;
+ }
+ } else {
+ bitsToSend = bufferBits;
+ sizeToSend = rgbSize;
}
- } else {
- convertedBuf.resize(rgbSize);
- copy_rgb_buffer_from_unlocked(
- convertedBuf.data(), bufferBits,
- cb.width,
- width, height, top, left, bpp);
- bitsToSend = convertedBuf.data();
- sizeToSend = rgbSize;
- }
- {
- const HostConnectionSession conn = getHostConnectionSession();
- ExtendedRCEncoderContext *const rcEnc = conn.getRcEncoder();
- rcEnc->bindDmaDirectly(bufferBits,
- getMmapedPhysAddr(cb.getMmapedOffset()));
- rcEnc->rcUpdateColorBufferDMA(rcEnc, cb.hostHandle,
- left, top, width, height,
- cb.glFormat, cb.glType,
- const_cast<char*>(bitsToSend), sizeToSend);
+ {
+ const HostConnectionSession conn = getHostConnectionSession();
+ ExtendedRCEncoderContext *const rcEnc = conn.getRcEncoder();
+ {
+ AEMU_SCOPED_TRACE("bindDmaDirectly");
+ rcEnc->bindDmaDirectly(bufferBits,
+ getMmapedPhysAddr(cb.getMmapedOffset()));
+ }
+ {
+ AEMU_SCOPED_TRACE("updateColorBuffer");
+ rcEnc->rcUpdateColorBufferDMA(rcEnc, cb.hostHandle,
+ 0, 0, cb.width, cb.height,
+ cb.glFormat, cb.glType,
+ const_cast<char*>(bitsToSend),
+ sizeToSend);
+ }
+ }
}
cb.lockedLeft = 0;
cb.lockedTop = 0;
cb.lockedWidth = 0;
cb.lockedHeight = 0;
+ cb.locked = 0;
+ cb.lockedUsage = 0;
}
bool isSupportedImpl(const IMapper::BufferDescriptorInfo& descriptor) const {