Loading include/private/surfaceflinger/SharedBufferStack.h +10 −0 Original line number Diff line number Diff line Loading @@ -285,6 +285,8 @@ public: uint32_t getTransform(int buffer) const; status_t resize(int newNumBuffers); status_t grow(int newNumBuffers); status_t shrink(int newNumBuffers); SharedBufferStack::Statistics getStats() const; Loading Loading @@ -346,6 +348,14 @@ private: int mNumBuffers; BufferList mBufferList; struct BuffersAvailableCondition : public ConditionBase { int mNumBuffers; inline BuffersAvailableCondition(SharedBufferServer* sbs, int numBuffers); inline bool operator()() const; inline const char* name() const { return "BuffersAvailableCondition"; } }; struct UnlockUpdate : public UpdateBase { const int lockedBuffer; inline UnlockUpdate(SharedBufferBase* sbb, int lockedBuffer); Loading include/ui/KeycodeLabels.h +22 −0 Original line number Diff line number Diff line Loading @@ -189,6 +189,28 @@ static const KeycodeLabel KEYCODES[] = { { "NUMPAD_LEFT_PAREN", 162 }, { "NUMPAD_RIGHT_PAREN", 163 }, { "VOLUME_MUTE", 164 }, { "INFO", 165 }, { "CHANNEL_UP", 166 }, { "CHANNEL_DOWN", 167 }, { "ZOOM_IN", 168 }, { "ZOOM_OUT", 169 }, { "TV", 170 }, { "WINDOW", 171 }, { "GUIDE", 172 }, { "DVR", 173 }, { "BOOKMARK", 174 }, { "CAPTIONS", 175 }, { "SETTINGS", 176 }, { "TV_POWER", 177 }, { "TV_INPUT", 178 }, { "STB_POWER", 179 }, { "STB_INPUT", 180 }, { "AVR_POWER", 181 }, { "AVR_INPUT", 182 }, { "PROG_RED", 183 }, { "PROG_GREEN", 184 }, { "PROG_YELLOW", 185 }, { "PROG_BLUE", 186 }, // NOTE: If you add a new keycode here you must also add it to several other files. // Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list. Loading libs/surfaceflinger_client/SharedBufferStack.cpp +70 −5 Original line number Diff line number Diff line Loading @@ -265,6 +265,14 @@ bool SharedBufferClient::LockCondition::operator()() const { (stack.queued > 0 && stack.inUse != buf)); } SharedBufferServer::BuffersAvailableCondition::BuffersAvailableCondition( SharedBufferServer* sbs, int numBuffers) : ConditionBase(sbs), mNumBuffers(numBuffers) { } bool SharedBufferServer::BuffersAvailableCondition::operator()() const { return stack.available == mNumBuffers; } // ---------------------------------------------------------------------------- SharedBufferClient::QueueUpdate::QueueUpdate(SharedBufferBase* sbb) Loading Loading @@ -448,6 +456,7 @@ status_t SharedBufferClient::queue(int buf) const nsecs_t now = systemTime(SYSTEM_TIME_THREAD); stack.stats.totalTime = ns2us(now - mDequeueTime[buf]); return err; } Loading Loading @@ -492,6 +501,7 @@ status_t SharedBufferClient::setBufferCount( if (err == NO_ERROR) { mNumBuffers = bufferCount; queued_head = (stack.head + stack.queued) % mNumBuffers; tail = computeTail(); } return err; } Loading Loading @@ -606,17 +616,24 @@ uint32_t SharedBufferServer::getTransform(int buf) const */ status_t SharedBufferServer::resize(int newNumBuffers) { if (uint32_t(newNumBuffers) >= SharedBufferStack::NUM_BUFFER_MAX) if ((unsigned int)(newNumBuffers) < SharedBufferStack::NUM_BUFFER_MIN || (unsigned int)(newNumBuffers) > SharedBufferStack::NUM_BUFFER_MAX) { return BAD_VALUE; } RWLock::AutoWLock _l(mLock); // for now we're not supporting shrinking const int numBuffers = mNumBuffers; if (newNumBuffers < numBuffers) return BAD_VALUE; if (newNumBuffers < mNumBuffers) { return shrink(newNumBuffers); } else { return grow(newNumBuffers); } } status_t SharedBufferServer::grow(int newNumBuffers) { SharedBufferStack& stack( *mSharedStack ); const int numBuffers = mNumBuffers; const int extra = newNumBuffers - numBuffers; // read the head, make sure it's valid Loading Loading @@ -650,6 +667,54 @@ status_t SharedBufferServer::resize(int newNumBuffers) return NO_ERROR; } status_t SharedBufferServer::shrink(int newNumBuffers) { SharedBufferStack& stack( *mSharedStack ); // Shrinking is only supported if there are no buffers currently dequeued. int32_t avail = stack.available; int32_t queued = stack.queued; if (avail + queued != mNumBuffers) { return INVALID_OPERATION; } // Wait for any queued buffers to be displayed. BuffersAvailableCondition condition(this, mNumBuffers); status_t err = waitForCondition(condition); if (err < 0) { return err; } // Reset head to index 0 and make it refer to buffer 0. The same renaming // (head -> 0) is done in the BufferManager. int32_t head = stack.head; int8_t* index = const_cast<int8_t*>(stack.index); for (int8_t i = 0; i < newNumBuffers; i++) { index[i] = i; } stack.head = 0; stack.headBuf = 0; // If one of the buffers is in use it must be the head buffer, which we are // renaming to buffer 0. if (stack.inUse > 0) { stack.inUse = 0; } // Free the buffers from the end of the list that are no longer needed. for (int i = newNumBuffers; i < mNumBuffers; i++) { mBufferList.remove(i); } // Tell the client to reallocate all the buffers. reallocateAll(); mNumBuffers = newNumBuffers; stack.available = newNumBuffers; return NO_ERROR; } SharedBufferStack::Statistics SharedBufferServer::getStats() const { SharedBufferStack& stack( *mSharedStack ); Loading libs/surfaceflinger_client/Surface.cpp +7 −1 Original line number Diff line number Diff line Loading @@ -855,6 +855,12 @@ int Surface::setBufferCount(int bufferCount) status_t err = mSharedBufferClient->setBufferCount(bufferCount, ipc); LOGE_IF(err, "ISurface::setBufferCount(%d) returned %s", bufferCount, strerror(-err)); if (err == NO_ERROR) { // Clear out any references to the old buffers. mBuffers.clear(); } return err; } Loading Loading @@ -1029,7 +1035,7 @@ int Surface::getBufferIndex(const sp<GraphicBuffer>& buffer) const // one of the buffers for which we do know the index. This can happen // e.g. if GraphicBuffer is used to wrap an android_native_buffer_t that // was dequeued from an ANativeWindow. for (int i = 0; i < mBuffers.size(); i++) { for (size_t i = 0; i < mBuffers.size(); i++) { if (buffer->handle == mBuffers[i]->handle) { idx = mBuffers[i]->getIndex(); break; Loading libs/surfaceflinger_client/tests/SharedBufferStack/SharedBufferStackTest.cpp +6 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,8 @@ void test0(SharedBufferServer& s, SharedBufferClient& c, size_t num, int* list); int main(int argc, char** argv) { SharedClient client; SharedBufferServer s(&client, 0, 4, 0); sp<SharedBufferServer> ps(new SharedBufferServer(&client, 0, 4, 0)); SharedBufferServer& s(*ps); SharedBufferClient c(&client, 0, 4, 0); printf("basic test 0\n"); Loading Loading @@ -67,6 +68,10 @@ int main(int argc, char** argv) int list3[6] = {3, 2, 1, 4, 5, 0}; test0(s, c, 6, list3); c.setBufferCount(4, resize); int list4[4] = {1, 2, 3, 0}; test0(s, c, 4, list4); return 0; } Loading Loading
include/private/surfaceflinger/SharedBufferStack.h +10 −0 Original line number Diff line number Diff line Loading @@ -285,6 +285,8 @@ public: uint32_t getTransform(int buffer) const; status_t resize(int newNumBuffers); status_t grow(int newNumBuffers); status_t shrink(int newNumBuffers); SharedBufferStack::Statistics getStats() const; Loading Loading @@ -346,6 +348,14 @@ private: int mNumBuffers; BufferList mBufferList; struct BuffersAvailableCondition : public ConditionBase { int mNumBuffers; inline BuffersAvailableCondition(SharedBufferServer* sbs, int numBuffers); inline bool operator()() const; inline const char* name() const { return "BuffersAvailableCondition"; } }; struct UnlockUpdate : public UpdateBase { const int lockedBuffer; inline UnlockUpdate(SharedBufferBase* sbb, int lockedBuffer); Loading
include/ui/KeycodeLabels.h +22 −0 Original line number Diff line number Diff line Loading @@ -189,6 +189,28 @@ static const KeycodeLabel KEYCODES[] = { { "NUMPAD_LEFT_PAREN", 162 }, { "NUMPAD_RIGHT_PAREN", 163 }, { "VOLUME_MUTE", 164 }, { "INFO", 165 }, { "CHANNEL_UP", 166 }, { "CHANNEL_DOWN", 167 }, { "ZOOM_IN", 168 }, { "ZOOM_OUT", 169 }, { "TV", 170 }, { "WINDOW", 171 }, { "GUIDE", 172 }, { "DVR", 173 }, { "BOOKMARK", 174 }, { "CAPTIONS", 175 }, { "SETTINGS", 176 }, { "TV_POWER", 177 }, { "TV_INPUT", 178 }, { "STB_POWER", 179 }, { "STB_INPUT", 180 }, { "AVR_POWER", 181 }, { "AVR_INPUT", 182 }, { "PROG_RED", 183 }, { "PROG_GREEN", 184 }, { "PROG_YELLOW", 185 }, { "PROG_BLUE", 186 }, // NOTE: If you add a new keycode here you must also add it to several other files. // Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list. Loading
libs/surfaceflinger_client/SharedBufferStack.cpp +70 −5 Original line number Diff line number Diff line Loading @@ -265,6 +265,14 @@ bool SharedBufferClient::LockCondition::operator()() const { (stack.queued > 0 && stack.inUse != buf)); } SharedBufferServer::BuffersAvailableCondition::BuffersAvailableCondition( SharedBufferServer* sbs, int numBuffers) : ConditionBase(sbs), mNumBuffers(numBuffers) { } bool SharedBufferServer::BuffersAvailableCondition::operator()() const { return stack.available == mNumBuffers; } // ---------------------------------------------------------------------------- SharedBufferClient::QueueUpdate::QueueUpdate(SharedBufferBase* sbb) Loading Loading @@ -448,6 +456,7 @@ status_t SharedBufferClient::queue(int buf) const nsecs_t now = systemTime(SYSTEM_TIME_THREAD); stack.stats.totalTime = ns2us(now - mDequeueTime[buf]); return err; } Loading Loading @@ -492,6 +501,7 @@ status_t SharedBufferClient::setBufferCount( if (err == NO_ERROR) { mNumBuffers = bufferCount; queued_head = (stack.head + stack.queued) % mNumBuffers; tail = computeTail(); } return err; } Loading Loading @@ -606,17 +616,24 @@ uint32_t SharedBufferServer::getTransform(int buf) const */ status_t SharedBufferServer::resize(int newNumBuffers) { if (uint32_t(newNumBuffers) >= SharedBufferStack::NUM_BUFFER_MAX) if ((unsigned int)(newNumBuffers) < SharedBufferStack::NUM_BUFFER_MIN || (unsigned int)(newNumBuffers) > SharedBufferStack::NUM_BUFFER_MAX) { return BAD_VALUE; } RWLock::AutoWLock _l(mLock); // for now we're not supporting shrinking const int numBuffers = mNumBuffers; if (newNumBuffers < numBuffers) return BAD_VALUE; if (newNumBuffers < mNumBuffers) { return shrink(newNumBuffers); } else { return grow(newNumBuffers); } } status_t SharedBufferServer::grow(int newNumBuffers) { SharedBufferStack& stack( *mSharedStack ); const int numBuffers = mNumBuffers; const int extra = newNumBuffers - numBuffers; // read the head, make sure it's valid Loading Loading @@ -650,6 +667,54 @@ status_t SharedBufferServer::resize(int newNumBuffers) return NO_ERROR; } status_t SharedBufferServer::shrink(int newNumBuffers) { SharedBufferStack& stack( *mSharedStack ); // Shrinking is only supported if there are no buffers currently dequeued. int32_t avail = stack.available; int32_t queued = stack.queued; if (avail + queued != mNumBuffers) { return INVALID_OPERATION; } // Wait for any queued buffers to be displayed. BuffersAvailableCondition condition(this, mNumBuffers); status_t err = waitForCondition(condition); if (err < 0) { return err; } // Reset head to index 0 and make it refer to buffer 0. The same renaming // (head -> 0) is done in the BufferManager. int32_t head = stack.head; int8_t* index = const_cast<int8_t*>(stack.index); for (int8_t i = 0; i < newNumBuffers; i++) { index[i] = i; } stack.head = 0; stack.headBuf = 0; // If one of the buffers is in use it must be the head buffer, which we are // renaming to buffer 0. if (stack.inUse > 0) { stack.inUse = 0; } // Free the buffers from the end of the list that are no longer needed. for (int i = newNumBuffers; i < mNumBuffers; i++) { mBufferList.remove(i); } // Tell the client to reallocate all the buffers. reallocateAll(); mNumBuffers = newNumBuffers; stack.available = newNumBuffers; return NO_ERROR; } SharedBufferStack::Statistics SharedBufferServer::getStats() const { SharedBufferStack& stack( *mSharedStack ); Loading
libs/surfaceflinger_client/Surface.cpp +7 −1 Original line number Diff line number Diff line Loading @@ -855,6 +855,12 @@ int Surface::setBufferCount(int bufferCount) status_t err = mSharedBufferClient->setBufferCount(bufferCount, ipc); LOGE_IF(err, "ISurface::setBufferCount(%d) returned %s", bufferCount, strerror(-err)); if (err == NO_ERROR) { // Clear out any references to the old buffers. mBuffers.clear(); } return err; } Loading Loading @@ -1029,7 +1035,7 @@ int Surface::getBufferIndex(const sp<GraphicBuffer>& buffer) const // one of the buffers for which we do know the index. This can happen // e.g. if GraphicBuffer is used to wrap an android_native_buffer_t that // was dequeued from an ANativeWindow. for (int i = 0; i < mBuffers.size(); i++) { for (size_t i = 0; i < mBuffers.size(); i++) { if (buffer->handle == mBuffers[i]->handle) { idx = mBuffers[i]->getIndex(); break; Loading
libs/surfaceflinger_client/tests/SharedBufferStack/SharedBufferStackTest.cpp +6 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,8 @@ void test0(SharedBufferServer& s, SharedBufferClient& c, size_t num, int* list); int main(int argc, char** argv) { SharedClient client; SharedBufferServer s(&client, 0, 4, 0); sp<SharedBufferServer> ps(new SharedBufferServer(&client, 0, 4, 0)); SharedBufferServer& s(*ps); SharedBufferClient c(&client, 0, 4, 0); printf("basic test 0\n"); Loading Loading @@ -67,6 +68,10 @@ int main(int argc, char** argv) int list3[6] = {3, 2, 1, 4, 5, 0}; test0(s, c, 6, list3); c.setBufferCount(4, resize); int list4[4] = {1, 2, 3, 0}; test0(s, c, 4, list4); return 0; } Loading