ISurfaceComposerClient.cpp revision 99ed22412db547c59d3da08114d9d5a586442b30
1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17// tag as surfaceflinger 18#define LOG_TAG "SurfaceFlinger" 19 20#include <stdio.h> 21#include <stdint.h> 22#include <sys/types.h> 23 24#include <binder/Parcel.h> 25#include <binder/IMemory.h> 26#include <binder/IPCThreadState.h> 27#include <binder/IServiceManager.h> 28 29#include <ui/Point.h> 30#include <ui/Rect.h> 31 32#include <surfaceflinger/ISurface.h> 33#include <surfaceflinger/ISurfaceComposerClient.h> 34#include <private/surfaceflinger/LayerState.h> 35 36// --------------------------------------------------------------------------- 37 38/* ideally AID_GRAPHICS would be in a semi-public header 39 * or there would be a way to map a user/group name to its id 40 */ 41#ifndef AID_GRAPHICS 42#define AID_GRAPHICS 1003 43#endif 44 45// --------------------------------------------------------------------------- 46 47namespace android { 48 49enum { 50 CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION, 51 DESTROY_SURFACE 52}; 53 54class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient> 55{ 56public: 57 BpSurfaceComposerClient(const sp<IBinder>& impl) 58 : BpInterface<ISurfaceComposerClient>(impl) 59 { 60 } 61 62 virtual sp<ISurface> createSurface( surface_data_t* params, 63 const String8& name, 64 DisplayID display, 65 uint32_t w, 66 uint32_t h, 67 PixelFormat format, 68 uint32_t flags) 69 { 70 Parcel data, reply; 71 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); 72 data.writeString8(name); 73 data.writeInt32(display); 74 data.writeInt32(w); 75 data.writeInt32(h); 76 data.writeInt32(format); 77 data.writeInt32(flags); 78 remote()->transact(CREATE_SURFACE, data, &reply); 79 params->readFromParcel(reply); 80 return interface_cast<ISurface>(reply.readStrongBinder()); 81 } 82 83 virtual status_t destroySurface(SurfaceID sid) 84 { 85 Parcel data, reply; 86 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); 87 data.writeInt32(sid); 88 remote()->transact(DESTROY_SURFACE, data, &reply); 89 return reply.readInt32(); 90 } 91}; 92 93IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient"); 94 95// ---------------------------------------------------------------------- 96 97status_t BnSurfaceComposerClient::onTransact( 98 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 99{ 100 switch(code) { 101 case CREATE_SURFACE: { 102 CHECK_INTERFACE(ISurfaceComposerClient, data, reply); 103 surface_data_t params; 104 String8 name = data.readString8(); 105 DisplayID display = data.readInt32(); 106 uint32_t w = data.readInt32(); 107 uint32_t h = data.readInt32(); 108 PixelFormat format = data.readInt32(); 109 uint32_t flags = data.readInt32(); 110 sp<ISurface> s = createSurface(¶ms, name, display, w, h, 111 format, flags); 112 params.writeToParcel(reply); 113 reply->writeStrongBinder(s->asBinder()); 114 return NO_ERROR; 115 } break; 116 case DESTROY_SURFACE: { 117 CHECK_INTERFACE(ISurfaceComposerClient, data, reply); 118 reply->writeInt32( destroySurface( data.readInt32() ) ); 119 return NO_ERROR; 120 } break; 121 default: 122 return BBinder::onTransact(code, data, reply, flags); 123 } 124} 125 126// ---------------------------------------------------------------------- 127 128status_t ISurfaceComposerClient::surface_data_t::readFromParcel(const Parcel& parcel) 129{ 130 token = parcel.readInt32(); 131 identity = parcel.readInt32(); 132 return NO_ERROR; 133} 134 135status_t ISurfaceComposerClient::surface_data_t::writeToParcel(Parcel* parcel) const 136{ 137 parcel->writeInt32(token); 138 parcel->writeInt32(identity); 139 return NO_ERROR; 140} 141 142}; // namespace android 143