Merge "Avoid crash when setting buffer on deleted layer" into oc-dev

This commit is contained in:
Steven Thomas 2017-05-02 17:47:23 +00:00 committed by Android (Google) Code Review
commit 6dbaf573a2
2 changed files with 44 additions and 21 deletions

View file

@ -655,18 +655,24 @@ bool ComposerClient::CommandReader::parseSetClientTarget(uint16_t length)
auto fence = readFence(); auto fence = readFence();
auto dataspace = readSigned(); auto dataspace = readSigned();
auto damage = readRegion((length - 4) / 4); auto damage = readRegion((length - 4) / 4);
bool closeFence = true;
auto err = lookupBuffer(BufferCache::CLIENT_TARGETS, auto err = lookupBuffer(BufferCache::CLIENT_TARGETS,
slot, useCache, clientTarget, &clientTarget); slot, useCache, clientTarget, &clientTarget);
if (err == Error::NONE) { if (err == Error::NONE) {
err = mHal.setClientTarget(mDisplay, clientTarget, fence, err = mHal.setClientTarget(mDisplay, clientTarget, fence,
dataspace, damage); dataspace, damage);
auto updateBufErr = updateBuffer(BufferCache::CLIENT_TARGETS, slot,
updateBuffer(BufferCache::CLIENT_TARGETS, slot, useCache, useCache, clientTarget);
clientTarget); if (err == Error::NONE) {
closeFence = false;
err = updateBufErr;
}
}
if (closeFence) {
close(fence);
} }
if (err != Error::NONE) { if (err != Error::NONE) {
close(fence);
mWriter.setError(getCommandLoc(), err); mWriter.setError(getCommandLoc(), err);
} }
@ -683,17 +689,23 @@ bool ComposerClient::CommandReader::parseSetOutputBuffer(uint16_t length)
auto slot = read(); auto slot = read();
auto outputBuffer = readHandle(&useCache); auto outputBuffer = readHandle(&useCache);
auto fence = readFence(); auto fence = readFence();
bool closeFence = true;
auto err = lookupBuffer(BufferCache::OUTPUT_BUFFERS, auto err = lookupBuffer(BufferCache::OUTPUT_BUFFERS,
slot, useCache, outputBuffer, &outputBuffer); slot, useCache, outputBuffer, &outputBuffer);
if (err == Error::NONE) { if (err == Error::NONE) {
err = mHal.setOutputBuffer(mDisplay, outputBuffer, fence); err = mHal.setOutputBuffer(mDisplay, outputBuffer, fence);
auto updateBufErr = updateBuffer(BufferCache::OUTPUT_BUFFERS,
updateBuffer(BufferCache::OUTPUT_BUFFERS,
slot, useCache, outputBuffer); slot, useCache, outputBuffer);
if (err == Error::NONE) {
closeFence = false;
err = updateBufErr;
}
}
if (closeFence) {
close(fence);
} }
if (err != Error::NONE) { if (err != Error::NONE) {
close(fence);
mWriter.setError(getCommandLoc(), err); mWriter.setError(getCommandLoc(), err);
} }
@ -786,17 +798,23 @@ bool ComposerClient::CommandReader::parseSetLayerBuffer(uint16_t length)
auto slot = read(); auto slot = read();
auto buffer = readHandle(&useCache); auto buffer = readHandle(&useCache);
auto fence = readFence(); auto fence = readFence();
bool closeFence = true;
auto err = lookupBuffer(BufferCache::LAYER_BUFFERS, auto err = lookupBuffer(BufferCache::LAYER_BUFFERS,
slot, useCache, buffer, &buffer); slot, useCache, buffer, &buffer);
if (err == Error::NONE) { if (err == Error::NONE) {
err = mHal.setLayerBuffer(mDisplay, mLayer, buffer, fence); err = mHal.setLayerBuffer(mDisplay, mLayer, buffer, fence);
auto updateBufErr = updateBuffer(BufferCache::LAYER_BUFFERS, slot,
updateBuffer(BufferCache::LAYER_BUFFERS, useCache, buffer);
slot, useCache, buffer); if (err == Error::NONE) {
closeFence = false;
err = updateBufErr;
}
}
if (closeFence) {
close(fence);
} }
if (err != Error::NONE) { if (err != Error::NONE) {
close(fence);
mWriter.setError(getCommandLoc(), err); mWriter.setError(getCommandLoc(), err);
} }
@ -915,8 +933,10 @@ bool ComposerClient::CommandReader::parseSetLayerSidebandStream(uint16_t length)
auto err = lookupLayerSidebandStream(stream, &stream); auto err = lookupLayerSidebandStream(stream, &stream);
if (err == Error::NONE) { if (err == Error::NONE) {
err = mHal.setLayerSidebandStream(mDisplay, mLayer, stream); err = mHal.setLayerSidebandStream(mDisplay, mLayer, stream);
auto updateErr = updateLayerSidebandStream(stream);
updateLayerSidebandStream(stream); if (err == Error::NONE) {
err = updateErr;
}
} }
if (err != Error::NONE) { if (err != Error::NONE) {
mWriter.setError(getCommandLoc(), err); mWriter.setError(getCommandLoc(), err);
@ -1097,21 +1117,24 @@ Error ComposerClient::CommandReader::lookupBuffer(BufferCache cache,
return Error::NONE; return Error::NONE;
} }
void ComposerClient::CommandReader::updateBuffer(BufferCache cache, Error ComposerClient::CommandReader::updateBuffer(BufferCache cache,
uint32_t slot, bool useCache, buffer_handle_t handle) uint32_t slot, bool useCache, buffer_handle_t handle)
{ {
// handle was looked up from cache // handle was looked up from cache
if (useCache) { if (useCache) {
return; return Error::NONE;
} }
std::lock_guard<std::mutex> lock(mClient.mDisplayDataMutex); std::lock_guard<std::mutex> lock(mClient.mDisplayDataMutex);
BufferCacheEntry* entry = nullptr; BufferCacheEntry* entry = nullptr;
lookupBufferCacheEntryLocked(cache, slot, &entry); Error error = lookupBufferCacheEntryLocked(cache, slot, &entry);
LOG_FATAL_IF(!entry, "failed to find the cache entry to update"); if (error != Error::NONE) {
return error;
}
*entry = handle; *entry = handle;
return Error::NONE;
} }
} // namespace implementation } // namespace implementation

