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 <gui/Surface.h>
24 #include <gui/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 
37 namespace android {
38 
39 sp<Surface> gSurface;
40 sp<SurfaceComposerClient> gComposerClient;
41 sp<SurfaceControl> gControl;
42 
getNativeWindow_()43 ANativeWindow *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                 1280,
56                 800,
57                 PIXEL_FORMAT_RGB_565,
58                 0);
59 
60     CHECK(control != NULL);
61     CHECK(control->isValid());
62 
63     SurfaceComposerClient::Transaction{}
64             .setLayer(control, 30000)
65             .show(control)
66             .apply();
67 
68     sp<Surface> surface = control->getSurface();
69     CHECK(surface != NULL);
70 
71     gSurface = surface;
72     gComposerClient = composerClient;
73     gControl = control;
74     // composerClient->dispose() at exit
75     return surface.get();
76 }
77 
disposeNativeWindow_()78 void disposeNativeWindow_()
79 {
80     gComposerClient->dispose();
81 }
82 
83 } // namespace android
84 
getNativeWindow()85 ANativeWindow *getNativeWindow()
86 {
87     return android::getNativeWindow_();
88 }
89 
disposeNativeWindow()90 void disposeNativeWindow()
91 {
92     android::disposeNativeWindow_();
93 }
94