• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #include <utils/Log.h>
18 
19 #include <binder/IPCThreadState.h>
20 #include <binder/ProcessState.h>
21 #include <binder/IServiceManager.h>
22 
23 #include <binder/IMemory.h>
24 #include <gui/ISurfaceComposer.h>
25 
26 #include <SkImageEncoder.h>
27 #include <SkBitmap.h>
28 
29 using namespace android;
30 
main(int argc,char ** argv)31 int main(int argc, char** argv)
32 {
33     if (argc != 2) {
34         printf("usage: %s path\n", argv[0]);
35         exit(0);
36     }
37 
38     const String16 name("SurfaceFlinger");
39     sp<ISurfaceComposer> composer;
40     getService(name, &composer);
41 
42     sp<IMemoryHeap> heap;
43     uint32_t w, h;
44     PixelFormat f;
45     sp<IBinder> display(composer->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
46     status_t err = composer->captureScreen(display, &heap, &w, &h, &f, 0, 0);
47     if (err != NO_ERROR) {
48         fprintf(stderr, "screen capture failed: %s\n", strerror(-err));
49         exit(0);
50     }
51 
52     printf("screen capture success: w=%u, h=%u, pixels=%p\n",
53             w, h, heap->getBase());
54 
55     printf("saving file as PNG in %s ...\n", argv[1]);
56 
57     SkBitmap b;
58     b.setConfig(SkBitmap::kARGB_8888_Config, w, h);
59     b.setPixels(heap->getBase());
60     SkImageEncoder::EncodeFile(argv[1], b,
61             SkImageEncoder::kPNG_Type, SkImageEncoder::kDefaultQuality);
62 
63     return 0;
64 }
65