summaryrefslogtreecommitdiffstats
path: root/libs/gui
diff options
context:
space:
mode:
authorDan Stoza <stoza@google.com>2015-06-05 15:01:58 -0700
committerDan Stoza <stoza@google.com>2015-06-05 15:01:58 -0700
commit107fbe5599016b0e35145a1a00c4f238b63d61e4 (patch)
treefea2c90086fdc3b5f76f13c66cdde8f7585ff3b9 /libs/gui
parent9d2c5a7c678bd384df0fb29952cf8943e7b1b160 (diff)
downloadframeworks_native-107fbe5599016b0e35145a1a00c4f238b63d61e4.zip
frameworks_native-107fbe5599016b0e35145a1a00c4f238b63d61e4.tar.gz
frameworks_native-107fbe5599016b0e35145a1a00c4f238b63d61e4.tar.bz2
libgui: Add getConsumerName
Adds a getConsumerName method to IGraphicBufferProducer and Surface. Currently, the name is cached inside of IGBP and is updated on connect and dequeueBuffer, which should be good enough for most uses. Bug: 6667401 Change-Id: Ife94bd89023fe7c00bad916932b9a19233fd2290
Diffstat (limited to 'libs/gui')
-rw-r--r--libs/gui/BufferQueueProducer.cpp6
-rw-r--r--libs/gui/IGraphicBufferProducer.cpp17
-rw-r--r--libs/gui/Surface.cpp4
-rw-r--r--libs/gui/tests/BufferQueue_test.cpp8
-rw-r--r--libs/gui/tests/DummyConsumer.h27
-rw-r--r--libs/gui/tests/Surface_test.cpp18
6 files changed, 74 insertions, 6 deletions
diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp
index 73d4261..38fb757 100644
--- a/libs/gui/BufferQueueProducer.cpp
+++ b/libs/gui/BufferQueueProducer.cpp
@@ -1089,6 +1089,12 @@ status_t BufferQueueProducer::setGenerationNumber(uint32_t generationNumber) {
return NO_ERROR;
}
+String8 BufferQueueProducer::getConsumerName() const {
+ ATRACE_CALL();
+ BQ_LOGV("getConsumerName: %s", mConsumerName.string());
+ return mConsumerName;
+}
+
void BufferQueueProducer::binderDied(const wp<android::IBinder>& /* who */) {
// If we're here, it means that a producer we were connected to died.
// We're guaranteed that we are still connected to it because we remove
diff --git a/libs/gui/IGraphicBufferProducer.cpp b/libs/gui/IGraphicBufferProducer.cpp
index cfe726b..d7a7885 100644
--- a/libs/gui/IGraphicBufferProducer.cpp
+++ b/libs/gui/IGraphicBufferProducer.cpp
@@ -48,6 +48,7 @@ enum {
ALLOCATE_BUFFERS,
ALLOW_ALLOCATION,
SET_GENERATION_NUMBER,
+ GET_CONSUMER_NAME,
};
class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer>
@@ -296,6 +297,17 @@ public:
}
return result;
}
+
+ virtual String8 getConsumerName() const {
+ Parcel data, reply;
+ data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
+ status_t result = remote()->transact(GET_CONSUMER_NAME, data, &reply);
+ if (result != NO_ERROR) {
+ ALOGE("getConsumerName failed to transact: %d", result);
+ return String8("TransactFailed");
+ }
+ return reply.readString8();
+ }
};
// Out-of-line virtual method definition to trigger vtable emission in this
@@ -467,6 +479,11 @@ status_t BnGraphicBufferProducer::onTransact(
reply->writeInt32(result);
return NO_ERROR;
}
+ case GET_CONSUMER_NAME: {
+ CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
+ reply->writeString8(getConsumerName());
+ return NO_ERROR;
+ }
}
return BBinder::onTransact(code, data, reply, flags);
}
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index aeb56e0..df0661c 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -111,6 +111,10 @@ status_t Surface::setGenerationNumber(uint32_t generation) {
return result;
}
+String8 Surface::getConsumerName() const {
+ return mGraphicBufferProducer->getConsumerName();
+}
+
int Surface::hook_setSwapInterval(ANativeWindow* window, int interval) {
Surface* c = getSelf(window);
return c->setSwapInterval(interval);
diff --git a/libs/gui/tests/BufferQueue_test.cpp b/libs/gui/tests/BufferQueue_test.cpp
index 3d1139d..1a54875 100644
--- a/libs/gui/tests/BufferQueue_test.cpp
+++ b/libs/gui/tests/BufferQueue_test.cpp
@@ -17,6 +17,8 @@
#define LOG_TAG "BufferQueue_test"
//#define LOG_NDEBUG 0
+#include "DummyConsumer.h"
+
#include <gui/BufferItem.h>
#include <gui/BufferQueue.h>
#include <gui/IProducerListener.h>
@@ -67,12 +69,6 @@ protected:
sp<IGraphicBufferConsumer> mConsumer;
};
-struct DummyConsumer : public BnConsumerListener {
- virtual void onFrameAvailable(const BufferItem& /* item */) {}
- virtual void onBuffersReleased() {}
- virtual void onSidebandStreamChanged() {}
-};
-
static const uint32_t TEST_DATA = 0x12345678u;
// XXX: Tests that fork a process to hold the BufferQueue must run before tests
diff --git a/libs/gui/tests/DummyConsumer.h b/libs/gui/tests/DummyConsumer.h
new file mode 100644
index 0000000..0511e16
--- /dev/null
+++ b/libs/gui/tests/DummyConsumer.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gui/IConsumerListener.h>
+
+namespace android {
+
+struct DummyConsumer : public BnConsumerListener {
+ virtual void onFrameAvailable(const BufferItem& /* item */) {}
+ virtual void onBuffersReleased() {}
+ virtual void onSidebandStreamChanged() {}
+};
+
+} // namespace android
diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp
index cf0043d..3f495f8 100644
--- a/libs/gui/tests/Surface_test.cpp
+++ b/libs/gui/tests/Surface_test.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include "DummyConsumer.h"
+
#include <gtest/gtest.h>
#include <binder/IMemory.h>
@@ -210,4 +212,20 @@ TEST_F(SurfaceTest, SettingGenerationNumber) {
ASSERT_EQ(1U, graphicBuffer->getGenerationNumber());
}
+TEST_F(SurfaceTest, GetConsumerName) {
+ sp<IGraphicBufferProducer> producer;
+ sp<IGraphicBufferConsumer> consumer;
+ BufferQueue::createBufferQueue(&producer, &consumer);
+
+ sp<DummyConsumer> dummyConsumer(new DummyConsumer);
+ consumer->consumerConnect(dummyConsumer, false);
+ consumer->setConsumerName(String8("TestConsumer"));
+
+ sp<Surface> surface = new Surface(producer);
+ sp<ANativeWindow> window(surface);
+ native_window_api_connect(window.get(), NATIVE_WINDOW_API_CPU);
+
+ EXPECT_STREQ("TestConsumer", surface->getConsumerName().string());
+}
+
}