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