1199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong/* 2199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * Copyright (C) 2010 The Android Open Source Project 3199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * 4199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * Licensed under the Apache License, Version 2.0 (the "License"); 5199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * you may not use this file except in compliance with the License. 6199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * You may obtain a copy of the License at 7199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * 8199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * http://www.apache.org/licenses/LICENSE-2.0 9199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * 10199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * Unless required by applicable law or agreed to in writing, software 11199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * distributed under the License is distributed on an "AS IS" BASIS, 12199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * See the License for the specific language governing permissions and 14199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * limitations under the License. 15199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong */ 16199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong 1751c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian#include <cutils/memory.h> 1851c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian 1951c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian#include <utils/Log.h> 2051c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian 2151c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian#include <binder/IPCThreadState.h> 2251c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian#include <binder/ProcessState.h> 2351c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian#include <binder/IServiceManager.h> 2451c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian 2551c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian#include <surfaceflinger/Surface.h> 2651c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian#include <surfaceflinger/ISurface.h> 2751c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian#include <surfaceflinger/SurfaceComposerClient.h> 2851c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian 2951c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopianusing namespace android; 3051c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian 3151c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopianint main(int argc, char** argv) 3251c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian{ 3351c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian // set up the thread-pool 3451c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian sp<ProcessState> proc(ProcessState::self()); 3551c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian ProcessState::self()->startThreadPool(); 3651c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian 3751c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian // create a client to surfaceflinger 3851c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian sp<SurfaceComposerClient> client = new SurfaceComposerClient(); 3951c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian 4051c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian sp<SurfaceControl> surfaceControl = client->createSurface( 4151c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian getpid(), 0, 160, 240, PIXEL_FORMAT_RGB_565); 42439863f3b3e725b5de1cba4940a21900369961c0Mathias Agopian SurfaceComposerClient::openGlobalTransaction(); 4351c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian surfaceControl->setLayer(100000); 44439863f3b3e725b5de1cba4940a21900369961c0Mathias Agopian SurfaceComposerClient::closeGlobalTransaction(); 4551c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian 4651c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian // pretend it went cross-process 4751c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian Parcel parcel; 4851c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian SurfaceControl::writeSurfaceToParcel(surfaceControl, &parcel); 4951c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian parcel.setDataPosition(0); 5051c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian sp<Surface> surface = Surface::readFromParcel(parcel); 5151c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian ANativeWindow* window = surface.get(); 5251c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian 5351c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian printf("window=%p\n", window); 5451c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian 5551c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian int err = native_window_set_buffer_count(window, 8); 56b2a153adc9860616acdb96d7cdd64494d5a2a0f2Iliyan Malchev ANativeWindowBuffer* buffer; 5751c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian 5851c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian for (int i=0 ; i<8 ; i++) { 5951c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian window->dequeueBuffer(window, &buffer); 6051c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian printf("buffer %d: %p\n", i, buffer); 6151c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian } 6251c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian 6351c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian printf("test complete. CTRL+C to finish.\n"); 6451c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian 6551c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian IPCThreadState::self()->joinThreadPool(); 6651c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian return 0; 6751c70e3e41ee8bedc1d951a06a74202dafa13009Mathias Agopian} 68