View file

@ -173,7 +173,7 @@ protected:
Error lookupBuffer(BufferCache cache, uint32_t slot, Error lookupBuffer(BufferCache cache, uint32_t slot,
bool useCache, buffer_handle_t handle, bool useCache, buffer_handle_t handle,
buffer_handle_t* outHandle); buffer_handle_t* outHandle);
void updateBuffer(BufferCache cache, uint32_t slot, Error updateBuffer(BufferCache cache, uint32_t slot,
bool useCache, buffer_handle_t handle); bool useCache, buffer_handle_t handle);
Error lookupLayerSidebandStream(buffer_handle_t handle, Error lookupLayerSidebandStream(buffer_handle_t handle,
@ -182,9 +182,9 @@ protected:
return lookupBuffer(BufferCache::LAYER_SIDEBAND_STREAMS, return lookupBuffer(BufferCache::LAYER_SIDEBAND_STREAMS,
0, false, handle, outHandle); 0, false, handle, outHandle);
} }
void updateLayerSidebandStream(buffer_handle_t handle) Error updateLayerSidebandStream(buffer_handle_t handle)
{ {
updateBuffer(BufferCache::LAYER_SIDEBAND_STREAMS, return updateBuffer(BufferCache::LAYER_SIDEBAND_STREAMS,
0, false, handle); 0, false, handle);
} }