From 5cec4742b3a1d7448bd32ae57cb4cf70b484c64c Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 11 Aug 2009 22:34:02 -0700 Subject: second take, hopefully this time it doesn't break one of the builds: "SurfaceFlinger will now allocate buffers based on the usage specified by the clients. This allows to allocate the right kind of buffer automatically, without having the user to specify anything." --- libs/ui/Surface.cpp | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'libs/ui/Surface.cpp') diff --git a/libs/ui/Surface.cpp b/libs/ui/Surface.cpp index 4abb7f62ad44..2b6905f33fc2 100644 --- a/libs/ui/Surface.cpp +++ b/libs/ui/Surface.cpp @@ -414,6 +414,7 @@ void Surface::init() android_native_window_t::lockBuffer = lockBuffer; android_native_window_t::queueBuffer = queueBuffer; android_native_window_t::query = query; + android_native_window_t::perform = perform; mSwapRectangle.makeInvalid(); DisplayInfo dinfo; SurfaceComposerClient::getDisplayInfo(0, &dinfo); @@ -423,6 +424,8 @@ void Surface::init() const_cast(android_native_window_t::minSwapInterval) = 1; const_cast(android_native_window_t::maxSwapInterval) = 1; const_cast(android_native_window_t::flags) = 0; + // be default we request a hardware surface + mUsage = GRALLOC_USAGE_HW_RENDER; } @@ -512,6 +515,17 @@ int Surface::query(android_native_window_t* window, return self->query(what, value); } +int Surface::perform(android_native_window_t* window, + int operation, ...) +{ + va_list args; + va_start(args, operation); + Surface* self = getSelf(window); + int res = self->perform(operation, args); + va_end(args); + return res; +} + // ---------------------------------------------------------------------------- status_t Surface::dequeueBuffer(sp* buffer) @@ -561,7 +575,7 @@ int Surface::dequeueBuffer(android_native_buffer_t** buffer) volatile const surface_info_t* const back = lcblk->surface + backIdx; if (back->flags & surface_info_t::eNeedNewBuffer) { - err = getBufferLocked(backIdx); + err = getBufferLocked(backIdx, mUsage); } if (err == NO_ERROR) { @@ -627,6 +641,20 @@ int Surface::query(int what, int* value) return BAD_VALUE; } +int Surface::perform(int operation, va_list args) +{ + int res = NO_ERROR; + switch (operation) { + case NATIVE_WINDOW_SET_USAGE: + mUsage = va_arg(args, int); + break; + default: + res = NAME_NOT_FOUND; + break; + } + return res; +} + // ---------------------------------------------------------------------------- status_t Surface::lock(SurfaceInfo* info, bool blocking) { @@ -636,6 +664,9 @@ status_t Surface::lock(SurfaceInfo* info, bool blocking) { status_t Surface::lock(SurfaceInfo* other, Region* dirtyIn, bool blocking) { // FIXME: needs some locking here + + // we're intending to do software rendering from this point + mUsage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN; sp backBuffer; status_t err = dequeueBuffer(&backBuffer); @@ -725,10 +756,10 @@ void Surface::setSwapRectangle(const Rect& r) { mSwapRectangle = r; } -status_t Surface::getBufferLocked(int index) +status_t Surface::getBufferLocked(int index, int usage) { status_t err = NO_MEMORY; - sp buffer = mSurface->getBuffer(); + sp buffer = mSurface->getBuffer(usage); LOGE_IF(buffer==0, "ISurface::getBuffer() returned NULL"); if (buffer != 0) { sp& currentBuffer(mBuffers[index]); -- cgit v1.2.3-59-g8ed1b