2011-01-13 02:30:40 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// tag as surfaceflinger
|
|
|
|
#define LOG_TAG "SurfaceFlinger"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <binder/Parcel.h>
|
|
|
|
|
|
|
|
#include <ui/GraphicBuffer.h>
|
|
|
|
|
2012-02-26 02:48:35 +00:00
|
|
|
#include <gui/IGraphicBufferAlloc.h>
|
2011-01-13 02:30:40 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CREATE_GRAPHIC_BUFFER = IBinder::FIRST_CALL_TRANSACTION,
|
|
|
|
};
|
|
|
|
|
|
|
|
class BpGraphicBufferAlloc : public BpInterface<IGraphicBufferAlloc>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BpGraphicBufferAlloc(const sp<IBinder>& impl)
|
|
|
|
: BpInterface<IGraphicBufferAlloc>(impl)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-11-18 18:24:03 +00:00
|
|
|
virtual ~BpGraphicBufferAlloc();
|
|
|
|
|
|
|
|
virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t width,
|
|
|
|
uint32_t height, PixelFormat format, uint32_t usage,
|
|
|
|
status_t* error) {
|
2011-01-13 02:30:40 +00:00
|
|
|
Parcel data, reply;
|
2011-04-09 02:10:43 +00:00
|
|
|
data.writeInterfaceToken(IGraphicBufferAlloc::getInterfaceDescriptor());
|
2014-11-18 18:24:03 +00:00
|
|
|
data.writeUint32(width);
|
|
|
|
data.writeUint32(height);
|
|
|
|
data.writeInt32(static_cast<int32_t>(format));
|
|
|
|
data.writeUint32(usage);
|
2011-01-13 02:30:40 +00:00
|
|
|
remote()->transact(CREATE_GRAPHIC_BUFFER, data, &reply);
|
|
|
|
sp<GraphicBuffer> graphicBuffer;
|
2011-07-01 21:53:49 +00:00
|
|
|
status_t result = reply.readInt32();
|
|
|
|
if (result == NO_ERROR) {
|
2011-01-13 02:30:40 +00:00
|
|
|
graphicBuffer = new GraphicBuffer();
|
2012-08-30 20:28:23 +00:00
|
|
|
result = reply.read(*graphicBuffer);
|
2015-06-01 20:59:15 +00:00
|
|
|
if (result != NO_ERROR) {
|
|
|
|
graphicBuffer.clear();
|
|
|
|
}
|
2011-04-09 02:10:43 +00:00
|
|
|
// reply.readStrongBinder();
|
|
|
|
// here we don't even have to read the BufferReference from
|
|
|
|
// the parcel, it'll die with the parcel.
|
2011-01-13 02:30:40 +00:00
|
|
|
}
|
2011-07-01 21:53:49 +00:00
|
|
|
*error = result;
|
2011-01-13 02:30:40 +00:00
|
|
|
return graphicBuffer;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-11-18 18:24:03 +00:00
|
|
|
// Out-of-line virtual method definition to trigger vtable emission in this
|
|
|
|
// translation unit (see clang warning -Wweak-vtables)
|
|
|
|
BpGraphicBufferAlloc::~BpGraphicBufferAlloc() {}
|
|
|
|
|
2011-01-13 02:30:40 +00:00
|
|
|
IMPLEMENT_META_INTERFACE(GraphicBufferAlloc, "android.ui.IGraphicBufferAlloc");
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
status_t BnGraphicBufferAlloc::onTransact(
|
|
|
|
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
|
|
|
|
{
|
|
|
|
// codes that don't require permission check
|
|
|
|
|
2014-11-18 18:24:03 +00:00
|
|
|
// BufferReference just keeps a strong reference to a GraphicBuffer until it
|
|
|
|
// is destroyed (that is, until no local or remote process have a reference
|
|
|
|
// to it).
|
2011-04-09 02:10:43 +00:00
|
|
|
class BufferReference : public BBinder {
|
2014-11-18 18:24:03 +00:00
|
|
|
sp<GraphicBuffer> mBuffer;
|
2011-04-09 02:10:43 +00:00
|
|
|
public:
|
2014-11-18 18:24:03 +00:00
|
|
|
BufferReference(const sp<GraphicBuffer>& buffer) : mBuffer(buffer) {}
|
2011-04-09 02:10:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-11-18 18:24:03 +00:00
|
|
|
switch (code) {
|
2011-01-13 02:30:40 +00:00
|
|
|
case CREATE_GRAPHIC_BUFFER: {
|
|
|
|
CHECK_INTERFACE(IGraphicBufferAlloc, data, reply);
|
2014-11-18 18:24:03 +00:00
|
|
|
uint32_t width = data.readUint32();
|
|
|
|
uint32_t height = data.readUint32();
|
|
|
|
PixelFormat format = static_cast<PixelFormat>(data.readInt32());
|
|
|
|
uint32_t usage = data.readUint32();
|
2011-07-01 21:53:49 +00:00
|
|
|
status_t error;
|
|
|
|
sp<GraphicBuffer> result =
|
2014-11-18 18:24:03 +00:00
|
|
|
createGraphicBuffer(width, height, format, usage, &error);
|
2011-07-01 21:53:49 +00:00
|
|
|
reply->writeInt32(error);
|
2011-01-13 02:30:40 +00:00
|
|
|
if (result != 0) {
|
|
|
|
reply->write(*result);
|
2011-04-09 02:10:43 +00:00
|
|
|
// We add a BufferReference to this parcel to make sure the
|
|
|
|
// buffer stays alive until the GraphicBuffer object on
|
|
|
|
// the other side has been created.
|
|
|
|
// This is needed so that the buffer handle can be
|
|
|
|
// registered before the buffer is destroyed on implementations
|
|
|
|
// that do not use file-descriptors to track their buffers.
|
|
|
|
reply->writeStrongBinder( new BufferReference(result) );
|
2011-01-13 02:30:40 +00:00
|
|
|
}
|
|
|
|
return NO_ERROR;
|
2014-11-18 18:24:03 +00:00
|
|
|
}
|
2011-01-13 02:30:40 +00:00
|
|
|
default:
|
|
|
|
return BBinder::onTransact(code, data, reply, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}; // namespace android
|