• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 <system/window.h>
18 
query(ANativeWindow * window,int what)19 static int32_t query(ANativeWindow* window, int what) {
20     int value;
21     int res = window->query(window, what, &value);
22     return res < 0 ? res : value;
23 }
24 
query64(ANativeWindow * window,int what)25 static int64_t query64(ANativeWindow* window, int what) {
26     int64_t value;
27     int res = window->perform(window, what, &value);
28     return res < 0 ? res : value;
29 }
30 
ANativeWindow_setCancelBufferInterceptor(ANativeWindow * window,ANativeWindow_cancelBufferInterceptor interceptor,void * data)31 int ANativeWindow_setCancelBufferInterceptor(ANativeWindow* window,
32                                              ANativeWindow_cancelBufferInterceptor interceptor,
33                                              void* data) {
34     return window->perform(window, NATIVE_WINDOW_SET_CANCEL_INTERCEPTOR, interceptor, data);
35 }
36 
ANativeWindow_setDequeueBufferInterceptor(ANativeWindow * window,ANativeWindow_dequeueBufferInterceptor interceptor,void * data)37 int ANativeWindow_setDequeueBufferInterceptor(ANativeWindow* window,
38                                               ANativeWindow_dequeueBufferInterceptor interceptor,
39                                               void* data) {
40     return window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_INTERCEPTOR, interceptor, data);
41 }
42 
ANativeWindow_setQueueBufferInterceptor(ANativeWindow * window,ANativeWindow_queueBufferInterceptor interceptor,void * data)43 int ANativeWindow_setQueueBufferInterceptor(ANativeWindow* window,
44                                             ANativeWindow_queueBufferInterceptor interceptor,
45                                             void* data) {
46     return window->perform(window, NATIVE_WINDOW_SET_QUEUE_INTERCEPTOR, interceptor, data);
47 }
48 
ANativeWindow_setPerformInterceptor(ANativeWindow * window,ANativeWindow_performInterceptor interceptor,void * data)49 int ANativeWindow_setPerformInterceptor(ANativeWindow* window,
50                                         ANativeWindow_performInterceptor interceptor, void* data) {
51     return window->perform(window, NATIVE_WINDOW_SET_PERFORM_INTERCEPTOR, interceptor, data);
52 }
53 
ANativeWindow_dequeueBuffer(ANativeWindow * window,ANativeWindowBuffer ** buffer,int * fenceFd)54 int ANativeWindow_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, int* fenceFd) {
55     return window->dequeueBuffer(window, buffer, fenceFd);
56 }
57 
ANativeWindow_cancelBuffer(ANativeWindow * window,ANativeWindowBuffer * buffer,int fenceFd)58 int ANativeWindow_cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) {
59     return window->cancelBuffer(window, buffer, fenceFd);
60 }
61 
ANativeWindow_setDequeueTimeout(ANativeWindow * window,int64_t timeout)62 int ANativeWindow_setDequeueTimeout(ANativeWindow* window, int64_t timeout) {
63     return window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT, timeout);
64 }
65 
66 // extern "C", so that it can be used outside libhostgraphics (in host hwui/.../CanvasContext.cpp)
ANativeWindow_tryAllocateBuffers(ANativeWindow * window)67 extern "C" void ANativeWindow_tryAllocateBuffers(ANativeWindow* window) {
68     if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) {
69         return;
70     }
71     window->perform(window, NATIVE_WINDOW_ALLOCATE_BUFFERS);
72 }
73 
ANativeWindow_getLastDequeueStartTime(ANativeWindow * window)74 int64_t ANativeWindow_getLastDequeueStartTime(ANativeWindow* window) {
75     return query64(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_START);
76 }
77 
ANativeWindow_getLastDequeueDuration(ANativeWindow * window)78 int64_t ANativeWindow_getLastDequeueDuration(ANativeWindow* window) {
79     return query64(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION);
80 }
81 
ANativeWindow_getLastQueueDuration(ANativeWindow * window)82 int64_t ANativeWindow_getLastQueueDuration(ANativeWindow* window) {
83     return query64(window, NATIVE_WINDOW_GET_LAST_QUEUE_DURATION);
84 }
85 
ANativeWindow_getWidth(ANativeWindow * window)86 int32_t ANativeWindow_getWidth(ANativeWindow* window) {
87     return query(window, NATIVE_WINDOW_WIDTH);
88 }
89 
ANativeWindow_getHeight(ANativeWindow * window)90 int32_t ANativeWindow_getHeight(ANativeWindow* window) {
91     return query(window, NATIVE_WINDOW_HEIGHT);
92 }
93 
ANativeWindow_getFormat(ANativeWindow * window)94 int32_t ANativeWindow_getFormat(ANativeWindow* window) {
95     return query(window, NATIVE_WINDOW_FORMAT);
96 }
97 
ANativeWindow_acquire(ANativeWindow * window)98 void ANativeWindow_acquire(ANativeWindow* window) {
99     // incStrong/decStrong token must be the same, doesn't matter what it is
100     window->incStrong((void*)ANativeWindow_acquire);
101 }
102 
ANativeWindow_release(ANativeWindow * window)103 void ANativeWindow_release(ANativeWindow* window) {
104     // incStrong/decStrong token must be the same, doesn't matter what it is
105     window->decStrong((void*)ANativeWindow_acquire);
106 }
107