nativewindow.cpp revision 75290ff394698c53f35a21612c03b8ddd21fecf9
1/* 2 * Copyright (C) 2011 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// Copied from frameworks/base/cmds/stagefright/stream.cpp 18 19// Note to NDK developers who happen to see this: this module uses Android internal platform APIs 20// that are not part of the NDK supported APIs, and are subject to change at any time. 21 22#include <binder/ProcessState.h> 23#include <surfaceflinger/ISurfaceComposer.h> 24#include <surfaceflinger/SurfaceComposerClient.h> 25#include <utils/String8.h> 26 27#include "nativewindow.h" 28 29#if 1 30#include <assert.h> 31#define CHECK assert 32#define CHECK_EQ(a,b) CHECK((a)==(b)) 33#else 34#include <media/stagefright/foundation/ADebug.h> 35#endif 36 37namespace android { 38 39sp<Surface> gSurface; 40sp<SurfaceComposerClient> gComposerClient; 41sp<SurfaceControl> gControl; 42 43ANativeWindow *getNativeWindow_() 44{ 45#if 0 46 android::ProcessState::self()->startThreadPool(); 47#endif 48 49 sp<SurfaceComposerClient> composerClient = new SurfaceComposerClient; 50 CHECK_EQ(composerClient->initCheck(), (status_t)OK); 51 52 sp<SurfaceControl> control = 53 composerClient->createSurface( 54 String8("A Surface"), 55 0, 56 1280, 57 800, 58 PIXEL_FORMAT_RGB_565, 59 0); 60 61 CHECK(control != NULL); 62 CHECK(control->isValid()); 63 64 SurfaceComposerClient::openGlobalTransaction(); 65 CHECK_EQ(control->setLayer(30000), (status_t)OK); 66 CHECK_EQ(control->show(), (status_t)OK); 67 SurfaceComposerClient::closeGlobalTransaction(); 68 69 sp<Surface> surface = control->getSurface(); 70 CHECK(surface != NULL); 71 72 gSurface = surface; 73 gComposerClient = composerClient; 74 gControl = control; 75 // composerClient->dispose() at exit 76 return surface.get(); 77} 78 79} // namespace android 80 81ANativeWindow *getNativeWindow() 82{ 83 return android::getNativeWindow_(); 84} 85