The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2007 The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License Version 2.0(the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 18 | #define LOG_TAG "FramebufferNativeWindow" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | |
| 20 | #include <stdlib.h> |
| 21 | #include <stdio.h> |
| 22 | #include <string.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 23 | #include <errno.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
| 25 | #include <cutils/log.h> |
| 26 | #include <cutils/atomic.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 27 | #include <utils/threads.h> |
Mathias Agopian | 42db9dc | 2009-08-06 20:46:44 -0700 | [diff] [blame] | 28 | #include <utils/RefBase.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
Mathias Agopian | 5f2165f | 2012-02-24 18:25:41 -0800 | [diff] [blame] | 30 | #include <ui/ANativeObjectBase.h> |
Jamie Gennis | d8e812c | 2012-06-13 16:32:25 -0700 | [diff] [blame] | 31 | #include <ui/Fence.h> |
Dan Stoza | f10c46e | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 32 | #define INCLUDED_FROM_FRAMEBUFFER_NATIVE_WINDOW_CPP |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 33 | #include <ui/FramebufferNativeWindow.h> |
Dan Stoza | f10c46e | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 34 | #undef INCLUDED_FROM_FRAMEBUFFER_NATIVE_WINDOW_CPP |
Mathias Agopian | 5f2165f | 2012-02-24 18:25:41 -0800 | [diff] [blame] | 35 | #include <ui/Rect.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| 37 | #include <EGL/egl.h> |
| 38 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 39 | #include <hardware/hardware.h> |
| 40 | #include <hardware/gralloc.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | |
| 42 | // ---------------------------------------------------------------------------- |
| 43 | namespace android { |
| 44 | // ---------------------------------------------------------------------------- |
| 45 | |
Mathias Agopian | 7189c00 | 2009-05-05 18:11:11 -0700 | [diff] [blame] | 46 | class NativeBuffer |
Mathias Agopian | 5f2165f | 2012-02-24 18:25:41 -0800 | [diff] [blame] | 47 | : public ANativeObjectBase< |
Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 48 | ANativeWindowBuffer, |
Mathias Agopian | 7189c00 | 2009-05-05 18:11:11 -0700 | [diff] [blame] | 49 | NativeBuffer, |
| 50 | LightRefBase<NativeBuffer> > |
| 51 | { |
| 52 | public: |
| 53 | NativeBuffer(int w, int h, int f, int u) : BASE() { |
Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 54 | ANativeWindowBuffer::width = w; |
| 55 | ANativeWindowBuffer::height = h; |
| 56 | ANativeWindowBuffer::format = f; |
| 57 | ANativeWindowBuffer::usage = u; |
Mathias Agopian | 7189c00 | 2009-05-05 18:11:11 -0700 | [diff] [blame] | 58 | } |
| 59 | private: |
| 60 | friend class LightRefBase<NativeBuffer>; |
| 61 | ~NativeBuffer() { }; // this class cannot be overloaded |
| 62 | }; |
| 63 | |
| 64 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 65 | /* |
| 66 | * This implements the (main) framebuffer management. This class is used |
| 67 | * mostly by SurfaceFlinger, but also by command line GL application. |
| 68 | * |
Dianne Hackborn | 4b5e91e | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 69 | * In fact this is an implementation of ANativeWindow on top of |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 70 | * the framebuffer. |
| 71 | * |
| 72 | * Currently it is pretty simple, it manages only two buffers (the front and |
| 73 | * back buffer). |
| 74 | * |
| 75 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 77 | FramebufferNativeWindow::FramebufferNativeWindow() |
Mathias Agopian | 1e16b13 | 2009-05-07 17:40:23 -0700 | [diff] [blame] | 78 | : BASE(), fbDev(0), grDev(0), mUpdateOnDemand(false) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 80 | hw_module_t const* module; |
| 81 | if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) { |
| 82 | int stride; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 83 | int err; |
Rodrigo Obregon | 71484f2 | 2010-11-03 15:16:18 -0500 | [diff] [blame] | 84 | int i; |
Mathias Agopian | 42db9dc | 2009-08-06 20:46:44 -0700 | [diff] [blame] | 85 | err = framebuffer_open(module, &fbDev); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 86 | ALOGE_IF(err, "couldn't open framebuffer HAL (%s)", strerror(-err)); |
Mathias Agopian | 42db9dc | 2009-08-06 20:46:44 -0700 | [diff] [blame] | 87 | |
| 88 | err = gralloc_open(module, &grDev); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 89 | ALOGE_IF(err, "couldn't open gralloc HAL (%s)", strerror(-err)); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | |
Mathias Agopian | 42db9dc | 2009-08-06 20:46:44 -0700 | [diff] [blame] | 91 | // bail out if we can't initialize the modules |
| 92 | if (!fbDev || !grDev) |
| 93 | return; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 94 | |
Mathias Agopian | 1e16b13 | 2009-05-07 17:40:23 -0700 | [diff] [blame] | 95 | mUpdateOnDemand = (fbDev->setUpdateRect != 0); |
| 96 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 97 | // initialize the buffer FIFO |
Naseer Ahmed | 0bc64be | 2012-06-29 12:02:32 -0700 | [diff] [blame] | 98 | if(fbDev->numFramebuffers >= MIN_NUM_FRAME_BUFFERS && |
| 99 | fbDev->numFramebuffers <= MAX_NUM_FRAME_BUFFERS){ |
| 100 | mNumBuffers = fbDev->numFramebuffers; |
| 101 | } else { |
| 102 | mNumBuffers = MIN_NUM_FRAME_BUFFERS; |
| 103 | } |
| 104 | mNumFreeBuffers = mNumBuffers; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 105 | mBufferHead = mNumBuffers-1; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | |
Dima Zavin | c6cd27c | 2012-02-22 14:37:57 -0800 | [diff] [blame] | 107 | /* |
| 108 | * This does not actually change the framebuffer format. It merely |
| 109 | * fakes this format to surfaceflinger so that when it creates |
| 110 | * framebuffer surfaces it will use this format. It's really a giant |
| 111 | * HACK to allow interworking with buggy gralloc+GPU driver |
| 112 | * implementations. You should *NEVER* need to set this for shipping |
| 113 | * devices. |
| 114 | */ |
| 115 | #ifdef FRAMEBUFFER_FORCE_FORMAT |
| 116 | *((uint32_t *)&fbDev->format) = FRAMEBUFFER_FORCE_FORMAT; |
| 117 | #endif |
| 118 | |
Rodrigo Obregon | 71484f2 | 2010-11-03 15:16:18 -0500 | [diff] [blame] | 119 | for (i = 0; i < mNumBuffers; i++) |
| 120 | { |
| 121 | buffers[i] = new NativeBuffer( |
| 122 | fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB); |
| 123 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | |
Rodrigo Obregon | 71484f2 | 2010-11-03 15:16:18 -0500 | [diff] [blame] | 125 | for (i = 0; i < mNumBuffers; i++) |
| 126 | { |
| 127 | err = grDev->alloc(grDev, |
| 128 | fbDev->width, fbDev->height, fbDev->format, |
| 129 | GRALLOC_USAGE_HW_FB, &buffers[i]->handle, &buffers[i]->stride); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 131 | ALOGE_IF(err, "fb buffer %d allocation failed w=%d, h=%d, err=%s", |
Rodrigo Obregon | 71484f2 | 2010-11-03 15:16:18 -0500 | [diff] [blame] | 132 | i, fbDev->width, fbDev->height, strerror(-err)); |
| 133 | |
| 134 | if (err) |
| 135 | { |
| 136 | mNumBuffers = i; |
| 137 | mNumFreeBuffers = i; |
| 138 | mBufferHead = mNumBuffers-1; |
| 139 | break; |
| 140 | } |
| 141 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 142 | |
Dianne Hackborn | 4b5e91e | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 143 | const_cast<uint32_t&>(ANativeWindow::flags) = fbDev->flags; |
| 144 | const_cast<float&>(ANativeWindow::xdpi) = fbDev->xdpi; |
| 145 | const_cast<float&>(ANativeWindow::ydpi) = fbDev->ydpi; |
| 146 | const_cast<int&>(ANativeWindow::minSwapInterval) = |
Marco Nelissen | a455793 | 2009-09-23 10:54:36 -0700 | [diff] [blame] | 147 | fbDev->minSwapInterval; |
Dianne Hackborn | 4b5e91e | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 148 | const_cast<int&>(ANativeWindow::maxSwapInterval) = |
Marco Nelissen | a455793 | 2009-09-23 10:54:36 -0700 | [diff] [blame] | 149 | fbDev->maxSwapInterval; |
| 150 | } else { |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 151 | ALOGE("Couldn't get gralloc module"); |
Marco Nelissen | a455793 | 2009-09-23 10:54:36 -0700 | [diff] [blame] | 152 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 153 | |
Dianne Hackborn | 4b5e91e | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 154 | ANativeWindow::setSwapInterval = setSwapInterval; |
| 155 | ANativeWindow::dequeueBuffer = dequeueBuffer; |
Dianne Hackborn | 4b5e91e | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 156 | ANativeWindow::queueBuffer = queueBuffer; |
| 157 | ANativeWindow::query = query; |
| 158 | ANativeWindow::perform = perform; |
Jamie Gennis | d8e812c | 2012-06-13 16:32:25 -0700 | [diff] [blame] | 159 | |
| 160 | ANativeWindow::dequeueBuffer_DEPRECATED = dequeueBuffer_DEPRECATED; |
| 161 | ANativeWindow::lockBuffer_DEPRECATED = lockBuffer_DEPRECATED; |
| 162 | ANativeWindow::queueBuffer_DEPRECATED = queueBuffer_DEPRECATED; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Mathias Agopian | 42db9dc | 2009-08-06 20:46:44 -0700 | [diff] [blame] | 165 | FramebufferNativeWindow::~FramebufferNativeWindow() |
| 166 | { |
| 167 | if (grDev) { |
Naseer Ahmed | 0bc64be | 2012-06-29 12:02:32 -0700 | [diff] [blame] | 168 | for(int i = 0; i < mNumBuffers; i++) { |
| 169 | if (buffers[i] != NULL) { |
| 170 | grDev->free(grDev, buffers[i]->handle); |
| 171 | } |
| 172 | } |
Mathias Agopian | 42db9dc | 2009-08-06 20:46:44 -0700 | [diff] [blame] | 173 | gralloc_close(grDev); |
| 174 | } |
| 175 | |
| 176 | if (fbDev) { |
| 177 | framebuffer_close(fbDev); |
| 178 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Mathias Agopian | 1e16b13 | 2009-05-07 17:40:23 -0700 | [diff] [blame] | 181 | status_t FramebufferNativeWindow::setUpdateRectangle(const Rect& r) |
| 182 | { |
| 183 | if (!mUpdateOnDemand) { |
| 184 | return INVALID_OPERATION; |
| 185 | } |
| 186 | return fbDev->setUpdateRect(fbDev, r.left, r.top, r.width(), r.height()); |
| 187 | } |
| 188 | |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 189 | status_t FramebufferNativeWindow::compositionComplete() |
| 190 | { |
| 191 | if (fbDev->compositionComplete) { |
| 192 | return fbDev->compositionComplete(fbDev); |
| 193 | } |
| 194 | return INVALID_OPERATION; |
| 195 | } |
| 196 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 197 | int FramebufferNativeWindow::setSwapInterval( |
Dianne Hackborn | 4b5e91e | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 198 | ANativeWindow* window, int interval) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 199 | { |
| 200 | framebuffer_device_t* fb = getSelf(window)->fbDev; |
| 201 | return fb->setSwapInterval(fb, interval); |
| 202 | } |
| 203 | |
Erik Gilling | 1d21a9c | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 204 | void FramebufferNativeWindow::dump(String8& result) { |
| 205 | if (fbDev->common.version >= 1 && fbDev->dump) { |
| 206 | const size_t SIZE = 4096; |
| 207 | char buffer[SIZE]; |
| 208 | |
| 209 | fbDev->dump(fbDev, buffer, SIZE); |
| 210 | result.append(buffer); |
| 211 | } |
| 212 | } |
| 213 | |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 214 | // only for debugging / logging |
| 215 | int FramebufferNativeWindow::getCurrentBufferIndex() const |
| 216 | { |
| 217 | Mutex::Autolock _l(mutex); |
| 218 | const int index = mCurrentBufferIndex; |
| 219 | return index; |
| 220 | } |
| 221 | |
Jamie Gennis | d8e812c | 2012-06-13 16:32:25 -0700 | [diff] [blame] | 222 | int FramebufferNativeWindow::dequeueBuffer_DEPRECATED(ANativeWindow* window, |
Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 223 | ANativeWindowBuffer** buffer) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 224 | { |
Jamie Gennis | d8e812c | 2012-06-13 16:32:25 -0700 | [diff] [blame] | 225 | int fenceFd = -1; |
| 226 | int result = dequeueBuffer(window, buffer, &fenceFd); |
| 227 | sp<Fence> fence(new Fence(fenceFd)); |
| 228 | int waitResult = fence->wait(Fence::TIMEOUT_NEVER); |
| 229 | if (waitResult != OK) { |
| 230 | ALOGE("dequeueBuffer_DEPRECATED: Fence::wait returned an " |
| 231 | "error: %d", waitResult); |
| 232 | return waitResult; |
| 233 | } |
| 234 | return result; |
| 235 | } |
| 236 | |
| 237 | int FramebufferNativeWindow::dequeueBuffer(ANativeWindow* window, |
| 238 | ANativeWindowBuffer** buffer, int* fenceFd) |
| 239 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 240 | FramebufferNativeWindow* self = getSelf(window); |
| 241 | Mutex::Autolock _l(self->mutex); |
| 242 | framebuffer_device_t* fb = self->fbDev; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 244 | int index = self->mBufferHead++; |
| 245 | if (self->mBufferHead >= self->mNumBuffers) |
| 246 | self->mBufferHead = 0; |
| 247 | |
Jesse Hall | a74cbc0 | 2012-06-21 11:35:23 -0700 | [diff] [blame] | 248 | // wait for a free non-front buffer |
| 249 | while (self->mNumFreeBuffers < 2) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 250 | self->mCondition.wait(self->mutex); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | } |
Jesse Hall | a74cbc0 | 2012-06-21 11:35:23 -0700 | [diff] [blame] | 252 | ALOG_ASSERT(self->buffers[index] != self->front); |
| 253 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 254 | // get this buffer |
| 255 | self->mNumFreeBuffers--; |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 256 | self->mCurrentBufferIndex = index; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 257 | |
| 258 | *buffer = self->buffers[index].get(); |
Jamie Gennis | d8e812c | 2012-06-13 16:32:25 -0700 | [diff] [blame] | 259 | *fenceFd = -1; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 260 | |
| 261 | return 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 264 | int FramebufferNativeWindow::lockBuffer_DEPRECATED(ANativeWindow* /*window*/, |
| 265 | ANativeWindowBuffer* /*buffer*/) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | { |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 267 | return NO_ERROR; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Jamie Gennis | d8e812c | 2012-06-13 16:32:25 -0700 | [diff] [blame] | 270 | int FramebufferNativeWindow::queueBuffer_DEPRECATED(ANativeWindow* window, |
Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 271 | ANativeWindowBuffer* buffer) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 272 | { |
Jamie Gennis | d8e812c | 2012-06-13 16:32:25 -0700 | [diff] [blame] | 273 | return queueBuffer(window, buffer, -1); |
| 274 | } |
| 275 | |
| 276 | int FramebufferNativeWindow::queueBuffer(ANativeWindow* window, |
| 277 | ANativeWindowBuffer* buffer, int fenceFd) |
| 278 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 279 | FramebufferNativeWindow* self = getSelf(window); |
| 280 | Mutex::Autolock _l(self->mutex); |
| 281 | framebuffer_device_t* fb = self->fbDev; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 282 | buffer_handle_t handle = static_cast<NativeBuffer*>(buffer)->handle; |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 283 | |
Jamie Gennis | d8e812c | 2012-06-13 16:32:25 -0700 | [diff] [blame] | 284 | sp<Fence> fence(new Fence(fenceFd)); |
| 285 | fence->wait(Fence::TIMEOUT_NEVER); |
| 286 | |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 287 | const int index = self->mCurrentBufferIndex; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 288 | int res = fb->post(fb, handle); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 289 | self->front = static_cast<NativeBuffer*>(buffer); |
| 290 | self->mNumFreeBuffers++; |
| 291 | self->mCondition.broadcast(); |
| 292 | return res; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Iliyan Malchev | 41abd67 | 2011-04-14 16:54:38 -0700 | [diff] [blame] | 295 | int FramebufferNativeWindow::query(const ANativeWindow* window, |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 296 | int what, int* value) |
| 297 | { |
Iliyan Malchev | 41abd67 | 2011-04-14 16:54:38 -0700 | [diff] [blame] | 298 | const FramebufferNativeWindow* self = getSelf(window); |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 299 | Mutex::Autolock _l(self->mutex); |
| 300 | framebuffer_device_t* fb = self->fbDev; |
| 301 | switch (what) { |
| 302 | case NATIVE_WINDOW_WIDTH: |
| 303 | *value = fb->width; |
| 304 | return NO_ERROR; |
| 305 | case NATIVE_WINDOW_HEIGHT: |
| 306 | *value = fb->height; |
| 307 | return NO_ERROR; |
Mathias Agopian | 6b1f410 | 2009-08-06 16:04:29 -0700 | [diff] [blame] | 308 | case NATIVE_WINDOW_FORMAT: |
| 309 | *value = fb->format; |
| 310 | return NO_ERROR; |
Jamie Gennis | 391bbe2 | 2011-03-14 15:00:06 -0700 | [diff] [blame] | 311 | case NATIVE_WINDOW_CONCRETE_TYPE: |
| 312 | *value = NATIVE_WINDOW_FRAMEBUFFER; |
| 313 | return NO_ERROR; |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 314 | case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: |
| 315 | *value = 0; |
| 316 | return NO_ERROR; |
| 317 | case NATIVE_WINDOW_DEFAULT_WIDTH: |
| 318 | *value = fb->width; |
| 319 | return NO_ERROR; |
| 320 | case NATIVE_WINDOW_DEFAULT_HEIGHT: |
| 321 | *value = fb->height; |
| 322 | return NO_ERROR; |
| 323 | case NATIVE_WINDOW_TRANSFORM_HINT: |
| 324 | *value = 0; |
| 325 | return NO_ERROR; |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 326 | } |
Mathias Agopian | 42db9dc | 2009-08-06 20:46:44 -0700 | [diff] [blame] | 327 | *value = 0; |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 328 | return BAD_VALUE; |
| 329 | } |
| 330 | |
Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 331 | int FramebufferNativeWindow::perform(ANativeWindow* /*window*/, |
Mathias Agopian | 5221271 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 332 | int operation, ...) |
| 333 | { |
| 334 | switch (operation) { |
Mathias Agopian | 55fa251 | 2010-03-11 15:06:54 -0800 | [diff] [blame] | 335 | case NATIVE_WINDOW_CONNECT: |
| 336 | case NATIVE_WINDOW_DISCONNECT: |
Mathias Agopian | bb66c9b | 2011-07-21 14:50:29 -0700 | [diff] [blame] | 337 | case NATIVE_WINDOW_SET_USAGE: |
Mathias Agopian | 7734ebf | 2011-07-13 15:24:42 -0700 | [diff] [blame] | 338 | case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY: |
Mathias Agopian | 7734ebf | 2011-07-13 15:24:42 -0700 | [diff] [blame] | 339 | case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS: |
Mathias Agopian | 7734ebf | 2011-07-13 15:24:42 -0700 | [diff] [blame] | 340 | case NATIVE_WINDOW_SET_BUFFERS_FORMAT: |
Mathias Agopian | bb66c9b | 2011-07-21 14:50:29 -0700 | [diff] [blame] | 341 | case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM: |
Mathias Agopian | 81a6335 | 2011-07-29 17:55:48 -0700 | [diff] [blame] | 342 | case NATIVE_WINDOW_API_CONNECT: |
| 343 | case NATIVE_WINDOW_API_DISCONNECT: |
Mathias Agopian | bb66c9b | 2011-07-21 14:50:29 -0700 | [diff] [blame] | 344 | // TODO: we should implement these |
Mathias Agopian | 7734ebf | 2011-07-13 15:24:42 -0700 | [diff] [blame] | 345 | return NO_ERROR; |
Mathias Agopian | bb66c9b | 2011-07-21 14:50:29 -0700 | [diff] [blame] | 346 | |
| 347 | case NATIVE_WINDOW_LOCK: |
| 348 | case NATIVE_WINDOW_UNLOCK_AND_POST: |
| 349 | case NATIVE_WINDOW_SET_CROP: |
| 350 | case NATIVE_WINDOW_SET_BUFFER_COUNT: |
| 351 | case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP: |
Mathias Agopian | 7734ebf | 2011-07-13 15:24:42 -0700 | [diff] [blame] | 352 | case NATIVE_WINDOW_SET_SCALING_MODE: |
| 353 | return INVALID_OPERATION; |
Mathias Agopian | 5221271 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 354 | } |
Mathias Agopian | 7734ebf | 2011-07-13 15:24:42 -0700 | [diff] [blame] | 355 | return NAME_NOT_FOUND; |
Mathias Agopian | 5221271 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 356 | } |
| 357 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | // ---------------------------------------------------------------------------- |
| 359 | }; // namespace android |
| 360 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 361 | |
Mathias Agopian | 42db9dc | 2009-08-06 20:46:44 -0700 | [diff] [blame] | 362 | using namespace android; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 363 | |
| 364 | EGLNativeWindowType android_createDisplaySurface(void) |
| 365 | { |
Mathias Agopian | 42db9dc | 2009-08-06 20:46:44 -0700 | [diff] [blame] | 366 | FramebufferNativeWindow* w; |
| 367 | w = new FramebufferNativeWindow(); |
| 368 | if (w->getDevice() == NULL) { |
| 369 | // get a ref so it can be destroyed when we exit this block |
| 370 | sp<FramebufferNativeWindow> ref(w); |
| 371 | return NULL; |
| 372 | } |
| 373 | return (EGLNativeWindowType)w; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 374 | } |