ISurfaceComposerClient.cpp revision 1db13d79518f600d65a4fc006fe42900b890966e
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 38namespace android { 39 40enum { 41 CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION, 42 DESTROY_SURFACE 43}; 44 45class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient> 46{ 47public: 48 BpSurfaceComposerClient(const sp<IBinder>& impl) 49 : BpInterface<ISurfaceComposerClient>(impl) 50 { 51 } 52 53 virtual sp<ISurface> createSurface( surface_data_t* params, 54 const String8& name, 55 DisplayID display, 56 uint32_t w, 57 uint32_t h, 58 PixelFormat format, 59 uint32_t flags) 60 { 61 Parcel data, reply; 62 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); 63 data.writeString8(name); 64 data.writeInt32(display); 65 data.writeInt32(w); 66 data.writeInt32(h); 67 data.writeInt32(format); 68 data.writeInt32(flags); 69 remote()->transact(CREATE_SURFACE, data, &reply); 70 params->readFromParcel(reply); 71 return interface_cast<ISurface>(reply.readStrongBinder()); 72 } 73 74 virtual status_t destroySurface(SurfaceID sid) 75 { 76 Parcel data, reply; 77 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); 78 data.writeInt32(sid); 79 remote()->transact(DESTROY_SURFACE, data, &reply); 80 return reply.readInt32(); 81 } 82}; 83 84IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient"); 85 86// ---------------------------------------------------------------------- 87 88status_t BnSurfaceComposerClient::onTransact( 89 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 90{ 91 switch(code) { 92 case CREATE_SURFACE: { 93 CHECK_INTERFACE(ISurfaceComposerClient, data, reply); 94 surface_data_t params; 95 String8 name = data.readString8(); 96 DisplayID display = data.readInt32(); 97 uint32_t w = data.readInt32(); 98 uint32_t h = data.readInt32(); 99 PixelFormat format = data.readInt32(); 100 uint32_t flags = data.readInt32(); 101 sp<ISurface> s = createSurface(¶ms, name, display, w, h, 102 format, flags); 103 params.writeToParcel(reply); 104 reply->writeStrongBinder(s->asBinder()); 105 return NO_ERROR; 106 } break; 107 case DESTROY_SURFACE: { 108 CHECK_INTERFACE(ISurfaceComposerClient, data, reply); 109 reply->writeInt32( destroySurface( data.readInt32() ) ); 110 return NO_ERROR; 111 } break; 112 default: 113 return BBinder::onTransact(code, data, reply, flags); 114 } 115} 116 117// ---------------------------------------------------------------------- 118 119status_t ISurfaceComposerClient::surface_data_t::readFromParcel(const Parcel& parcel) 120{ 121 token = parcel.readInt32(); 122 identity = parcel.readInt32(); 123 return NO_ERROR; 124} 125 126status_t ISurfaceComposerClient::surface_data_t::writeToParcel(Parcel* parcel) const 127{ 128 parcel->writeInt32(token); 129 parcel->writeInt32(identity); 130 return NO_ERROR; 131} 132 133}; // namespace android 134