| James Dong | 5f7204c | 2011-03-17 11:48:13 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2010 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 |  | 
| Mathias Agopian | 208cb07 | 2010-07-27 20:11:35 -0700 | [diff] [blame] | 17 | #include <cutils/memory.h> | 
|  | 18 |  | 
|  | 19 | #include <utils/Log.h> | 
|  | 20 |  | 
|  | 21 | #include <binder/IPCThreadState.h> | 
|  | 22 | #include <binder/ProcessState.h> | 
|  | 23 | #include <binder/IServiceManager.h> | 
|  | 24 |  | 
|  | 25 | #include <surfaceflinger/Surface.h> | 
|  | 26 | #include <surfaceflinger/ISurface.h> | 
|  | 27 | #include <surfaceflinger/SurfaceComposerClient.h> | 
|  | 28 |  | 
| Mathias Agopian | 208cb07 | 2010-07-27 20:11:35 -0700 | [diff] [blame] | 29 | using namespace android; | 
|  | 30 |  | 
|  | 31 | int main(int argc, char** argv) | 
|  | 32 | { | 
|  | 33 | // set up the thread-pool | 
|  | 34 | sp<ProcessState> proc(ProcessState::self()); | 
|  | 35 | ProcessState::self()->startThreadPool(); | 
|  | 36 |  | 
|  | 37 | // create a client to surfaceflinger | 
|  | 38 | sp<SurfaceComposerClient> client = new SurfaceComposerClient(); | 
|  | 39 |  | 
| Mathias Agopian | 208cb07 | 2010-07-27 20:11:35 -0700 | [diff] [blame] | 40 | sp<SurfaceControl> surfaceControl = client->createSurface( | 
| Glenn Kasten | e8c9ec6 | 2012-02-09 12:09:25 -0800 | [diff] [blame] | 41 | 0, 160, 240, PIXEL_FORMAT_RGB_565); | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 42 | SurfaceComposerClient::openGlobalTransaction(); | 
| Mathias Agopian | 208cb07 | 2010-07-27 20:11:35 -0700 | [diff] [blame] | 43 | surfaceControl->setLayer(100000); | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 44 | SurfaceComposerClient::closeGlobalTransaction(); | 
| Mathias Agopian | 208cb07 | 2010-07-27 20:11:35 -0700 | [diff] [blame] | 45 |  | 
|  | 46 | // pretend it went cross-process | 
|  | 47 | Parcel parcel; | 
|  | 48 | SurfaceControl::writeSurfaceToParcel(surfaceControl, &parcel); | 
|  | 49 | parcel.setDataPosition(0); | 
|  | 50 | sp<Surface> surface = Surface::readFromParcel(parcel); | 
|  | 51 | ANativeWindow* window = surface.get(); | 
|  | 52 |  | 
|  | 53 | printf("window=%p\n", window); | 
|  | 54 |  | 
|  | 55 | int err = native_window_set_buffer_count(window, 8); | 
| Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 56 | ANativeWindowBuffer* buffer; | 
| Mathias Agopian | 208cb07 | 2010-07-27 20:11:35 -0700 | [diff] [blame] | 57 |  | 
|  | 58 | for (int i=0 ; i<8 ; i++) { | 
|  | 59 | window->dequeueBuffer(window, &buffer); | 
|  | 60 | printf("buffer %d: %p\n", i, buffer); | 
|  | 61 | } | 
|  | 62 |  | 
|  | 63 | printf("test complete. CTRL+C to finish.\n"); | 
|  | 64 |  | 
|  | 65 | IPCThreadState::self()->joinThreadPool(); | 
|  | 66 | return 0; | 
|  | 67 | } |