15f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong/*
25f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong * Copyright (C) 2010 The Android Open Source Project
35f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong *
45f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong * Licensed under the Apache License, Version 2.0 (the "License");
55f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong * you may not use this file except in compliance with the License.
65f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong * You may obtain a copy of the License at
75f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong *
85f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong *      http://www.apache.org/licenses/LICENSE-2.0
95f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong *
105f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong * Unless required by applicable law or agreed to in writing, software
115f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong * distributed under the License is distributed on an "AS IS" BASIS,
125f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong * See the License for the specific language governing permissions and
145f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong * limitations under the License.
155f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong */
165f7204cb66b5500c814b5987af5db99b2b8fe90cJames Dong
17076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <cutils/memory.h>
18076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
19076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <utils/Log.h>
20076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
219cce325fae8adcf7560a28eef394489f09bad74dMathias Agopian#include <binder/IPCThreadState.h>
229cce325fae8adcf7560a28eef394489f09bad74dMathias Agopian#include <binder/ProcessState.h>
239cce325fae8adcf7560a28eef394489f09bad74dMathias Agopian#include <binder/IServiceManager.h>
249cce325fae8adcf7560a28eef394489f09bad74dMathias Agopian
2590ac799241f077a7b7e6c1875fd933864c8dd2a7Mathias Agopian#include <gui/Surface.h>
2690ac799241f077a7b7e6c1875fd933864c8dd2a7Mathias Agopian#include <gui/SurfaceComposerClient.h>
279cce325fae8adcf7560a28eef394489f09bad74dMathias Agopian
28076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopianusing namespace android;
29076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
30076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiannamespace android {
31076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
32076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopianint main(int argc, char** argv)
33076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{
34076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    // set up the thread-pool
35076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    sp<ProcessState> proc(ProcessState::self());
36076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    ProcessState::self()->startThreadPool();
37076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
38076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    // create a client to surfaceflinger
39076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    sp<SurfaceComposerClient> client = new SurfaceComposerClient();
40076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
41e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    sp<SurfaceControl> surfaceControl = client->createSurface(String8("resize"),
429d4e3d2f42e93e2d12bacabe97d307d30c3c20ddJeff Brown            160, 240, PIXEL_FORMAT_RGB_565, 0);
43076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
44e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    sp<Surface> surface = surfaceControl->getSurface();
45076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
46698c0873cf2e07bdc7fd1e72169aee2a19fa40d7Mathias Agopian    SurfaceComposerClient::openGlobalTransaction();
47e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    surfaceControl->setLayer(100000);
48698c0873cf2e07bdc7fd1e72169aee2a19fa40d7Mathias Agopian    SurfaceComposerClient::closeGlobalTransaction();
49076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
50e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    ANativeWindow_Buffer outBuffer;
51e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    surface->lock(&outBuffer, NULL);
52e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    ssize_t bpr = outBuffer.stride * bytesPerPixel(outBuffer.format);
53e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    android_memset16((uint16_t*)outBuffer.bits, 0xF800, bpr*outBuffer.height);
54076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    surface->unlockAndPost();
55076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
56e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    surface->lock(&outBuffer);
57e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    android_memset16((uint16_t*)outBuffer.bits, 0x07E0, bpr*outBuffer.height);
58076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    surface->unlockAndPost();
59076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
60698c0873cf2e07bdc7fd1e72169aee2a19fa40d7Mathias Agopian    SurfaceComposerClient::openGlobalTransaction();
61e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    surfaceControl->setSize(320, 240);
62698c0873cf2e07bdc7fd1e72169aee2a19fa40d7Mathias Agopian    SurfaceComposerClient::closeGlobalTransaction();
63076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
64076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
65076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    IPCThreadState::self()->joinThreadPool();
66076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
67076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    return 0;
68076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian}
69