summaryrefslogtreecommitdiffstats
path: root/libs/surfaceflinger
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2009-08-10 21:59:56 -0700
committerMathias Agopian <mathias@google.com>2009-08-11 16:12:56 -0700
commit8b76a0ac6fbf07254629ed1ea86af014d5abe050 (patch)
treee492e09655269fff3ca14b6a62f9b07f2d484038 /libs/surfaceflinger
parentc5ea43920919eeaec4ec0686de9fa3d034d82337 (diff)
downloadframeworks_base-8b76a0ac6fbf07254629ed1ea86af014d5abe050.zip
frameworks_base-8b76a0ac6fbf07254629ed1ea86af014d5abe050.tar.gz
frameworks_base-8b76a0ac6fbf07254629ed1ea86af014d5abe050.tar.bz2
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.
This change makes SurfaceHolder.setType(GPU) obsolete (it's now ignored). Added an API to android_native_window_t to allow extending the functionality without ever breaking binary compatibility. This is used to implement the new set_usage() API. This API needs to be called by software renderers because the default is to use usage flags suitable for h/w.
Diffstat (limited to 'libs/surfaceflinger')
-rw-r--r--libs/surfaceflinger/Layer.cpp8
-rw-r--r--libs/surfaceflinger/Layer.h4
-rw-r--r--libs/surfaceflinger/LayerBase.cpp2
-rw-r--r--libs/surfaceflinger/LayerBase.h2
-rw-r--r--libs/surfaceflinger/LayerBitmap.cpp24
-rw-r--r--libs/surfaceflinger/LayerBitmap.h7
-rw-r--r--libs/surfaceflinger/LayerBuffer.cpp6
-rw-r--r--libs/surfaceflinger/LayerDim.cpp7
8 files changed, 32 insertions, 28 deletions
diff --git a/libs/surfaceflinger/Layer.cpp b/libs/surfaceflinger/Layer.cpp
index d1142cc..8c0b40d 100644
--- a/libs/surfaceflinger/Layer.cpp
+++ b/libs/surfaceflinger/Layer.cpp
@@ -217,7 +217,7 @@ void Layer::onDraw(const Region& clip) const
drawWithOpenGL(clip, mTextures[index]);
}
-sp<SurfaceBuffer> Layer::peekBuffer()
+sp<SurfaceBuffer> Layer::peekBuffer(int usage)
{
/*
* This is called from the client's Surface::lock(), after it locked
@@ -250,7 +250,7 @@ sp<SurfaceBuffer> Layer::peekBuffer()
}
LayerBitmap& layerBitmap(mBuffers[backBufferIndex]);
- sp<SurfaceBuffer> buffer = layerBitmap.allocate();
+ sp<SurfaceBuffer> buffer = layerBitmap.allocate(usage);
LOGD_IF(DEBUG_RESIZE,
"Layer::getBuffer(this=%p), index=%d, (%d,%d), (%d,%d)",
@@ -649,12 +649,12 @@ Layer::SurfaceLayer::~SurfaceLayer()
{
}
-sp<SurfaceBuffer> Layer::SurfaceLayer::getBuffer()
+sp<SurfaceBuffer> Layer::SurfaceLayer::getBuffer(int usage)
{
sp<SurfaceBuffer> buffer = 0;
sp<Layer> owner(getOwner());
if (owner != 0) {
- buffer = owner->peekBuffer();
+ buffer = owner->peekBuffer(usage);
}
return buffer;
}
diff --git a/libs/surfaceflinger/Layer.h b/libs/surfaceflinger/Layer.h
index 4c13d6e..add5d50 100644
--- a/libs/surfaceflinger/Layer.h
+++ b/libs/surfaceflinger/Layer.h
@@ -101,7 +101,7 @@ private:
status_t resize(int32_t index, uint32_t w, uint32_t h, const char* what);
Region post(uint32_t* oldState, bool& recomputeVisibleRegions);
- sp<SurfaceBuffer> peekBuffer();
+ sp<SurfaceBuffer> peekBuffer(int usage);
void destroy();
void scheduleBroadcast();
@@ -114,7 +114,7 @@ private:
~SurfaceLayer();
private:
- virtual sp<SurfaceBuffer> getBuffer();
+ virtual sp<SurfaceBuffer> getBuffer(int usage);
sp<Layer> getOwner() const {
return static_cast<Layer*>(Surface::getOwner().get());
diff --git a/libs/surfaceflinger/LayerBase.cpp b/libs/surfaceflinger/LayerBase.cpp
index fbce73d..419574c 100644
--- a/libs/surfaceflinger/LayerBase.cpp
+++ b/libs/surfaceflinger/LayerBase.cpp
@@ -759,7 +759,7 @@ status_t LayerBaseClient::Surface::onTransact(
return BnSurface::onTransact(code, data, reply, flags);
}
-sp<SurfaceBuffer> LayerBaseClient::Surface::getBuffer()
+sp<SurfaceBuffer> LayerBaseClient::Surface::getBuffer(int)
{
return NULL;
}
diff --git a/libs/surfaceflinger/LayerBase.h b/libs/surfaceflinger/LayerBase.h
index 6fb1d1c..65bf55b 100644
--- a/libs/surfaceflinger/LayerBase.h
+++ b/libs/surfaceflinger/LayerBase.h
@@ -335,7 +335,7 @@ public:
sp<LayerBaseClient> getOwner() const;
private:
- virtual sp<SurfaceBuffer> getBuffer();
+ virtual sp<SurfaceBuffer> getBuffer(int usage);
virtual status_t registerBuffers(const ISurface::BufferHeap& buffers);
virtual void postBuffer(ssize_t offset);
virtual void unregisterBuffers();
diff --git a/libs/surfaceflinger/LayerBitmap.cpp b/libs/surfaceflinger/LayerBitmap.cpp
index 5221fed..5e74451 100644
--- a/libs/surfaceflinger/LayerBitmap.cpp
+++ b/libs/surfaceflinger/LayerBitmap.cpp
@@ -38,13 +38,14 @@ namespace android {
// Buffer and implementation of android_native_buffer_t
// ===========================================================================
-Buffer::Buffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t flags)
+Buffer::Buffer(uint32_t w, uint32_t h, PixelFormat format,
+ uint32_t reqUsage, uint32_t flags)
: SurfaceBuffer(), mInitCheck(NO_INIT), mFlags(flags),
mVStride(0)
{
this->format = format;
if (w>0 && h>0) {
- mInitCheck = initSize(w, h);
+ mInitCheck = initSize(w, h, reqUsage);
}
}
@@ -65,7 +66,7 @@ android_native_buffer_t* Buffer::getNativeBuffer() const
return static_cast<android_native_buffer_t*>(const_cast<Buffer*>(this));
}
-status_t Buffer::initSize(uint32_t w, uint32_t h)
+status_t Buffer::initSize(uint32_t w, uint32_t h, uint32_t reqUsage)
{
status_t err = NO_ERROR;
@@ -88,16 +89,9 @@ status_t Buffer::initSize(uint32_t w, uint32_t h)
usage = BufferAllocator::USAGE_SW_READ_OFTEN |
BufferAllocator::USAGE_SW_WRITE_OFTEN;
} else {
- if (mFlags & Buffer::GPU) {
- // the client wants to do GL rendering
- usage = BufferAllocator::USAGE_HW_RENDER |
- BufferAllocator::USAGE_HW_TEXTURE;
- } else {
- // software rendering-client, h/w composition
- usage = BufferAllocator::USAGE_SW_READ_OFTEN |
- BufferAllocator::USAGE_SW_WRITE_OFTEN |
- BufferAllocator::USAGE_HW_TEXTURE;
- }
+ // it's allowed to modify the usage flags here, but generally
+ // the requested flags should be honored.
+ usage = reqUsage | BufferAllocator::USAGE_HW_TEXTURE;
}
err = allocator.alloc(w, h, format, usage, &handle, &stride);
@@ -174,12 +168,12 @@ status_t LayerBitmap::setSize(uint32_t w, uint32_t h)
return NO_ERROR;
}
-sp<Buffer> LayerBitmap::allocate()
+sp<Buffer> LayerBitmap::allocate(uint32_t reqUsage)
{
Mutex::Autolock _l(mLock);
surface_info_t* info = mInfo;
mBuffer.clear(); // free buffer before allocating a new one
- sp<Buffer> buffer = new Buffer(mWidth, mHeight, mFormat, mFlags);
+ sp<Buffer> buffer = new Buffer(mWidth, mHeight, mFormat, reqUsage, mFlags);
status_t err = buffer->initCheck();
if (LIKELY(err == NO_ERROR)) {
info->flags = surface_info_t::eBufferDirty;
diff --git a/libs/surfaceflinger/LayerBitmap.h b/libs/surfaceflinger/LayerBitmap.h
index 22525ce..48ee553 100644
--- a/libs/surfaceflinger/LayerBitmap.h
+++ b/libs/surfaceflinger/LayerBitmap.h
@@ -58,7 +58,8 @@ public:
};
// creates w * h buffer
- Buffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t flags = 0);
+ Buffer(uint32_t w, uint32_t h, PixelFormat format,
+ uint32_t reqUsage, uint32_t flags = 0);
// return status
status_t initCheck() const;
@@ -81,7 +82,7 @@ private:
Buffer& operator = (const Buffer& rhs);
const Buffer& operator = (const Buffer& rhs) const;
- status_t initSize(uint32_t w, uint32_t h);
+ status_t initSize(uint32_t w, uint32_t h, uint32_t reqUsage);
ssize_t mInitCheck;
uint32_t mFlags;
@@ -108,7 +109,7 @@ public:
status_t setSize(uint32_t w, uint32_t h);
- sp<Buffer> allocate();
+ sp<Buffer> allocate(uint32_t reqUsage);
status_t free();
sp<const Buffer> getBuffer() const { return mBuffer; }
diff --git a/libs/surfaceflinger/LayerBuffer.cpp b/libs/surfaceflinger/LayerBuffer.cpp
index 90e7f50..e1f4bea 100644
--- a/libs/surfaceflinger/LayerBuffer.cpp
+++ b/libs/surfaceflinger/LayerBuffer.cpp
@@ -28,6 +28,7 @@
#include <hardware/copybit.h>
+#include "BufferAllocator.h"
#include "LayerBuffer.h"
#include "SurfaceFlinger.h"
#include "DisplayHardware/DisplayHardware.h"
@@ -464,7 +465,10 @@ void LayerBuffer::BufferSource::onDraw(const Region& clip) const
mTempBitmap->getWidth() < tmp_w ||
mTempBitmap->getHeight() < tmp_h) {
mTempBitmap.clear();
- mTempBitmap = new android::Buffer(tmp_w, tmp_h, src.img.format);
+ mTempBitmap = new android::Buffer(
+ tmp_w, tmp_h, src.img.format,
+ BufferAllocator::USAGE_HW_TEXTURE |
+ BufferAllocator::USAGE_HW_2D);
err = mTempBitmap->initCheck();
}
diff --git a/libs/surfaceflinger/LayerDim.cpp b/libs/surfaceflinger/LayerDim.cpp
index 8e9df9c..6ebb49f 100644
--- a/libs/surfaceflinger/LayerDim.cpp
+++ b/libs/surfaceflinger/LayerDim.cpp
@@ -21,6 +21,7 @@
#include <utils/Errors.h>
#include <utils/Log.h>
+#include "BufferAllocator.h"
#include "LayerDim.h"
#include "SurfaceFlinger.h"
#include "DisplayHardware/DisplayHardware.h"
@@ -68,7 +69,11 @@ void LayerDim::initDimmer(SurfaceFlinger* flinger, uint32_t w, uint32_t h)
if (LIKELY(flags & DisplayHardware::DIRECT_TEXTURE)) {
// TODO: api to pass the usage flags
- sp<Buffer> buffer = new Buffer(w, h, PIXEL_FORMAT_RGB_565);
+ sp<Buffer> buffer = new Buffer(w, h, PIXEL_FORMAT_RGB_565,
+ BufferAllocator::USAGE_SW_WRITE_OFTEN |
+ BufferAllocator::USAGE_HW_TEXTURE |
+ BufferAllocator::USAGE_HW_2D);
+
android_native_buffer_t* clientBuf = buffer->getNativeBuffer();
glGenTextures(1, &sTexId);