Merge "Add Geocorder.isImplemented()" into kraken
diff --git a/camera/tests/CameraServiceTest/Android.mk b/camera/tests/CameraServiceTest/Android.mk
index 9bb190a..cf4e42f 100644
--- a/camera/tests/CameraServiceTest/Android.mk
+++ b/camera/tests/CameraServiceTest/Android.mk
@@ -21,4 +21,6 @@
libcamera_client \
libsurfaceflinger_client
-include $(BUILD_EXECUTABLE)
+# Disable it because the ISurface interface may change, and before we have a
+# chance to fix this test, we don't want to break normal builds.
+#include $(BUILD_EXECUTABLE)
diff --git a/core/res/res/drawable-hdpi/status_bar_background.png b/core/res/res/drawable-hdpi/status_bar_background.png
index e6a865a..3d00cd0 100644
--- a/core/res/res/drawable-hdpi/status_bar_background.png
+++ b/core/res/res/drawable-hdpi/status_bar_background.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/status_bar_close_on.9.png b/core/res/res/drawable-hdpi/status_bar_close_on.9.png
index 5acf638..f313ffb 100644
--- a/core/res/res/drawable-hdpi/status_bar_close_on.9.png
+++ b/core/res/res/drawable-hdpi/status_bar_close_on.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/status_bar_header_background.9.png b/core/res/res/drawable-hdpi/status_bar_header_background.9.png
index be36ff2..37b5fef 100644
--- a/core/res/res/drawable-hdpi/status_bar_header_background.9.png
+++ b/core/res/res/drawable-hdpi/status_bar_header_background.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/statusbar_background.9.png b/core/res/res/drawable-hdpi/statusbar_background.9.png
index dcca695..a4be298 100644
--- a/core/res/res/drawable-hdpi/statusbar_background.9.png
+++ b/core/res/res/drawable-hdpi/statusbar_background.9.png
Binary files differ
diff --git a/core/res/res/layout/status_bar.xml b/core/res/res/layout/status_bar.xml
index e8d8866..2237ee4 100644
--- a/core/res/res/layout/status_bar.xml
+++ b/core/res/res/layout/status_bar.xml
@@ -76,28 +76,28 @@
android:paddingTop="2dip"
android:paddingRight="10dip">
<TextView
+ android:textAppearance="@style/TextAppearance.StatusBar.Ticker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
- android:textColor="#ff000000" />
+ />
<TextView
+ android:textAppearance="@style/TextAppearance.StatusBar.Ticker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
- android:textColor="#ff000000" />
+ />
</com.android.server.status.TickerView>
</LinearLayout>
<com.android.server.status.DateView android:id="@+id/date"
+ android:textAppearance="@style/TextAppearance.StatusBar.Icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:singleLine="true"
- android:textSize="16sp"
- android:textStyle="bold"
android:gravity="center_vertical|left"
android:paddingLeft="6px"
android:paddingRight="6px"
- android:textColor="?android:attr/textColorPrimaryInverse"
android:background="@drawable/statusbar_background"
/>
</com.android.server.status.StatusBarView>
diff --git a/core/res/res/layout/status_bar_expanded.xml b/core/res/res/layout/status_bar_expanded.xml
index 30138a7..68eb922 100644
--- a/core/res/res/layout/status_bar_expanded.xml
+++ b/core/res/res/layout/status_bar_expanded.xml
@@ -48,7 +48,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceLarge"
- android:textColor="?android:attr/textColorSecondaryInverse"
+ android:textColor="?android:attr/textColorSecondary"
android:paddingLeft="4dp"
/>
<TextView android:id="@+id/spnLabel"
@@ -56,7 +56,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceLarge"
- android:textColor="?android:attr/textColorSecondaryInverse"
+ android:textColor="?android:attr/textColorSecondary"
android:paddingLeft="4dp"
/>
</LinearLayout>
@@ -67,7 +67,7 @@
android:layout_marginTop="4dp"
android:layout_marginBottom="1dp"
android:textSize="14sp"
- android:textColor="#ff000000"
+ android:textColor="?android:attr/textColorPrimaryInverse"
android:text="@string/status_bar_clear_all_button"
style="?android:attr/buttonStyle"
android:paddingLeft="15dp"
@@ -99,7 +99,7 @@
android:layout_height="wrap_content"
android:background="@drawable/title_bar_portrait"
android:paddingLeft="5dp"
- android:textAppearance="@style/TextAppearance.StatusBarTitle"
+ android:textAppearance="@style/TextAppearance.StatusBar.Title"
android:text="@string/status_bar_no_notifications_title"
/>
@@ -108,7 +108,7 @@
android:layout_height="wrap_content"
android:background="@drawable/title_bar_portrait"
android:paddingLeft="5dp"
- android:textAppearance="@style/TextAppearance.StatusBarTitle"
+ android:textAppearance="@style/TextAppearance.StatusBar.Title"
android:text="@string/status_bar_ongoing_events_title"
/>
<LinearLayout android:id="@+id/ongoingItems"
@@ -122,7 +122,7 @@
android:layout_height="wrap_content"
android:background="@drawable/title_bar_portrait"
android:paddingLeft="5dp"
- android:textAppearance="@style/TextAppearance.StatusBarTitle"
+ android:textAppearance="@style/TextAppearance.StatusBar.Title"
android:text="@string/status_bar_latest_events_title"
/>
<LinearLayout android:id="@+id/latestItems"
diff --git a/core/res/res/layout/status_bar_latest_event_content.xml b/core/res/res/layout/status_bar_latest_event_content.xml
index c3aa041..ea6200a 100644
--- a/core/res/res/layout/status_bar_latest_event_content.xml
+++ b/core/res/res/layout/status_bar_latest_event_content.xml
@@ -18,16 +18,15 @@
android:scaleType="fitCenter"
android:src="@drawable/arrow_down_float"/>
<TextView android:id="@+id/title"
+ android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
- android:textStyle="bold"
- android:textSize="18sp"
android:paddingLeft="4dp"
- android:textColor="#ff000000" />
+ />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
@@ -35,23 +34,22 @@
android:orientation="horizontal"
>
<TextView android:id="@+id/text"
+ android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
- android:textColor="#ff000000"
android:singleLine="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
- android:textSize="14sp"
android:paddingLeft="4dp"
/>
<android.widget.DateTimeView android:id="@+id/time"
+ android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
android:layout_marginLeft="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
- android:textSize="14sp"
android:paddingRight="5dp"
- android:textColor="#ff000000" />
+ />
</LinearLayout>
</LinearLayout>
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index b5fff96..af04117 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -187,11 +187,26 @@
<!-- Status Bar Styles -->
- <style name="TextAppearance.StatusBarTitle">
+ <style name="TextAppearance.StatusBar">
<item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
- <item name="android:textStyle">bold</item>
<item name="android:textColor">?android:attr/textColorPrimary</item>
</style>
+ <style name="TextAppearance.StatusBar.Ticker">
+ </style>
+ <style name="TextAppearance.StatusBar.Title">
+ <item name="android:textStyle">bold</item>
+ </style>
+
+ <style name="TextAppearance.StatusBar.Icon">
+ <item name="android:textStyle">bold</item>
+ </style>
+ <style name="TextAppearance.StatusBar.EventContent">
+ <item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
+ </style>
+ <style name="TextAppearance.StatusBar.EventContent.Title">
+ <item name="android:textSize">18sp</item>
+ <item name="android:textStyle">bold</item>
+ </style>
<!-- Widget Styles -->
diff --git a/docs/html/index.jd b/docs/html/index.jd
index 0ba5e08..01940e8 100644
--- a/docs/html/index.jd
+++ b/docs/html/index.jd
@@ -14,9 +14,8 @@
<img src="{@docRoot}images/home/io-logo.png" alt="Google IO
2010" width="200" height="41" style="padding:22px 12px;"/>
<div id="announcement" style="width:295px">
-<p>Google I/O is happening now! To those of you with us, welcome! If you couldn't make it to the
-event, stay tuned for videos and slides from the Android sessions, which will be posted at the
-Google I/O web site.</p><p><a
+<p>Thanks to everyone who visited us at Google I/O in San Francisco! Stay tuned for
+videos and slides from the Android sessions, which will be posted at the Google I/O web site.</p><p><a
href="http://code.google.com/events/io/2010/sessions.html#Android">Learn more »</a></p>
</div> <!-- end annoucement -->
</div> <!-- end annoucement-block -->
diff --git a/docs/html/resources/tutorials/hello-world.jd b/docs/html/resources/tutorials/hello-world.jd
index 7bad054..77ffc6f 100644
--- a/docs/html/resources/tutorials/hello-world.jd
+++ b/docs/html/resources/tutorials/hello-world.jd
@@ -299,7 +299,7 @@
<pre><?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@id+/textview"
+ android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/hello"/></pre>
@@ -410,7 +410,7 @@
<pre><?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@id+/textview"
+ android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/hello"/></pre>
diff --git a/docs/html/sdk/eclipse-adt.jd b/docs/html/sdk/eclipse-adt.jd
index 57eac1f..f5558ab 100644
--- a/docs/html/sdk/eclipse-adt.jd
+++ b/docs/html/sdk/eclipse-adt.jd
@@ -95,7 +95,7 @@
<div class="toggleable opened">
<a href="#" onclick="return toggleDiv(this)">
<img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-img" height="9px" width="9px" />
-ADT 0.9.6</a> <em>(March 2010)</em>
+ADT 0.9.7</a> <em>(May 2010)</em>
<div class="toggleme">
<dl>
diff --git a/include/camera/CameraParameters.h b/include/camera/CameraParameters.h
index 20eef72..faf6155 100644
--- a/include/camera/CameraParameters.h
+++ b/include/camera/CameraParameters.h
@@ -119,14 +119,17 @@
// should not set default value for this parameter.
// Example value: "0" or "90" or "180" or "270". Write only.
static const char KEY_ROTATION[];
- // GPS latitude coordinate. This will be stored in JPEG EXIF header.
- // Example value: "25.032146". Write only.
+ // GPS latitude coordinate. GPSLatitude and GPSLatitudeRef will be stored in
+ // JPEG EXIF header.
+ // Example value: "25.032146" or "-33.462809". Write only.
static const char KEY_GPS_LATITUDE[];
- // GPS longitude coordinate. This will be stored in JPEG EXIF header.
- // Example value: "121.564448". Write only.
+ // GPS longitude coordinate. GPSLongitude and GPSLongitudeRef will be stored
+ // in JPEG EXIF header.
+ // Example value: "121.564448" or "-70.660286". Write only.
static const char KEY_GPS_LONGITUDE[];
- // GPS altitude. This will be stored in JPEG EXIF header.
- // Example value: "21.0". Write only.
+ // GPS altitude. GPSAltitude and GPSAltitudeRef will be stored in JPEG EXIF
+ // header.
+ // Example value: "21.0" or "-5". Write only.
static const char KEY_GPS_ALTITUDE[];
// GPS timestamp (UTC in seconds since January 1, 1970). This should be
// stored in JPEG EXIF header.
diff --git a/include/private/surfaceflinger/SharedBufferStack.h b/include/private/surfaceflinger/SharedBufferStack.h
index a1a02e0..c3ac317 100644
--- a/include/private/surfaceflinger/SharedBufferStack.h
+++ b/include/private/surfaceflinger/SharedBufferStack.h
@@ -55,12 +55,6 @@
*
*/
-// When changing these values, the COMPILE_TIME_ASSERT at the end of this
-// file need to be updated.
-const unsigned int NUM_LAYERS_MAX = 31;
-const unsigned int NUM_BUFFER_MAX = 16;
-const unsigned int NUM_DISPLAY_MAX = 4;
-
// ----------------------------------------------------------------------------
class Region;
@@ -82,6 +76,13 @@
friend class SharedBufferServer;
public:
+ // When changing these values, the COMPILE_TIME_ASSERT at the end of this
+ // file need to be updated.
+ static const unsigned int NUM_LAYERS_MAX = 31;
+ static const unsigned int NUM_BUFFER_MAX = 16;
+ static const unsigned int NUM_BUFFER_MIN = 2;
+ static const unsigned int NUM_DISPLAY_MAX = 4;
+
struct Statistics { // 4 longs
typedef int32_t usecs_t;
usecs_t totalTime;
@@ -147,7 +148,7 @@
// FIXME: this should be replaced by a lock-less primitive
Mutex lock;
Condition cv;
- SharedBufferStack surfaces[ NUM_LAYERS_MAX ];
+ SharedBufferStack surfaces[ SharedBufferStack::NUM_LAYERS_MAX ];
};
// ============================================================================
@@ -155,7 +156,7 @@
class SharedBufferBase
{
public:
- SharedBufferBase(SharedClient* sharedClient, int surface, int num,
+ SharedBufferBase(SharedClient* sharedClient, int surface,
int32_t identity);
~SharedBufferBase();
uint32_t getIdentity();
@@ -166,9 +167,7 @@
protected:
SharedClient* const mSharedClient;
SharedBufferStack* const mSharedStack;
- int mNumBuffers;
const int mIdentity;
- int32_t computeTail() const;
friend struct Update;
friend struct QueueUpdate;
@@ -217,8 +216,16 @@
bool needNewBuffer(int buffer) const;
status_t setDirtyRegion(int buffer, const Region& reg);
status_t setCrop(int buffer, const Rect& reg);
- status_t setBufferCount(int bufferCount);
+
+ class SetBufferCountCallback {
+ friend class SharedBufferClient;
+ virtual status_t operator()(int bufferCount) const = 0;
+ protected:
+ virtual ~SetBufferCountCallback() { }
+ };
+ status_t setBufferCount(int bufferCount, const SetBufferCountCallback& ipc);
+
private:
friend struct Condition;
friend struct DequeueCondition;
@@ -249,11 +256,16 @@
inline const char* name() const { return "LockCondition"; }
};
+ int32_t computeTail() const;
+
+ mutable RWLock mLock;
+ int mNumBuffers;
+
int32_t tail;
int32_t undoDequeueTail;
int32_t queued_head;
// statistics...
- nsecs_t mDequeueTime[NUM_BUFFER_MAX];
+ nsecs_t mDequeueTime[SharedBufferStack::NUM_BUFFER_MAX];
};
// ----------------------------------------------------------------------------
@@ -287,7 +299,8 @@
size_t mCapacity;
uint32_t mList;
public:
- BufferList(size_t c = NUM_BUFFER_MAX) : mCapacity(c), mList(0) { }
+ BufferList(size_t c = SharedBufferStack::NUM_BUFFER_MAX)
+ : mCapacity(c), mList(0) { }
status_t add(int value);
status_t remove(int value);
@@ -324,6 +337,9 @@
}
};
+ // this protects mNumBuffers and mBufferList
+ mutable RWLock mLock;
+ int mNumBuffers;
BufferList mBufferList;
struct UnlockUpdate : public UpdateBase {
@@ -373,7 +389,7 @@
uint8_t connected;
uint8_t reserved[3];
uint32_t pad[7];
- display_cblk_t displays[NUM_DISPLAY_MAX];
+ display_cblk_t displays[SharedBufferStack::NUM_DISPLAY_MAX];
};
// ---------------------------------------------------------------------------
diff --git a/include/surfaceflinger/Surface.h b/include/surfaceflinger/Surface.h
index 973780f..e4d60af 100644
--- a/include/surfaceflinger/Surface.h
+++ b/include/surfaceflinger/Surface.h
@@ -212,6 +212,7 @@
int dispatch_connect(va_list args);
int dispatch_disconnect(va_list args);
int dispatch_crop(va_list args);
+ int dispatch_set_buffer_count(va_list args);
void setUsage(uint32_t reqUsage);
int connect(int api);
diff --git a/include/ui/egl/android_natives.h b/include/ui/egl/android_natives.h
index 49bfa2b..b44901f 100644
--- a/include/ui/egl/android_natives.h
+++ b/include/ui/egl/android_natives.h
@@ -81,6 +81,7 @@
NATIVE_WINDOW_CONNECT,
NATIVE_WINDOW_DISCONNECT,
NATIVE_WINDOW_SET_CROP,
+ NATIVE_WINDOW_SET_BUFFER_COUNT,
};
/* parameter for NATIVE_WINDOW_[DIS]CONNECT */
@@ -190,6 +191,7 @@
* NATIVE_WINDOW_CONNECT
* NATIVE_WINDOW_DISCONNECT
* NATIVE_WINDOW_SET_CROP
+ * NATIVE_WINDOW_SET_BUFFER_COUNT
*
*/
@@ -201,8 +203,9 @@
/*
- * native_window_set_usage() sets the intended usage flags for the next
- * buffers acquired with (*lockBuffer)() and on.
+ * native_window_set_usage(..., usage)
+ * Sets the intended usage flags for the next buffers
+ * acquired with (*lockBuffer)() and on.
* By default (if this function is never called), a usage of
* GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE
* is assumed.
@@ -217,8 +220,8 @@
}
/*
- * native_window_connect(..., NATIVE_WINDOW_API_EGL) must be called
- * by EGL when the window is made current.
+ * native_window_connect(..., NATIVE_WINDOW_API_EGL)
+ * Must be called by EGL when the window is made current.
* Returns -EINVAL if for some reason the window cannot be connected, which
* can happen if it's connected to some other API.
*/
@@ -229,8 +232,8 @@
}
/*
- * native_window_disconnect(..., NATIVE_WINDOW_API_EGL) must be called
- * by EGL when the window is made not current.
+ * native_window_disconnect(..., NATIVE_WINDOW_API_EGL)
+ * Must be called by EGL when the window is made not current.
* An error is returned if for instance the window wasn't connected in the
* first place.
*/
@@ -241,8 +244,8 @@
}
/*
- * native_window_set_crop(..., crop) sets which region of the next queued
- * buffers needs to be considered.
+ * native_window_set_crop(..., crop)
+ * Sets which region of the next queued buffers needs to be considered.
* A buffer's crop region is scaled to match the surface's size.
*
* The specified crop region applies to all buffers queued after it is called.
@@ -259,6 +262,17 @@
return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
}
+/*
+ * native_window_set_buffer_count(..., count)
+ * Sets the number of buffers associated with this native window.
+ */
+static inline int native_window_set_buffer_count(
+ android_native_window_t* window,
+ size_t bufferCount)
+{
+ return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
+}
+
// ---------------------------------------------------------------------------
/* FIXME: this is legacy for pixmaps */
diff --git a/libs/surfaceflinger/Barrier.h b/libs/surfaceflinger/Barrier.h
index e2bcf6a..6f8507e 100644
--- a/libs/surfaceflinger/Barrier.h
+++ b/libs/surfaceflinger/Barrier.h
@@ -29,10 +29,6 @@
inline Barrier() : state(CLOSED) { }
inline ~Barrier() { }
void open() {
- // gcc memory barrier, this makes sure all memory writes
- // have been issued by gcc. On an SMP system we'd need a real
- // h/w barrier.
- asm volatile ("":::"memory");
Mutex::Autolock _l(lock);
state = OPENED;
cv.broadcast();
diff --git a/libs/surfaceflinger/Layer.cpp b/libs/surfaceflinger/Layer.cpp
index 1fe997d..621b7e3 100644
--- a/libs/surfaceflinger/Layer.cpp
+++ b/libs/surfaceflinger/Layer.cpp
@@ -60,7 +60,7 @@
// no OpenGL operation is possible here, since we might not be
// in the OpenGL thread.
lcblk = new SharedBufferServer(
- client->ctrlblk, i, mBufferManager.getBufferCount(),
+ client->ctrlblk, i, mBufferManager.getDefaultBufferCount(),
getIdentity());
mBufferManager.setActiveBufferIndex( lcblk->getFrontBuffer() );
@@ -68,7 +68,10 @@
Layer::~Layer()
{
- destroy();
+ // FIXME: must be called from the main UI thread
+ EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
+ mBufferManager.destroy(dpy);
+
// the actual buffers will be destroyed here
delete lcblk;
}
@@ -81,17 +84,6 @@
lcblk->setStatus(NO_INIT);
}
-void Layer::destroy()
-{
- EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
- mBufferManager.destroy(dpy);
-
- mSurface.clear();
-
- Mutex::Autolock _l(mLock);
- mWidth = mHeight = 0;
-}
-
sp<LayerBaseClient::Surface> Layer::createSurface() const
{
return mSurface;
@@ -99,9 +91,17 @@
status_t Layer::ditch()
{
+ // NOTE: Called from the main UI thread
+
// the layer is not on screen anymore. free as much resources as possible
mFreezeLock.clear();
- destroy();
+
+ EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
+ mBufferManager.destroy(dpy);
+ mSurface.clear();
+
+ Mutex::Autolock _l(mLock);
+ mWidth = mHeight = 0;
return NO_ERROR;
}
@@ -211,7 +211,7 @@
status_t Layer::setBufferCount(int bufferCount)
{
- // this ensures our client doesn't go away while we're accessing
+ // Ensures our client doesn't go away while we're accessing
// the shared area.
sp<Client> ourClient(client.promote());
if (ourClient == 0) {
@@ -219,15 +219,10 @@
return DEAD_OBJECT;
}
- status_t err;
-
- // FIXME: resize() below is NOT thread-safe, we need to synchronize
- // the users of lcblk in our process (ie: retire), and we assume the
- // client is not mucking with the SharedStack, which is only enforced
- // by construction, therefore we need to protect ourselves against
- // buggy and malicious client (as always)
-
- err = lcblk->resize(bufferCount);
+ // NOTE: lcblk->resize() is protected by an internal lock
+ status_t err = lcblk->resize(bufferCount);
+ if (err == NO_ERROR)
+ mBufferManager.resize(bufferCount);
return err;
}
@@ -248,7 +243,7 @@
* This is called from the client's Surface::dequeue(). This can happen
* at any time, especially while we're in the middle of using the
* buffer 'index' as our front buffer.
- *
+ *
* Make sure the buffer we're resizing is not the front buffer and has been
* dequeued. Once this condition is asserted, we are guaranteed that this
* buffer cannot become the front buffer under our feet, since we're called
@@ -544,12 +539,20 @@
// ---------------------------------------------------------------------------
Layer::BufferManager::BufferManager(TextureManager& tm)
- : mTextureManager(tm), mActiveBuffer(0), mFailover(false)
+ : mNumBuffers(NUM_BUFFERS), mTextureManager(tm),
+ mActiveBuffer(0), mFailover(false)
{
}
-size_t Layer::BufferManager::getBufferCount() const {
- return NUM_BUFFERS;
+Layer::BufferManager::~BufferManager()
+{
+}
+
+status_t Layer::BufferManager::resize(size_t size)
+{
+ Mutex::Autolock _l(mLock);
+ mNumBuffers = size;
+ return NO_ERROR;
}
// only for debugging
@@ -568,51 +571,55 @@
}
Texture Layer::BufferManager::getActiveTexture() const {
- return mFailover ? mFailoverTexture : mBufferData[mActiveBuffer].texture;
+ Texture res;
+ if (mFailover) {
+ res = mFailoverTexture;
+ } else {
+ static_cast<Image&>(res) = mBufferData[mActiveBuffer].texture;
+ }
+ return res;
}
sp<GraphicBuffer> Layer::BufferManager::getActiveBuffer() const {
+ const size_t activeBuffer = mActiveBuffer;
+ BufferData const * const buffers = mBufferData;
Mutex::Autolock _l(mLock);
- return mBufferData[mActiveBuffer].buffer;
+ return buffers[activeBuffer].buffer;
}
sp<GraphicBuffer> Layer::BufferManager::detachBuffer(size_t index)
{
+ BufferData* const buffers = mBufferData;
sp<GraphicBuffer> buffer;
Mutex::Autolock _l(mLock);
- buffer = mBufferData[index].buffer;
- mBufferData[index].buffer = 0;
+ buffer = buffers[index].buffer;
+ buffers[index].buffer = 0;
return buffer;
}
status_t Layer::BufferManager::attachBuffer(size_t index,
const sp<GraphicBuffer>& buffer)
{
+ BufferData* const buffers = mBufferData;
Mutex::Autolock _l(mLock);
- mBufferData[index].buffer = buffer;
- mBufferData[index].texture.dirty = true;
- return NO_ERROR;
-}
-
-status_t Layer::BufferManager::destroyTexture(Texture* tex, EGLDisplay dpy)
-{
- if (tex->name != -1U) {
- glDeleteTextures(1, &tex->name);
- tex->name = -1U;
- }
- if (tex->image != EGL_NO_IMAGE_KHR) {
- eglDestroyImageKHR(dpy, tex->image);
- tex->image = EGL_NO_IMAGE_KHR;
- }
+ buffers[index].buffer = buffer;
+ buffers[index].texture.dirty = true;
return NO_ERROR;
}
status_t Layer::BufferManager::destroy(EGLDisplay dpy)
{
- Mutex::Autolock _l(mLock);
- for (size_t i=0 ; i<NUM_BUFFERS ; i++) {
- destroyTexture(&mBufferData[i].texture, dpy);
- mBufferData[i].buffer = 0;
+ BufferData* const buffers = mBufferData;
+ size_t num;
+ { // scope for the lock
+ Mutex::Autolock _l(mLock);
+ num = mNumBuffers;
+ for (size_t i=0 ; i<num ; i++) {
+ buffers[i].buffer = 0;
+ }
+ }
+ for (size_t i=0 ; i<num ; i++) {
+ destroyTexture(&buffers[i].texture, dpy);
}
destroyTexture(&mFailoverTexture, dpy);
return NO_ERROR;
@@ -622,7 +629,7 @@
const sp<GraphicBuffer>& buffer)
{
size_t index = mActiveBuffer;
- Texture& texture(mBufferData[index].texture);
+ Image& texture(mBufferData[index].texture);
status_t err = mTextureManager.initEglImage(&texture, dpy, buffer);
// if EGLImage fails, we switch to regular texture mode, and we
// free all resources associated with using EGLImages.
@@ -631,7 +638,8 @@
destroyTexture(&mFailoverTexture, dpy);
} else {
mFailover = true;
- for (size_t i=0 ; i<NUM_BUFFERS ; i++) {
+ const size_t num = mNumBuffers;
+ for (size_t i=0 ; i<num ; i++) {
destroyTexture(&mBufferData[i].texture, dpy);
}
}
@@ -644,6 +652,19 @@
return mTextureManager.loadTexture(&mFailoverTexture, dirty, t);
}
+status_t Layer::BufferManager::destroyTexture(Image* tex, EGLDisplay dpy)
+{
+ if (tex->name != -1U) {
+ glDeleteTextures(1, &tex->name);
+ tex->name = -1U;
+ }
+ if (tex->image != EGL_NO_IMAGE_KHR) {
+ eglDestroyImageKHR(dpy, tex->image);
+ tex->image = EGL_NO_IMAGE_KHR;
+ }
+ return NO_ERROR;
+}
+
// ---------------------------------------------------------------------------
Layer::SurfaceLayer::SurfaceLayer(const sp<SurfaceFlinger>& flinger,
@@ -661,6 +682,11 @@
sp<GraphicBuffer> buffer;
sp<Layer> owner(getOwner());
if (owner != 0) {
+ /*
+ * requestBuffer() cannot be called from the main thread
+ * as it could cause a dead-lock, since it may have to wait
+ * on conditions updated my the main thread.
+ */
buffer = owner->requestBuffer(index, usage);
}
return buffer;
@@ -671,6 +697,11 @@
status_t err = DEAD_OBJECT;
sp<Layer> owner(getOwner());
if (owner != 0) {
+ /*
+ * setBufferCount() cannot be called from the main thread
+ * as it could cause a dead-lock, since it may have to wait
+ * on conditions updated my the main thread.
+ */
err = owner->setBufferCount(bufferCount);
}
return err;
diff --git a/libs/surfaceflinger/Layer.h b/libs/surfaceflinger/Layer.h
index 80fbd6a..247748b 100644
--- a/libs/surfaceflinger/Layer.h
+++ b/libs/surfaceflinger/Layer.h
@@ -90,7 +90,6 @@
sp<GraphicBuffer> requestBuffer(int index, int usage);
status_t setBufferCount(int bufferCount);
- void destroy();
class SurfaceLayer : public LayerBaseClient::Surface {
public:
@@ -120,25 +119,32 @@
static const size_t NUM_BUFFERS = 2;
struct BufferData {
sp<GraphicBuffer> buffer;
- Texture texture;
+ Image texture;
};
+ // this lock protect mBufferData[].buffer but since there
+ // is very little contention, we have only one like for
+ // the whole array, we also use it to protect mNumBuffers.
mutable Mutex mLock;
- BufferData mBufferData[NUM_BUFFERS];
+ BufferData mBufferData[SharedBufferStack::NUM_BUFFER_MAX];
+ size_t mNumBuffers;
Texture mFailoverTexture;
TextureManager& mTextureManager;
ssize_t mActiveBuffer;
bool mFailover;
- static status_t destroyTexture(Texture* tex, EGLDisplay dpy);
+ static status_t destroyTexture(Image* tex, EGLDisplay dpy);
public:
+ static size_t getDefaultBufferCount() { return NUM_BUFFERS; }
BufferManager(TextureManager& tm);
-
- size_t getBufferCount() const;
+ ~BufferManager();
// detach/attach buffer from/to given index
sp<GraphicBuffer> detachBuffer(size_t index);
status_t attachBuffer(size_t index, const sp<GraphicBuffer>& buffer);
+ // resize the number of active buffers
+ status_t resize(size_t size);
+
// ----------------------------------------------
// must be called from GL thread
@@ -170,6 +176,8 @@
TextureManager mTextureManager;
BufferManager mBufferManager;
+ // this lock protects mWidth and mHeight which are accessed from
+ // the main thread and requestBuffer's binder transaction thread.
mutable Mutex mLock;
uint32_t mWidth;
uint32_t mHeight;
diff --git a/libs/surfaceflinger/LayerBlur.cpp b/libs/surfaceflinger/LayerBlur.cpp
index 2d77876..09c90e8 100644
--- a/libs/surfaceflinger/LayerBlur.cpp
+++ b/libs/surfaceflinger/LayerBlur.cpp
@@ -95,7 +95,9 @@
mCacheDirty = false;
} else {
if (!mAutoRefreshPending) {
- mFlinger->signalDelayedEvent(ms2ns(500));
+ mFlinger->postMessageAsync(
+ new MessageBase(MessageQueue::INVALIDATE),
+ ms2ns(500));
mAutoRefreshPending = true;
}
}
diff --git a/libs/surfaceflinger/MessageQueue.cpp b/libs/surfaceflinger/MessageQueue.cpp
index b43d801..d668e88 100644
--- a/libs/surfaceflinger/MessageQueue.cpp
+++ b/libs/surfaceflinger/MessageQueue.cpp
@@ -60,9 +60,9 @@
{
}
-MessageList::value_type MessageQueue::waitMessage(nsecs_t timeout)
+sp<MessageBase> MessageQueue::waitMessage(nsecs_t timeout)
{
- MessageList::value_type result;
+ sp<MessageBase> result;
bool again;
do {
@@ -132,6 +132,7 @@
if (again) {
// the message has been processed. release our reference to it
// without holding the lock.
+ result->notify();
result = 0;
}
@@ -141,7 +142,7 @@
}
status_t MessageQueue::postMessage(
- const MessageList::value_type& message, nsecs_t relTime, uint32_t flags)
+ const sp<MessageBase>& message, nsecs_t relTime, uint32_t flags)
{
return queueMessage(message, relTime, flags);
}
@@ -154,7 +155,7 @@
}
status_t MessageQueue::queueMessage(
- const MessageList::value_type& message, nsecs_t relTime, uint32_t flags)
+ const sp<MessageBase>& message, nsecs_t relTime, uint32_t flags)
{
Mutex::Autolock _l(mLock);
message->when = systemTime() + relTime;
@@ -167,13 +168,13 @@
return NO_ERROR;
}
-void MessageQueue::dump(const MessageList::value_type& message)
+void MessageQueue::dump(const sp<MessageBase>& message)
{
Mutex::Autolock _l(mLock);
dumpLocked(message);
}
-void MessageQueue::dumpLocked(const MessageList::value_type& message)
+void MessageQueue::dumpLocked(const sp<MessageBase>& message)
{
LIST::const_iterator cur(mMessages.begin());
LIST::const_iterator end(mMessages.end());
diff --git a/libs/surfaceflinger/MessageQueue.h b/libs/surfaceflinger/MessageQueue.h
index dc8138d..890f809 100644
--- a/libs/surfaceflinger/MessageQueue.h
+++ b/libs/surfaceflinger/MessageQueue.h
@@ -25,6 +25,7 @@
#include <utils/Timers.h>
#include <utils/List.h>
+#include "Barrier.h"
namespace android {
@@ -37,7 +38,6 @@
List< sp<MessageBase> > mList;
typedef List< sp<MessageBase> > LIST;
public:
- typedef sp<MessageBase> value_type;
inline LIST::iterator begin() { return mList.begin(); }
inline LIST::const_iterator begin() const { return mList.begin(); }
inline LIST::iterator end() { return mList.end(); }
@@ -63,11 +63,19 @@
// return true if message has a handler
virtual bool handler() { return false; }
+
+ // waits for the handler to be processed
+ void wait() const { barrier.wait(); }
+ // releases all waiters. this is done automatically if
+ // handler returns true
+ void notify() const { barrier.open(); }
+
protected:
virtual ~MessageBase() { }
private:
+ mutable Barrier barrier;
friend class LightRefBase<MessageBase>;
};
@@ -82,42 +90,33 @@
typedef List< sp<MessageBase> > LIST;
public:
- // this is a work-around the multichar constant warning. A macro would
- // work too, but would pollute the namespace.
- template <int a, int b, int c, int d>
- struct WHAT {
- static const uint32_t Value =
- (uint32_t(a&0xff)<<24)|(uint32_t(b&0xff)<<16)|
- (uint32_t(c&0xff)<<8)|uint32_t(d&0xff);
- };
-
MessageQueue();
~MessageQueue();
// pre-defined messages
enum {
- INVALIDATE = WHAT<'_','p','d','t'>::Value
+ INVALIDATE = '_upd'
};
- MessageList::value_type waitMessage(nsecs_t timeout = -1);
+ sp<MessageBase> waitMessage(nsecs_t timeout = -1);
- status_t postMessage(const MessageList::value_type& message,
+ status_t postMessage(const sp<MessageBase>& message,
nsecs_t reltime=0, uint32_t flags = 0);
-
+
status_t invalidate();
- void dump(const MessageList::value_type& message);
+ void dump(const sp<MessageBase>& message);
private:
- status_t queueMessage(const MessageList::value_type& message,
+ status_t queueMessage(const sp<MessageBase>& message,
nsecs_t reltime, uint32_t flags);
- void dumpLocked(const MessageList::value_type& message);
+ void dumpLocked(const sp<MessageBase>& message);
Mutex mLock;
Condition mCondition;
MessageList mMessages;
bool mInvalidate;
- MessageList::value_type mInvalidateMessage;
+ sp<MessageBase> mInvalidateMessage;
};
// ---------------------------------------------------------------------------
diff --git a/libs/surfaceflinger/SurfaceFlinger.cpp b/libs/surfaceflinger/SurfaceFlinger.cpp
index 62d829b..5a6893f 100644
--- a/libs/surfaceflinger/SurfaceFlinger.cpp
+++ b/libs/surfaceflinger/SurfaceFlinger.cpp
@@ -426,7 +426,7 @@
timeout = waitTime>0 ? waitTime : 0;
}
- MessageList::value_type msg = mEventQueue.waitMessage(timeout);
+ sp<MessageBase> msg = mEventQueue.waitMessage(timeout);
// see if we timed out
if (isFrozen()) {
@@ -461,9 +461,20 @@
const_cast<SurfaceFlinger*>(this)->signalEvent();
}
-void SurfaceFlinger::signalDelayedEvent(nsecs_t delay)
+status_t SurfaceFlinger::postMessageAsync(const sp<MessageBase>& msg,
+ nsecs_t reltime, uint32_t flags)
{
- mEventQueue.postMessage( new MessageBase(MessageQueue::INVALIDATE), delay);
+ return mEventQueue.postMessage(msg, reltime, flags);
+}
+
+status_t SurfaceFlinger::postMessageSync(const sp<MessageBase>& msg,
+ nsecs_t reltime, uint32_t flags)
+{
+ status_t res = mEventQueue.postMessage(msg, reltime, flags);
+ if (res == NO_ERROR) {
+ msg->wait();
+ }
+ return res;
}
// ----------------------------------------------------------------------------
@@ -1135,15 +1146,11 @@
return android_atomic_and(~flags, &mTransactionFlags) & flags;
}
-uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags, nsecs_t delay)
+uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags)
{
uint32_t old = android_atomic_or(flags, &mTransactionFlags);
if ((old & flags)==0) { // wake the server up
- if (delay > 0) {
- signalDelayedEvent(delay);
- } else {
- signalEvent();
- }
+ signalEvent();
}
return old;
}
@@ -1245,7 +1252,7 @@
//LOGD("createSurface for pid %d (%d x %d)", pid, w, h);
int32_t id = client->generateId(pid);
- if (uint32_t(id) >= NUM_LAYERS_MAX) {
+ if (uint32_t(id) >= SharedBufferStack::NUM_LAYERS_MAX) {
LOGE("createSurface() failed, generateId = %d", id);
return surfaceHandle;
}
@@ -1399,7 +1406,7 @@
}
};
- mEventQueue.postMessage( new MessageDestroySurface(this, layer) );
+ postMessageAsync( new MessageDestroySurface(this, layer) );
return NO_ERROR;
}
@@ -1672,7 +1679,7 @@
int32_t Client::generateId(int pid)
{
const uint32_t i = clz( ~mBitmap );
- if (i >= NUM_LAYERS_MAX) {
+ if (i >= SharedBufferStack::NUM_LAYERS_MAX) {
return NO_MEMORY;
}
mPid = pid;
@@ -1699,7 +1706,8 @@
}
bool Client::isValid(int32_t i) const {
- return (uint32_t(i)<NUM_LAYERS_MAX) && (mBitmap & (1<<(31-i)));
+ return (uint32_t(i)<SharedBufferStack::NUM_LAYERS_MAX) &&
+ (mBitmap & (1<<(31-i)));
}
sp<LayerBaseClient> Client::getLayerUser(int32_t i) const {
diff --git a/libs/surfaceflinger/SurfaceFlinger.h b/libs/surfaceflinger/SurfaceFlinger.h
index 9c8de51..2558324 100644
--- a/libs/surfaceflinger/SurfaceFlinger.h
+++ b/libs/surfaceflinger/SurfaceFlinger.h
@@ -255,8 +255,6 @@
public: // hack to work around gcc 4.0.3 bug
void signalEvent();
private:
- void signalDelayedEvent(nsecs_t delay);
-
void handleConsoleEvents();
void handleTransaction(uint32_t transactionFlags);
void handleTransactionLocked(
@@ -286,7 +284,7 @@
void free_resources_l();
uint32_t getTransactionFlags(uint32_t flags);
- uint32_t setTransactionFlags(uint32_t flags, nsecs_t delay = 0);
+ uint32_t setTransactionFlags(uint32_t flags);
void commitTransaction();
@@ -310,7 +308,12 @@
mutable MessageQueue mEventQueue;
-
+
+ status_t postMessageAsync(const sp<MessageBase>& msg,
+ nsecs_t reltime=0, uint32_t flags = 0);
+
+ status_t postMessageSync(const sp<MessageBase>& msg,
+ nsecs_t reltime=0, uint32_t flags = 0);
// access must be protected by mStateLock
diff --git a/libs/surfaceflinger/TextureManager.cpp b/libs/surfaceflinger/TextureManager.cpp
index e5d5302..ee2159b 100644
--- a/libs/surfaceflinger/TextureManager.cpp
+++ b/libs/surfaceflinger/TextureManager.cpp
@@ -68,7 +68,7 @@
return false;
}
-status_t TextureManager::initEglImage(Texture* texture,
+status_t TextureManager::initEglImage(Image* texture,
EGLDisplay dpy, const sp<GraphicBuffer>& buffer)
{
status_t err = NO_ERROR;
@@ -108,7 +108,6 @@
err = INVALID_OPERATION;
} else {
// Everything went okay!
- texture->NPOTAdjust = false;
texture->dirty = false;
texture->width = clientBuf->width;
texture->height = clientBuf->height;
diff --git a/libs/surfaceflinger/TextureManager.h b/libs/surfaceflinger/TextureManager.h
index 90cb62b..d0acfe9 100644
--- a/libs/surfaceflinger/TextureManager.h
+++ b/libs/surfaceflinger/TextureManager.h
@@ -36,21 +36,24 @@
// ---------------------------------------------------------------------------
-struct Texture {
- Texture() : name(-1U), width(0), height(0),
- image(EGL_NO_IMAGE_KHR), transform(0),
- NPOTAdjust(false), dirty(true) { }
+struct Image {
+ Image() : name(-1U), image(EGL_NO_IMAGE_KHR), width(0), height(0),
+ transform(0), dirty(true) { }
GLuint name;
+ EGLImageKHR image;
GLuint width;
GLuint height;
+ uint32_t transform;
+ bool dirty;
+};
+
+struct Texture : public Image {
+ Texture() : Image(), NPOTAdjust(false) { }
GLuint potWidth;
GLuint potHeight;
GLfloat wScale;
GLfloat hScale;
- EGLImageKHR image;
- uint32_t transform;
bool NPOTAdjust;
- bool dirty;
};
// ---------------------------------------------------------------------------
@@ -68,7 +71,7 @@
const Region& dirty, const GGLSurface& t);
// make active buffer an EGLImage if needed
- status_t initEglImage(Texture* texture,
+ status_t initEglImage(Image* texture,
EGLDisplay dpy, const sp<GraphicBuffer>& buffer);
};
diff --git a/libs/surfaceflinger_client/SharedBufferStack.cpp b/libs/surfaceflinger_client/SharedBufferStack.cpp
index dab8ed8..e2e1591 100644
--- a/libs/surfaceflinger_client/SharedBufferStack.cpp
+++ b/libs/surfaceflinger_client/SharedBufferStack.cpp
@@ -44,7 +44,7 @@
// these functions are used by the clients
status_t SharedClient::validate(size_t i) const {
- if (uint32_t(i) >= uint32_t(NUM_LAYERS_MAX))
+ if (uint32_t(i) >= uint32_t(SharedBufferStack::NUM_LAYERS_MAX))
return BAD_INDEX;
return surfaces[i].status;
}
@@ -144,10 +144,10 @@
// ----------------------------------------------------------------------------
SharedBufferBase::SharedBufferBase(SharedClient* sharedClient,
- int surface, int num, int32_t identity)
+ int surface, int32_t identity)
: mSharedClient(sharedClient),
mSharedStack(sharedClient->surfaces + surface),
- mNumBuffers(num), mIdentity(identity)
+ mIdentity(identity)
{
}
@@ -179,34 +179,16 @@
char buffer[SIZE];
String8 result;
SharedBufferStack& stack( *mSharedStack );
- int tail = computeTail();
snprintf(buffer, SIZE,
- "%s[ head=%2d, available=%2d, queued=%2d, tail=%2d ] "
+ "%s[ head=%2d, available=%2d, queued=%2d ] "
"reallocMask=%08x, inUse=%2d, identity=%d, status=%d",
- prefix, stack.head, stack.available, stack.queued, tail,
+ prefix, stack.head, stack.available, stack.queued,
stack.reallocMask, stack.inUse, stack.identity, stack.status);
result.append(buffer);
-
- snprintf(buffer, SIZE, " { ");
- result.append(buffer);
-
- for (int i=0 ; i<mNumBuffers ; i++) {
- snprintf(buffer, SIZE, "%d ", stack.index[i]);
- result.append(buffer);
- }
-
- snprintf(buffer, SIZE, " }\n");
- result.append(buffer);
-
+ result.append("\n");
return result;
}
-int32_t SharedBufferBase::computeTail() const
-{
- SharedBufferStack& stack( *mSharedStack );
- return (mNumBuffers + stack.head - stack.available + 1) % mNumBuffers;
-}
-
status_t SharedBufferBase::waitForCondition(const ConditionBase& condition)
{
const SharedBufferStack& stack( *mSharedStack );
@@ -270,7 +252,7 @@
}
bool SharedBufferServer::ReallocateCondition::operator()() const {
int32_t head = stack.head;
- if (uint32_t(head) >= NUM_BUFFER_MAX) {
+ if (uint32_t(head) >= SharedBufferStack::NUM_BUFFER_MAX) {
// if stack.head is messed up, we cannot allow the server to
// crash (since stack.head is mapped on the client side)
stack.status = BAD_VALUE;
@@ -318,7 +300,7 @@
}
ssize_t SharedBufferServer::RetireUpdate::operator()() {
int32_t head = stack.head;
- if (uint32_t(head) >= NUM_BUFFER_MAX)
+ if (uint32_t(head) >= SharedBufferStack::NUM_BUFFER_MAX)
return BAD_VALUE;
// Preventively lock the current buffer before updating queued.
@@ -361,14 +343,20 @@
SharedBufferClient::SharedBufferClient(SharedClient* sharedClient,
int surface, int num, int32_t identity)
- : SharedBufferBase(sharedClient, surface, num, identity),
- tail(0), undoDequeueTail(0)
+ : SharedBufferBase(sharedClient, surface, identity),
+ mNumBuffers(num), tail(0), undoDequeueTail(0)
{
SharedBufferStack& stack( *mSharedStack );
tail = computeTail();
queued_head = stack.head;
}
+int32_t SharedBufferClient::computeTail() const
+{
+ SharedBufferStack& stack( *mSharedStack );
+ return (mNumBuffers + stack.head - stack.available + 1) % mNumBuffers;
+}
+
ssize_t SharedBufferClient::dequeue()
{
SharedBufferStack& stack( *mSharedStack );
@@ -377,7 +365,9 @@
LOGW("dequeue: tail=%d, head=%d, avail=%d, queued=%d",
tail, stack.head, stack.available, stack.queued);
}
-
+
+ RWLock::AutoRLock _rd(mLock);
+
const nsecs_t dequeueTime = systemTime(SYSTEM_TIME_THREAD);
//LOGD("[%d] about to dequeue a buffer",
@@ -407,6 +397,8 @@
status_t SharedBufferClient::undoDequeue(int buf)
{
+ RWLock::AutoRLock _rd(mLock);
+
// TODO: we can only undo the previous dequeue, we should
// enforce that in the api
UndoDequeueUpdate update(this);
@@ -419,6 +411,8 @@
status_t SharedBufferClient::lock(int buf)
{
+ RWLock::AutoRLock _rd(mLock);
+
SharedBufferStack& stack( *mSharedStack );
LockCondition condition(this, buf);
status_t err = waitForCondition(condition);
@@ -427,6 +421,8 @@
status_t SharedBufferClient::queue(int buf)
{
+ RWLock::AutoRLock _rd(mLock);
+
SharedBufferStack& stack( *mSharedStack );
queued_head = (queued_head + 1) % mNumBuffers;
@@ -460,21 +456,32 @@
return stack.setDirtyRegion(buf, reg);
}
-status_t SharedBufferClient::setBufferCount(int bufferCount)
+status_t SharedBufferClient::setBufferCount(
+ int bufferCount, const SetBufferCountCallback& ipc)
{
SharedBufferStack& stack( *mSharedStack );
- if (uint32_t(bufferCount) >= NUM_BUFFER_MAX)
+ if (uint32_t(bufferCount) >= SharedBufferStack::NUM_BUFFER_MAX)
return BAD_VALUE;
- mNumBuffers = bufferCount;
- queued_head = (stack.head + stack.queued) % mNumBuffers;
- return NO_ERROR;
+
+ if (uint32_t(bufferCount) < SharedBufferStack::NUM_BUFFER_MIN)
+ return BAD_VALUE;
+
+ RWLock::AutoWLock _wr(mLock);
+
+ status_t err = ipc(bufferCount);
+ if (err == NO_ERROR) {
+ mNumBuffers = bufferCount;
+ queued_head = (stack.head + stack.queued) % mNumBuffers;
+ }
+ return err;
}
// ----------------------------------------------------------------------------
SharedBufferServer::SharedBufferServer(SharedClient* sharedClient,
int surface, int num, int32_t identity)
- : SharedBufferBase(sharedClient, surface, num, identity)
+ : SharedBufferBase(sharedClient, surface, identity),
+ mNumBuffers(num)
{
mSharedStack->init(identity);
mSharedStack->head = num-1;
@@ -490,10 +497,12 @@
ssize_t SharedBufferServer::retireAndLock()
{
+ RWLock::AutoRLock _l(mLock);
+
RetireUpdate update(this, mNumBuffers);
ssize_t buf = updateCondition( update );
if (buf >= 0) {
- if (uint32_t(buf) >= NUM_BUFFER_MAX)
+ if (uint32_t(buf) >= SharedBufferStack::NUM_BUFFER_MAX)
return BAD_VALUE;
SharedBufferStack& stack( *mSharedStack );
buf = stack.index[buf];
@@ -520,6 +529,8 @@
status_t SharedBufferServer::reallocate()
{
+ RWLock::AutoRLock _l(mLock);
+
SharedBufferStack& stack( *mSharedStack );
uint32_t mask = (1<<mNumBuffers)-1;
android_atomic_or(mask, &stack.reallocMask);
@@ -534,6 +545,13 @@
status_t SharedBufferServer::assertReallocate(int buf)
{
+ /*
+ * NOTE: it's safe to hold mLock for read while waiting for
+ * the ReallocateCondition because that condition is not updated
+ * by the thread that holds mLock for write.
+ */
+ RWLock::AutoRLock _l(mLock);
+
// TODO: need to validate "buf"
ReallocateCondition condition(this, buf);
status_t err = waitForCondition(condition);
@@ -546,9 +564,7 @@
return stack.getDirtyRegion(buf);
}
-
/*
- *
* NOTE: this is not thread-safe on the server-side, meaning
* 'head' cannot move during this operation. The client-side
* can safely operate an usual.
@@ -556,9 +572,11 @@
*/
status_t SharedBufferServer::resize(int newNumBuffers)
{
- if (uint32_t(newNumBuffers) >= NUM_BUFFER_MAX)
+ if (uint32_t(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)
@@ -569,7 +587,7 @@
// read the head, make sure it's valid
int32_t head = stack.head;
- if (uint32_t(head) >= NUM_BUFFER_MAX)
+ if (uint32_t(head) >= SharedBufferStack::NUM_BUFFER_MAX)
return BAD_VALUE;
int base = numBuffers;
diff --git a/libs/surfaceflinger_client/Surface.cpp b/libs/surfaceflinger_client/Surface.cpp
index afbeafb..5f42af0 100644
--- a/libs/surfaceflinger_client/Surface.cpp
+++ b/libs/surfaceflinger_client/Surface.cpp
@@ -584,6 +584,9 @@
case NATIVE_WINDOW_SET_CROP:
res = dispatch_crop( args );
break;
+ case NATIVE_WINDOW_SET_BUFFER_COUNT:
+ res = dispatch_set_buffer_count( args );
+ break;
default:
res = NAME_NOT_FOUND;
break;
@@ -607,6 +610,10 @@
android_native_rect_t const* rect = va_arg(args, android_native_rect_t*);
return crop( reinterpret_cast<Rect const*>(rect) );
}
+int Surface::dispatch_set_buffer_count(va_list args) {
+ size_t bufferCount = va_arg(args, size_t);
+ return setBufferCount(bufferCount);
+}
void Surface::setUsage(uint32_t reqUsage)
@@ -678,19 +685,18 @@
sp<ISurface> s(mSurface);
if (s == 0) return NO_INIT;
- // FIXME: this needs to be synchronized dequeue/queue
+ class SetBufferCountIPC : public SharedBufferClient::SetBufferCountCallback {
+ sp<ISurface> surface;
+ virtual status_t operator()(int bufferCount) const {
+ return surface->setBufferCount(bufferCount);
+ }
+ public:
+ SetBufferCountIPC(const sp<ISurface>& surface) : surface(surface) { }
+ } ipc(s);
- status_t err = s->setBufferCount(bufferCount);
+ status_t err = mSharedBufferClient->setBufferCount(bufferCount, ipc);
LOGE_IF(err, "ISurface::setBufferCount(%d) returned %s",
bufferCount, strerror(-err));
- if (err == NO_ERROR) {
- err = mSharedBufferClient->getStatus();
- LOGE_IF(err, "Surface (identity=%d) state = %d", mIdentity, err);
- if (!err) {
- // update our local copy of the buffer count
- mSharedBufferClient->setBufferCount(bufferCount);
- }
- }
return err;
}
@@ -857,7 +863,7 @@
currentBuffer->setIndex(index);
}
} else {
- err = err<0 ? err : NO_MEMORY;
+ err = err<0 ? err : status_t(NO_MEMORY);
}
}
return err;
diff --git a/libs/surfaceflinger_client/SurfaceComposerClient.cpp b/libs/surfaceflinger_client/SurfaceComposerClient.cpp
index 85167da..9ac73d2 100644
--- a/libs/surfaceflinger_client/SurfaceComposerClient.cpp
+++ b/libs/surfaceflinger_client/SurfaceComposerClient.cpp
@@ -250,7 +250,7 @@
status_t SurfaceComposerClient::getDisplayInfo(
DisplayID dpy, DisplayInfo* info)
{
- if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
+ if (uint32_t(dpy)>=SharedBufferStack::NUM_DISPLAY_MAX)
return BAD_VALUE;
volatile surface_flinger_cblk_t const * cblk = get_cblk();
@@ -268,7 +268,7 @@
ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy)
{
- if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
+ if (uint32_t(dpy)>=SharedBufferStack::NUM_DISPLAY_MAX)
return BAD_VALUE;
volatile surface_flinger_cblk_t const * cblk = get_cblk();
volatile display_cblk_t const * dcblk = cblk->displays + dpy;
@@ -277,7 +277,7 @@
ssize_t SurfaceComposerClient::getDisplayHeight(DisplayID dpy)
{
- if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
+ if (uint32_t(dpy)>=SharedBufferStack::NUM_DISPLAY_MAX)
return BAD_VALUE;
volatile surface_flinger_cblk_t const * cblk = get_cblk();
volatile display_cblk_t const * dcblk = cblk->displays + dpy;
@@ -286,7 +286,7 @@
ssize_t SurfaceComposerClient::getDisplayOrientation(DisplayID dpy)
{
- if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
+ if (uint32_t(dpy)>=SharedBufferStack::NUM_DISPLAY_MAX)
return BAD_VALUE;
volatile surface_flinger_cblk_t const * cblk = get_cblk();
volatile display_cblk_t const * dcblk = cblk->displays + dpy;
@@ -345,7 +345,7 @@
sp<ISurface> surface = mClient->createSurface(&data, pid, name,
display, w, h, format, flags);
if (surface != 0) {
- if (uint32_t(data.token) < NUM_LAYERS_MAX) {
+ if (uint32_t(data.token) < SharedBufferStack::NUM_LAYERS_MAX) {
result = new SurfaceControl(this, surface, data, w, h, format, flags);
}
}
diff --git a/libs/surfaceflinger_client/tests/SharedBufferStack/SharedBufferStackTest.cpp b/libs/surfaceflinger_client/tests/SharedBufferStack/SharedBufferStackTest.cpp
index f490a65..f409f48 100644
--- a/libs/surfaceflinger_client/tests/SharedBufferStack/SharedBufferStackTest.cpp
+++ b/libs/surfaceflinger_client/tests/SharedBufferStack/SharedBufferStackTest.cpp
@@ -54,8 +54,16 @@
printf("resize test\n");
- s.resize(6);
- c.setBufferCount(6);
+ class SetBufferCountIPC : public SharedBufferClient::SetBufferCountCallback {
+ SharedBufferServer& s;
+ virtual status_t operator()(int bufferCount) const {
+ return s.resize(bufferCount);
+ }
+ public:
+ SetBufferCountIPC(SharedBufferServer& s) : s(s) { }
+ } resize(s);
+
+ c.setBufferCount(6, resize);
int list3[6] = {3, 2, 1, 4, 5, 0};
test0(s, c, 6, list3);
diff --git a/location/java/android/location/provider/GeocodeProvider.java b/location/java/android/location/provider/GeocodeProvider.java
index db5c078..9a58763 100644
--- a/location/java/android/location/provider/GeocodeProvider.java
+++ b/location/java/android/location/provider/GeocodeProvider.java
@@ -51,7 +51,7 @@
/**
* This method is overridden to implement the
- * {@link Geocoder#getFromLocation(double, double, int)} method.
+ * {@link android.location.Geocoder#getFromLocation(double, double, int)} method.
* Classes implementing this method should not hold a reference to the params parameter.
*/
public abstract String onGetFromLocation(double latitude, double longitude, int maxResults,
@@ -59,7 +59,7 @@
/**
* This method is overridden to implement the
- * {@link Geocoder#getFromLocationName(String, int, double, double, double, double)} method.
+ * {@link android.location.Geocoder#getFromLocationName(String, int, double, double, double, double)} method.
* Classes implementing this method should not hold a reference to the params parameter.
*/
public abstract String onGetFromLocationName(String locationName,
diff --git a/location/java/android/location/provider/LocationProvider.java b/location/java/android/location/provider/LocationProvider.java
index 5771363..cf939de 100644
--- a/location/java/android/location/provider/LocationProvider.java
+++ b/location/java/android/location/provider/LocationProvider.java
@@ -255,11 +255,11 @@
/**
* Returns a information on the status of this provider.
- * {@link #OUT_OF_SERVICE} is returned if the provider is
+ * {@link android.location.LocationProvider#OUT_OF_SERVICE} is returned if the provider is
* out of service, and this is not expected to change in the near
- * future; {@link #TEMPORARILY_UNAVAILABLE} is returned if
+ * future; {@link android.location.LocationProvider#TEMPORARILY_UNAVAILABLE} is returned if
* the provider is temporarily unavailable but is expected to be
- * available shortly; and {@link #AVAILABLE} is returned
+ * available shortly; and {@link android.location.LocationProvider#AVAILABLE} is returned
* if the provider is currently available.
*
* <p> If extras is non-null, additional status information may be
@@ -308,9 +308,9 @@
/**
* Updates the network state for the given provider. This function must
- * be overwritten if {@link #requiresNetwork} returns true. The state is
- * {@link #TEMPORARILY_UNAVAILABLE} (disconnected), OR {@link #AVAILABLE}
- * (connected or connecting).
+ * be overwritten if {@link android.location.LocationProvider#requiresNetwork} returns true.
+ * The state is {@link android.location.LocationProvider#TEMPORARILY_UNAVAILABLE} (disconnected)
+ * OR {@link android.location.LocationProvider#AVAILABLE} (connected or connecting).
*
* @param state data state
*/
diff --git a/media/libmediaplayerservice/StagefrightRecorder.cpp b/media/libmediaplayerservice/StagefrightRecorder.cpp
index de64714..572389f 100644
--- a/media/libmediaplayerservice/StagefrightRecorder.cpp
+++ b/media/libmediaplayerservice/StagefrightRecorder.cpp
@@ -701,6 +701,7 @@
mSampleRate = 8000;
mAudioChannels = 1;
mAudioBitRate = 12200;
+ mInterleaveDurationUs = 0;
mOutputFd = -1;
mFlags = 0;
diff --git a/media/libstagefright/FileSource.cpp b/media/libstagefright/FileSource.cpp
index b6f1af2..dd2579b 100644
--- a/media/libstagefright/FileSource.cpp
+++ b/media/libstagefright/FileSource.cpp
@@ -45,6 +45,10 @@
}
ssize_t FileSource::readAt(off_t offset, void *data, size_t size) {
+ if (mFile == NULL) {
+ return NO_INIT;
+ }
+
Mutex::Autolock autoLock(mLock);
if (mLength >= 0) {
@@ -67,6 +71,10 @@
}
status_t FileSource::getSize(off_t *size) {
+ if (mFile == NULL) {
+ return NO_INIT;
+ }
+
if (mLength >= 0) {
*size = mLength;
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index 094059d..e0f8f9e 100644
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -334,8 +334,6 @@
}
off_t MPEG4Writer::addLengthPrefixedSample_l(MediaBuffer *buffer) {
- StripStartcode(buffer);
-
off_t old_offset = mOffset;
size_t length = buffer->range_length();
@@ -827,6 +825,8 @@
continue;
}
+ if (is_avc) StripStartcode(buffer);
+
SampleInfo info;
info.size = is_avc
#if USE_NALLEN_FOUR
diff --git a/services/java/com/android/server/location/GpsLocationProvider.java b/services/java/com/android/server/location/GpsLocationProvider.java
index 6fe02c2..0cf67a3 100755
--- a/services/java/com/android/server/location/GpsLocationProvider.java
+++ b/services/java/com/android/server/location/GpsLocationProvider.java
@@ -1173,7 +1173,8 @@
}
}
- updateStatus(mStatus, svCount);
+ // return number of sets used in fix instead of total
+ updateStatus(mStatus, Integer.bitCount(mSvMasks[USED_FOR_FIX_MASK]));
if (mNavigating && mStatus == LocationProvider.AVAILABLE && mLastFixTime > 0 &&
System.currentTimeMillis() - mLastFixTime > RECENT_FIX_TIMEOUT) {
diff --git a/services/java/com/android/server/status/StatusBarIcon.java b/services/java/com/android/server/status/StatusBarIcon.java
index 6f8b8a8..f77b550 100644
--- a/services/java/com/android/server/status/StatusBarIcon.java
+++ b/services/java/com/android/server/status/StatusBarIcon.java
@@ -51,14 +51,11 @@
switch (data.type) {
case IconData.TEXT: {
TextView t;
- t = new TextView(context);
+ t = new TextView(context, null, com.android.internal.R.style.TextAppearance_StatusBar_Icon);
mTextView = t;
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT);
- t.setTextSize(16);
- t.setTextColor(0xff000000);
- t.setTypeface(Typeface.DEFAULT_BOLD);
t.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
t.setPadding(6, 0, 0, 0);
t.setLayoutParams(layoutParams);
diff --git a/services/java/com/android/server/status/StatusBarPolicy.java b/services/java/com/android/server/status/StatusBarPolicy.java
index 35ccfe8..cab2662 100644
--- a/services/java/com/android/server/status/StatusBarPolicy.java
+++ b/services/java/com/android/server/status/StatusBarPolicy.java
@@ -29,6 +29,7 @@
import android.content.IntentFilter;
import android.content.res.TypedArray;
import android.graphics.PixelFormat;
+import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.location.LocationManager;
import android.media.AudioManager;
@@ -49,7 +50,10 @@
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.text.format.DateFormat;
+import android.text.style.CharacterStyle;
import android.text.style.RelativeSizeSpan;
+import android.text.style.ForegroundColorSpan;
+import android.text.style.StyleSpan;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.util.Slog;
@@ -86,6 +90,12 @@
// message codes for the handler
private static final int EVENT_BATTERY_CLOSE = 4;
+ private static final int AM_PM_STYLE_NORMAL = 0;
+ private static final int AM_PM_STYLE_SMALL = 1;
+ private static final int AM_PM_STYLE_GONE = 2;
+
+ private static final int AM_PM_STYLE = AM_PM_STYLE_GONE;
+
private final Context mContext;
private final StatusBarService mService;
private final Handler mHandler = new StatusBarHandler();
@@ -576,31 +586,33 @@
* add dummy characters around it to let us find it again after
* formatting and change its size.
*/
- int a = -1;
- boolean quoted = false;
- for (int i = 0; i < format.length(); i++) {
- char c = format.charAt(i);
+ if (AM_PM_STYLE != AM_PM_STYLE_NORMAL) {
+ int a = -1;
+ boolean quoted = false;
+ for (int i = 0; i < format.length(); i++) {
+ char c = format.charAt(i);
- if (c == '\'') {
- quoted = !quoted;
+ if (c == '\'') {
+ quoted = !quoted;
+ }
+
+ if (!quoted && c == 'a') {
+ a = i;
+ break;
+ }
}
- if (!quoted && c == 'a') {
- a = i;
- break;
+ if (a >= 0) {
+ // Move a back so any whitespace before the AM/PM is also in the alternate size.
+ final int b = a;
+ while (a > 0 && Character.isWhitespace(format.charAt(a-1))) {
+ a--;
+ }
+ format = format.substring(0, a) + MAGIC1 + format.substring(a, b)
+ + "a" + MAGIC2 + format.substring(b + 1);
}
}
- if (a >= 0) {
- // Move a back so any whitespace before the AM/PM is also in the alternate size.
- final int b = a;
- while (a > 0 && Character.isWhitespace(format.charAt(a-1))) {
- a--;
- }
- format = format.substring(0, a) + MAGIC1 + format.substring(a, b)
- + "a" + MAGIC2 + format.substring(b + 1);
- }
-
mClockFormat = sdf = new SimpleDateFormat(format);
mClockFormatString = format;
} else {
@@ -608,22 +620,31 @@
}
String result = sdf.format(mCalendar.getTime());
- int magic1 = result.indexOf(MAGIC1);
- int magic2 = result.indexOf(MAGIC2);
+ if (AM_PM_STYLE != AM_PM_STYLE_NORMAL) {
+ int magic1 = result.indexOf(MAGIC1);
+ int magic2 = result.indexOf(MAGIC2);
- if (magic1 >= 0 && magic2 > magic1) {
- SpannableStringBuilder formatted = new SpannableStringBuilder(result);
+ if (magic1 >= 0 && magic2 > magic1) {
+ SpannableStringBuilder formatted = new SpannableStringBuilder(result);
- formatted.setSpan(new RelativeSizeSpan(0.7f), magic1, magic2,
- Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
+ if (AM_PM_STYLE == AM_PM_STYLE_GONE) {
+ formatted.delete(magic1, magic2+1);
+ } else {
+ if (AM_PM_STYLE == AM_PM_STYLE_SMALL) {
+ CharacterStyle style = new RelativeSizeSpan(0.7f);
+ formatted.setSpan(style, magic1, magic2,
+ Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
+ }
- formatted.delete(magic2, magic2 + 1);
- formatted.delete(magic1, magic1 + 1);
+ formatted.delete(magic2, magic2 + 1);
+ formatted.delete(magic1, magic1 + 1);
+ }
- return formatted;
- } else {
- return result;
+ return formatted;
+ }
}
+
+ return result;
}
private final void updateClock() {