diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:31:44 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:31:44 -0800 |
commit | edbf3b6af777b721cd2a1ef461947e51e88241e1 (patch) | |
tree | f09427b843b192cccf8c3b5328cb81dddf6489fa /include/ui | |
parent | d5193d9394c5e58176d7bcdf50ef017f8a3b9e1e (diff) | |
download | frameworks_native-edbf3b6af777b721cd2a1ef461947e51e88241e1.zip frameworks_native-edbf3b6af777b721cd2a1ef461947e51e88241e1.tar.gz frameworks_native-edbf3b6af777b721cd2a1ef461947e51e88241e1.tar.bz2 |
auto import from //depot/cupcake/@135843
Diffstat (limited to 'include/ui')
-rw-r--r-- | include/ui/Camera.h | 196 | ||||
-rw-r--r-- | include/ui/CameraHardwareInterface.h | 190 | ||||
-rw-r--r-- | include/ui/CameraParameters.h | 79 | ||||
-rw-r--r-- | include/ui/DisplayInfo.h | 43 | ||||
-rw-r--r-- | include/ui/EGLDisplaySurface.h | 86 | ||||
-rw-r--r-- | include/ui/EGLNativeSurface.h | 55 | ||||
-rw-r--r-- | include/ui/EGLNativeWindowSurface.h | 59 | ||||
-rw-r--r-- | include/ui/EventHub.h | 145 | ||||
-rw-r--r-- | include/ui/ICamera.h | 102 | ||||
-rw-r--r-- | include/ui/ICameraClient.h | 55 | ||||
-rw-r--r-- | include/ui/ICameraService.h | 55 | ||||
-rw-r--r-- | include/ui/IOverlay.h | 53 | ||||
-rw-r--r-- | include/ui/ISurface.h | 105 | ||||
-rw-r--r-- | include/ui/ISurfaceComposer.h | 181 | ||||
-rw-r--r-- | include/ui/ISurfaceFlingerClient.h | 90 | ||||
-rw-r--r-- | include/ui/KeyCharacterMap.h | 72 | ||||
-rw-r--r-- | include/ui/KeycodeLabels.h | 236 | ||||
-rw-r--r-- | include/ui/Overlay.h | 109 | ||||
-rw-r--r-- | include/ui/PixelFormat.h | 125 | ||||
-rw-r--r-- | include/ui/Point.h | 88 | ||||
-rw-r--r-- | include/ui/Rect.h | 152 | ||||
-rw-r--r-- | include/ui/Region.h | 174 | ||||
-rw-r--r-- | include/ui/Surface.h | 137 | ||||
-rw-r--r-- | include/ui/SurfaceComposerClient.h | 179 |
24 files changed, 2766 insertions, 0 deletions
diff --git a/include/ui/Camera.h b/include/ui/Camera.h new file mode 100644 index 0000000..e593fea --- /dev/null +++ b/include/ui/Camera.h @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * Copyright (C) 2008 HTC Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_CAMERA_H +#define ANDROID_HARDWARE_CAMERA_H + +#include <ui/ICameraClient.h> + +namespace android { + +/* + * A set of bit masks for specifying how the received preview frames are + * handled before the previewCallback() call. + * + * The least significant 3 bits of an "int" value are used for this purpose: + * + * ..... 0 0 0 + * ^ ^ ^ + * | | |---------> determine whether the callback is enabled or not + * | |-----------> determine whether the callback is one-shot or not + * |-------------> determine whether the frame is copied out or not + * + * WARNING: + * When a frame is sent directly without copying, it is the frame receiver's + * responsiblity to make sure that the frame data won't get corrupted by + * subsequent preview frames filled by the camera. This flag is recommended + * only when copying out data brings significant performance price and the + * handling/processing of the received frame data is always faster than + * the preview frame rate so that data corruption won't occur. + * + * For instance, + * 1. 0x00 disables the callback. In this case, copy out and one shot bits + * are ignored. + * 2. 0x01 enables a callback without copying out the received frames. A + * typical use case is the Camcorder application to avoid making costly + * frame copies. + * 3. 0x05 is enabling a callback with frame copied out repeatedly. A typical + * use case is the Camera application. + * 4. 0x07 is enabling a callback with frame copied out only once. A typical use + * case is the Barcode scanner application. + */ +#define FRAME_CALLBACK_FLAG_ENABLE_MASK 0x01 +#define FRAME_CALLBACK_FLAG_ONE_SHOT_MASK 0x02 +#define FRAME_CALLBACK_FLAG_COPY_OUT_MASK 0x04 + +// Typical use cases +#define FRAME_CALLBACK_FLAG_NOOP 0x00 +#define FRAME_CALLBACK_FLAG_CAMCORDER 0x01 +#define FRAME_CALLBACK_FLAG_CAMERA 0x05 +#define FRAME_CALLBACK_FLAG_BARCODE_SCANNER 0x07 + +class ICameraService; +class ICamera; +class Surface; +class Mutex; +class String8; + +typedef void (*shutter_callback)(void *cookie); +typedef void (*frame_callback)(const sp<IMemory>& mem, void *cookie); +typedef void (*autofocus_callback)(bool focused, void *cookie); +typedef void (*error_callback)(status_t err, void *cookie); + +class Camera : public BnCameraClient, public IBinder::DeathRecipient +{ +public: + // construct a camera client from an existing remote + Camera(const sp<ICamera>& camera); + + static sp<Camera> connect(); + ~Camera(); + void init(); + + status_t reconnect(); + void disconnect(); + status_t lock(); + status_t unlock(); + + status_t getStatus() { return mStatus; } + + // pass the buffered ISurface to the camera service + status_t setPreviewDisplay(const sp<Surface>& surface); + status_t setPreviewDisplay(const sp<ISurface>& surface); + + // start preview mode, must call setPreviewDisplay first + status_t startPreview(); + + // stop preview mode + void stopPreview(); + + // get preview state + bool previewEnabled(); + + // start recording mode, must call setPreviewDisplay first + status_t startRecording(); + + // stop recording mode + void stopRecording(); + + // get recording state + bool recordingEnabled(); + + // release a recording frame + void releaseRecordingFrame(const sp<IMemory>& mem); + + // autoFocus - status returned from callback + status_t autoFocus(); + + // take a picture - picture returned from callback + status_t takePicture(); + + // set preview/capture parameters - key/value pairs + status_t setParameters(const String8& params); + + // get preview/capture parameters - key/value pairs + String8 getParameters() const; + + void setShutterCallback(shutter_callback cb, void *cookie); + void setRawCallback(frame_callback cb, void *cookie); + void setJpegCallback(frame_callback cb, void *cookie); + void setRecordingCallback(frame_callback cb, void *cookie); + void setPreviewCallback(frame_callback cb, void *cookie, int preview_callback_flag = FRAME_CALLBACK_FLAG_NOOP); + void setErrorCallback(error_callback cb, void *cookie); + void setAutoFocusCallback(autofocus_callback cb, void *cookie); + + // ICameraClient interface + virtual void shutterCallback(); + virtual void rawCallback(const sp<IMemory>& picture); + virtual void jpegCallback(const sp<IMemory>& picture); + virtual void previewCallback(const sp<IMemory>& frame); + virtual void errorCallback(status_t error); + virtual void autoFocusCallback(bool focused); + virtual void recordingCallback(const sp<IMemory>& frame); + + sp<ICamera> remote(); + +private: + Camera(); + virtual void binderDied(const wp<IBinder>& who); + + class DeathNotifier: public IBinder::DeathRecipient + { + public: + DeathNotifier() { + } + + virtual void binderDied(const wp<IBinder>& who); + }; + + static sp<DeathNotifier> mDeathNotifier; + + // helper function to obtain camera service handle + static const sp<ICameraService>& getCameraService(); + + sp<ICamera> mCamera; + status_t mStatus; + + shutter_callback mShutterCallback; + void *mShutterCallbackCookie; + frame_callback mRawCallback; + void *mRawCallbackCookie; + frame_callback mJpegCallback; + void *mJpegCallbackCookie; + frame_callback mPreviewCallback; + void *mPreviewCallbackCookie; + frame_callback mRecordingCallback; + void *mRecordingCallbackCookie; + error_callback mErrorCallback; + void *mErrorCallbackCookie; + autofocus_callback mAutoFocusCallback; + void *mAutoFocusCallbackCookie; + + friend class DeathNotifier; + + static Mutex mLock; + static sp<ICameraService> mCameraService; + +}; + +}; // namespace android + +#endif + diff --git a/include/ui/CameraHardwareInterface.h b/include/ui/CameraHardwareInterface.h new file mode 100644 index 0000000..73036f0 --- /dev/null +++ b/include/ui/CameraHardwareInterface.h @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H +#define ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H + +#include <utils/IMemory.h> +#include <utils/RefBase.h> +#include <ui/CameraParameters.h> +#include <ui/Overlay.h> + +namespace android { + +/** Callback for startPreview() */ +typedef void (*preview_callback)(const sp<IMemory>& mem, void* user); + +/** Callback for startRecord() */ +typedef void (*recording_callback)(const sp<IMemory>& mem, void* user); + +/** Callback for takePicture() */ +typedef void (*shutter_callback)(void* user); + +/** Callback for takePicture() */ +typedef void (*raw_callback)(const sp<IMemory>& mem, void* user); + +/** Callback for takePicture() */ +typedef void (*jpeg_callback)(const sp<IMemory>& mem, void* user); + +/** Callback for autoFocus() */ +typedef void (*autofocus_callback)(bool focused, void* user); + +/** + * CameraHardwareInterface.h defines the interface to the + * camera hardware abstraction layer, used for setting and getting + * parameters, live previewing, and taking pictures. + * + * It is a referenced counted interface with RefBase as its base class. + * CameraService calls openCameraHardware() to retrieve a strong pointer to the + * instance of this interface and may be called multiple times. The + * following steps describe a typical sequence: + * + * -# After CameraService calls openCameraHardware(), getParameters() and + * setParameters() are used to initialize the camera instance. + * CameraService calls getPreviewHeap() to establish access to the + * preview heap so it can be registered with SurfaceFlinger for + * efficient display updating while in preview mode. + * -# startPreview() is called, which is passed a preview_callback() + * function and a user parameter. The camera instance then periodically + * calls preview_callback() each time a new preview frame is available. + * The callback routine has two parameters: the first is a pointer to + * the IMemory containing the frame and the second a user parameter. If + * the preview_callback code needs to use this memory after returning, + * it must copy the data. + * + * Prior to taking a picture, CameraService calls autofocus() with + * autofocus_callback() and a user parameter. When auto focusing has + * completed, the camera instance calls autofocus_callback(), which informs + * the application whether focusing was successful. The camera instance + * only calls autofocus_callback() once and it is up to the application to + * call autoFocus() again if refocusing is desired. + * + * CameraService calls takePicture() to request the camera instance take a + * picture. This method has two callbacks: raw_callback() and jpeg_callback(). + * When the raw image is available, raw_callback() is called with a pointer + * to the IMemory containing the raw image. When the jpeg image is available, + * jpeg_callback() is called with a pointer to the IMemory containing the + * jpeg image. As with preview_callback(), the memory must be copied if it's + * needed after returning. + */ +class CameraHardwareInterface : public virtual RefBase { +public: + virtual ~CameraHardwareInterface() { } + + /** Return the IMemoryHeap for the preview image heap */ + virtual sp<IMemoryHeap> getPreviewHeap() const = 0; + + /** Return the IMemoryHeap for the raw image heap */ + virtual sp<IMemoryHeap> getRawHeap() const = 0; + + /** + * Start preview mode. When a preview image is available + * preview_callback is called with the user parameter. The + * call back parameter may be null. + */ + virtual status_t startPreview(preview_callback cb, void* user) = 0; + /** + * Only used if overlays are used for camera preview. + */ + virtual bool useOverlay() {return false;} + virtual status_t setOverlay(const sp<Overlay> &overlay) {return BAD_VALUE;} + + /** + * Stop a previously started preview. + */ + virtual void stopPreview() = 0; + + /** + * Returns true if preview is enabled. + */ + virtual bool previewEnabled() = 0; + + /** + * Start record mode. When a record image is available recording_callback() + * is called with the user parameter. Every record frame must be released + * by calling releaseRecordingFrame(). + */ + virtual status_t startRecording(recording_callback cb, void* user) = 0; + + /** + * Stop a previously started recording. + */ + virtual void stopRecording() = 0; + + /** + * Returns true if recording is enabled. + */ + virtual bool recordingEnabled() = 0; + + /** + * Release a record frame previously returned by the recording_callback() + * passed to startRecord(). + */ + virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0; + + /** + * Start auto focus, the callback routine is called + * once when focusing is complete. autoFocus() will + * be called again if another auto focus is needed. + */ + virtual status_t autoFocus(autofocus_callback, + void* user) = 0; + + /** + * Take a picture. The raw_callback is called when + * the uncompressed image is available. The jpeg_callback + * is called when the compressed image is available. These + * call backs may be null. The user parameter is passed + * to each of the call back routines. + */ + virtual status_t takePicture(shutter_callback, + raw_callback, + jpeg_callback, + void* user) = 0; + + /** + * Cancel a picture that was started with takePicture. You may cancel any + * of the shutter, raw, or jpeg callbacks. Calling this method when no + * picture is being taken is a no-op. + */ + virtual status_t cancelPicture(bool cancel_shutter, + bool cancel_raw, + bool cancel_jpeg) = 0; + + /** Set the camera parameters. */ + virtual status_t setParameters(const CameraParameters& params) = 0; + + /** Return the camera parameters. */ + virtual CameraParameters getParameters() const = 0; + + /** + * Release the hardware resources owned by this object. Note that this is + * *not* done in the destructor. + */ + virtual void release() = 0; + + /** + * Dump state of the camera hardware + */ + virtual status_t dump(int fd, const Vector<String16>& args) const = 0; +}; + +/** factory function to instantiate a camera hardware object */ +extern "C" sp<CameraHardwareInterface> openCameraHardware(); + +}; // namespace android + +#endif diff --git a/include/ui/CameraParameters.h b/include/ui/CameraParameters.h new file mode 100644 index 0000000..9ca1806 --- /dev/null +++ b/include/ui/CameraParameters.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_CAMERA_PARAMETERS_H +#define ANDROID_HARDWARE_CAMERA_PARAMETERS_H + +#include <utils/KeyedVector.h> +#include <utils/String8.h> + +namespace android { + +class CameraParameters +{ +public: + CameraParameters(); + CameraParameters(const String8 ¶ms) { unflatten(params); } + ~CameraParameters(); + + enum { + CAMERA_ORIENTATION_UNKNOWN = 0, + CAMERA_ORIENTATION_PORTRAIT = 1, + CAMERA_ORIENTATION_LANDSCAPE = 2, + }; + + String8 flatten() const; + void unflatten(const String8 ¶ms); + + void set(const char *key, const char *value); + void set(const char *key, int value); + const char *get(const char *key) const; + int getInt(const char *key) const; + + /* preview-size=176x144 */ + void setPreviewSize(int width, int height); + void getPreviewSize(int *width, int *height) const; + + /* preview-fps=15 */ + void setPreviewFrameRate(int fps); + int getPreviewFrameRate() const; + + /* preview-format=rgb565|yuv422 */ + void setPreviewFormat(const char *format); + const char *getPreviewFormat() const; + + /* picture-size=1024x768 */ + void setPictureSize(int width, int height); + void getPictureSize(int *width, int *height) const; + + /* picture-format=yuv422|jpeg */ + void setPictureFormat(const char *format); + const char *getPictureFormat() const; + + int getOrientation() const; + void setOrientation(int orientation); + + void dump() const; + status_t dump(int fd, const Vector<String16>& args) const; + +private: + DefaultKeyedVector<String8,String8> mMap; +}; + + +}; // namespace android + +#endif diff --git a/include/ui/DisplayInfo.h b/include/ui/DisplayInfo.h new file mode 100644 index 0000000..c419efe --- /dev/null +++ b/include/ui/DisplayInfo.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef ANDROID_UI_DISPLAY_INFO_H +#define ANDROID_UI_DISPLAY_INFO_H + +#include <stdint.h> +#include <sys/types.h> + +#include <ui/PixelFormat.h> + +namespace android { + +struct DisplayInfo { + uint32_t w; + uint32_t h; + PixelFormatInfo pixelFormatInfo; + uint8_t orientation; + uint8_t reserved[3]; + float fps; + float density; + float xdpi; + float ydpi; +}; + +}; // namespace android + +#endif // ANDROID_COMPOSER_DISPLAY_INFO_H + diff --git a/include/ui/EGLDisplaySurface.h b/include/ui/EGLDisplaySurface.h new file mode 100644 index 0000000..a8b5853 --- /dev/null +++ b/include/ui/EGLDisplaySurface.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EGL_DISPLAY_SURFACE_H +#define ANDROID_EGL_DISPLAY_SURFACE_H + +#include <stdint.h> +#include <sys/types.h> + +#include <utils/Timers.h> + +#include <ui/EGLNativeSurface.h> + +#include <pixelflinger/pixelflinger.h> +#include <linux/fb.h> + +#include <EGL/egl.h> + +struct copybit_device_t; +struct copybit_image_t; + +// --------------------------------------------------------------------------- +namespace android { +// --------------------------------------------------------------------------- + +class Region; +class Rect; + +class EGLDisplaySurface : public EGLNativeSurface<EGLDisplaySurface> +{ +public: + EGLDisplaySurface(); + ~EGLDisplaySurface(); + + int32_t getPageFlipCount() const; + void copyFrontToBack(const Region& copyback); + void copyFrontToImage(const copybit_image_t& dst); + void copyBackToImage(const copybit_image_t& dst); + + void setSwapRectangle(int l, int t, int w, int h); + +private: + static void hook_incRef(NativeWindowType window); + static void hook_decRef(NativeWindowType window); + static uint32_t hook_swapBuffers(NativeWindowType window); + + uint32_t swapBuffers(); + + status_t mapFrameBuffer(); + + enum { + PAGE_FLIP = 0x00000001 + }; + GGLSurface mFb[2]; + int mIndex; + uint32_t mFlags; + size_t mSize; + fb_var_screeninfo mInfo; + fb_fix_screeninfo mFinfo; + int32_t mPageFlipCount; + nsecs_t mTime; + int32_t mSwapCount; + nsecs_t mSleep; + uint32_t mFeatureFlags; + copybit_device_t* mBlitEngine; +}; + +// --------------------------------------------------------------------------- +}; // namespace android +// --------------------------------------------------------------------------- + +#endif // ANDROID_EGL_DISPLAY_SURFACE_H + diff --git a/include/ui/EGLNativeSurface.h b/include/ui/EGLNativeSurface.h new file mode 100644 index 0000000..7964e7c --- /dev/null +++ b/include/ui/EGLNativeSurface.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EGL_NATIVE_SURFACE_H +#define ANDROID_EGL_NATIVE_SURFACE_H + +#include <stdint.h> +#include <sys/types.h> + +#include <cutils/atomic.h> +#include <utils/RefBase.h> + +#include <EGL/eglnatives.h> + +// --------------------------------------------------------------------------- +namespace android { +// --------------------------------------------------------------------------- + +template <class TYPE> +class EGLNativeSurface : public egl_native_window_t, public LightRefBase<TYPE> +{ +public: + EGLNativeSurface() { + memset(egl_native_window_t::reserved, 0, + sizeof(egl_native_window_t::reserved)); + memset(egl_native_window_t::reserved_proc, 0, + sizeof(egl_native_window_t::reserved_proc)); + memset(egl_native_window_t::oem, 0, + sizeof(egl_native_window_t::oem)); + } +protected: + EGLNativeSurface& operator = (const EGLNativeSurface& rhs); + EGLNativeSurface(const EGLNativeSurface& rhs); + inline ~EGLNativeSurface() { }; +}; + +// --------------------------------------------------------------------------- +}; // namespace android +// --------------------------------------------------------------------------- + +#endif // ANDROID_EGL_SURFACE_H + diff --git a/include/ui/EGLNativeWindowSurface.h b/include/ui/EGLNativeWindowSurface.h new file mode 100644 index 0000000..3494234 --- /dev/null +++ b/include/ui/EGLNativeWindowSurface.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EGL_NATIVE_WINDOW_SURFACE_H +#define ANDROID_EGL_NATIVE_WINDOW_SURFACE_H + +#include <stdint.h> +#include <sys/types.h> +#include <ui/EGLNativeSurface.h> +#include <EGL/egl.h> + +// --------------------------------------------------------------------------- +namespace android { +// --------------------------------------------------------------------------- + +class Surface; + +class EGLNativeWindowSurface : public EGLNativeSurface<EGLNativeWindowSurface> +{ +public: + EGLNativeWindowSurface(const sp<Surface>& surface); + ~EGLNativeWindowSurface(); + + void setSwapRectangle(int l, int t, int w, int h); + +private: + static void hook_incRef(NativeWindowType window); + static void hook_decRef(NativeWindowType window); + static uint32_t hook_swapBuffers(NativeWindowType window); + static void hook_connect(NativeWindowType window); + static void hook_disconnect(NativeWindowType window); + + uint32_t swapBuffers(); + void connect(); + void disconnect(); + + sp<Surface> mSurface; + bool mConnected; +}; + +// --------------------------------------------------------------------------- +}; // namespace android +// --------------------------------------------------------------------------- + +#endif // ANDROID_EGL_NATIVE_WINDOW_SURFACE_H + diff --git a/include/ui/EventHub.h b/include/ui/EventHub.h new file mode 100644 index 0000000..3848d8c --- /dev/null +++ b/include/ui/EventHub.h @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2005 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +#ifndef _RUNTIME_EVENT_HUB_H +#define _RUNTIME_EVENT_HUB_H + +#include <utils/String8.h> +#include <utils/threads.h> +#include <utils.h> + +#include <linux/input.h> + +struct pollfd; + +namespace android { + +class KeyLayoutMap; + +/* + * Grand Central Station for events. With a single call to waitEvent() + * you can wait for: + * - input events from the keypad of a real device + * - input events and meta-events (e.g. "quit") from the simulator + * - synthetic events from the runtime (e.g. "URL fetch completed") + * - real or forged "vsync" events + * + * Do not instantiate this class. Instead, call startUp(). + */ +class EventHub : public RefBase +{ +public: + EventHub(); + + status_t errorCheck() const; + + // bit fields for classes of devices. + enum { + CLASS_KEYBOARD = 0x00000001, + CLASS_ALPHAKEY = 0x00000002, + CLASS_TOUCHSCREEN = 0x00000004, + CLASS_TRACKBALL = 0x00000008 + }; + uint32_t getDeviceClasses(int32_t deviceId) const; + + String8 getDeviceName(int32_t deviceId) const; + + int getAbsoluteInfo(int32_t deviceId, int axis, int *outMinValue, + int* outMaxValue, int* outFlat, int* outFuzz) const; + + int getSwitchState(int sw) const; + int getSwitchState(int32_t deviceId, int sw) const; + + int getScancodeState(int key) const; + int getScancodeState(int32_t deviceId, int key) const; + + int getKeycodeState(int key) const; + int getKeycodeState(int32_t deviceId, int key) const; + + // special type codes when devices are added/removed. + enum { + DEVICE_ADDED = 0x10000000, + DEVICE_REMOVED = 0x20000000 + }; + + // examine key input devices for specific framework keycode support + bool hasKeys(size_t numCodes, int32_t* keyCodes, uint8_t* outFlags); + + virtual bool getEvent(int32_t* outDeviceId, int32_t* outType, + int32_t* outScancode, int32_t* outKeycode, uint32_t *outFlags, + int32_t* outValue, nsecs_t* outWhen); + +protected: + virtual ~EventHub(); + virtual void onFirstRef(); + +private: + bool openPlatformInput(void); + int32_t convertDeviceKey_TI_P2(int code); + + int open_device(const char *device); + int close_device(const char *device); + int scan_dir(const char *dirname); + int read_notify(int nfd); + + status_t mError; + + struct device_t { + const int32_t id; + const String8 path; + String8 name; + uint32_t classes; + uint8_t* keyBitmask; + KeyLayoutMap* layoutMap; + String8 keylayoutFilename; + device_t* next; + + device_t(int32_t _id, const char* _path); + ~device_t(); + }; + + device_t* getDevice(int32_t deviceId) const; + + // Protect all internal state. + mutable Mutex mLock; + + bool mHaveFirstKeyboard; + int32_t mFirstKeyboardId; // the API is that the build in keyboard is id 0, so map it + + struct device_ent { + device_t* device; + uint32_t seq; + }; + device_ent *mDevicesById; + int mNumDevicesById; + + device_t *mOpeningDevices; + device_t *mClosingDevices; + + device_t **mDevices; + struct pollfd *mFDs; + int mFDCount; + + // device ids that report particular switches. +#ifdef EV_SW + int32_t mSwitches[SW_MAX+1]; +#endif +}; + +}; // namespace android + +#endif // _RUNTIME_EVENT_HUB_H diff --git a/include/ui/ICamera.h b/include/ui/ICamera.h new file mode 100644 index 0000000..241fb63 --- /dev/null +++ b/include/ui/ICamera.h @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_ICAMERA_H +#define ANDROID_HARDWARE_ICAMERA_H + +#include <utils/RefBase.h> +#include <utils/IInterface.h> +#include <utils/Parcel.h> +#include <ui/ISurface.h> +#include <utils/IMemory.h> +#include <utils/String8.h> +#include <ui/Camera.h> + +namespace android { + +class ICameraClient; + +class ICamera: public IInterface +{ +public: + DECLARE_META_INTERFACE(Camera); + + virtual void disconnect() = 0; + + // connect new client with existing camera remote + virtual status_t connect(const sp<ICameraClient>& client) = 0; + + // prevent other processes from using this ICamera interface + virtual status_t lock() = 0; + + // allow other processes to use this ICamera interface + virtual status_t unlock() = 0; + + // pass the buffered ISurface to the camera service + virtual status_t setPreviewDisplay(const sp<ISurface>& surface) = 0; + + // set the preview callback flag to affect how the received frames from + // preview are handled. + virtual void setPreviewCallbackFlag(int flag) = 0; + + // start preview mode, must call setPreviewDisplay first + virtual status_t startPreview() = 0; + + // stop preview mode + virtual void stopPreview() = 0; + + // get preview state + virtual bool previewEnabled() = 0; + + // start recording mode + virtual status_t startRecording() = 0; + + // stop recording mode + virtual void stopRecording() = 0; + + // get recording state + virtual bool recordingEnabled() = 0; + + // release a recording frame + virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0; + + // auto focus + virtual status_t autoFocus() = 0; + + // take a picture + virtual status_t takePicture() = 0; + + // set preview/capture parameters - key/value pairs + virtual status_t setParameters(const String8& params) = 0; + + // get preview/capture parameters - key/value pairs + virtual String8 getParameters() const = 0; +}; + +// ---------------------------------------------------------------------------- + +class BnCamera: public BnInterface<ICamera> +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +}; // namespace android + +#endif diff --git a/include/ui/ICameraClient.h b/include/ui/ICameraClient.h new file mode 100644 index 0000000..73b951c --- /dev/null +++ b/include/ui/ICameraClient.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_ICAMERA_APP_H +#define ANDROID_HARDWARE_ICAMERA_APP_H + +#include <utils/RefBase.h> +#include <utils/IInterface.h> +#include <utils/Parcel.h> +#include <utils/IMemory.h> + +namespace android { + +class ICameraClient: public IInterface +{ +public: + DECLARE_META_INTERFACE(CameraClient); + + virtual void shutterCallback() = 0; + virtual void rawCallback(const sp<IMemory>& picture) = 0; + virtual void jpegCallback(const sp<IMemory>& picture) = 0; + virtual void previewCallback(const sp<IMemory>& frame) = 0; + virtual void errorCallback(status_t error) = 0; + virtual void autoFocusCallback(bool focused) = 0; + virtual void recordingCallback(const sp<IMemory>& frame) = 0; + +}; + +// ---------------------------------------------------------------------------- + +class BnCameraClient: public BnInterface<ICameraClient> +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +}; // namespace android + +#endif diff --git a/include/ui/ICameraService.h b/include/ui/ICameraService.h new file mode 100644 index 0000000..dfd8923 --- /dev/null +++ b/include/ui/ICameraService.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_ICAMERASERVICE_H +#define ANDROID_HARDWARE_ICAMERASERVICE_H + +#include <utils/RefBase.h> +#include <utils/IInterface.h> +#include <utils/Parcel.h> + +#include <ui/ICameraClient.h> +#include <ui/ICamera.h> + +namespace android { + +class ICameraService : public IInterface +{ +protected: + enum { + CONNECT = IBinder::FIRST_CALL_TRANSACTION, + }; + +public: + DECLARE_META_INTERFACE(CameraService); + + virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient) = 0; +}; + +// ---------------------------------------------------------------------------- + +class BnCameraService: public BnInterface<ICameraService> +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +}; // namespace android + +#endif diff --git a/include/ui/IOverlay.h b/include/ui/IOverlay.h new file mode 100644 index 0000000..699b1b0 --- /dev/null +++ b/include/ui/IOverlay.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_IOVERLAY_H +#define ANDROID_IOVERLAY_H + +#include <stdint.h> +#include <sys/types.h> + +#include <utils/Errors.h> +#include <utils/IInterface.h> +#include <utils/RefBase.h> +#include <ui/PixelFormat.h> + +namespace android { + +class IOverlay : public IInterface +{ +public: + DECLARE_META_INTERFACE(Overlay); + + virtual void destroy() = 0; // one-way +}; + +// ---------------------------------------------------------------------------- + +class BnOverlay : public BnInterface<IOverlay> +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +// ---------------------------------------------------------------------------- + +}; // namespace android + +#endif // ANDROID_IOVERLAY_H diff --git a/include/ui/ISurface.h b/include/ui/ISurface.h new file mode 100644 index 0000000..87b320f --- /dev/null +++ b/include/ui/ISurface.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_ISURFACE_H +#define ANDROID_ISURFACE_H + +#include <stdint.h> +#include <sys/types.h> + +#include <utils/Errors.h> +#include <utils/IInterface.h> +#include <utils/RefBase.h> +#include <ui/PixelFormat.h> + +#include <hardware/hardware.h> + +namespace android { + +typedef int32_t SurfaceID; + +class IMemoryHeap; +class OverlayRef; + +class ISurface : public IInterface +{ +protected: + enum { + REGISTER_BUFFERS = IBinder::FIRST_CALL_TRANSACTION, + UNREGISTER_BUFFERS, + POST_BUFFER, // one-way transaction + CREATE_OVERLAY, + }; + +public: + DECLARE_META_INTERFACE(Surface); + + + class BufferHeap { + public: + enum { + /* rotate source image 90 degrees */ + ROT_90 = HAL_TRANSFORM_ROT_90, + }; + BufferHeap(); + + BufferHeap(uint32_t w, uint32_t h, + int32_t hor_stride, int32_t ver_stride, + PixelFormat format, const sp<IMemoryHeap>& heap); + + BufferHeap(uint32_t w, uint32_t h, + int32_t hor_stride, int32_t ver_stride, + PixelFormat format, uint32_t transform, uint32_t flags, + const sp<IMemoryHeap>& heap); + + ~BufferHeap(); + + uint32_t w; + uint32_t h; + int32_t hor_stride; + int32_t ver_stride; + PixelFormat format; + uint32_t transform; + uint32_t flags; + sp<IMemoryHeap> heap; + }; + + virtual status_t registerBuffers(const BufferHeap& buffers) = 0; + + virtual void postBuffer(ssize_t offset) = 0; // one-way + + virtual void unregisterBuffers() = 0; + + virtual sp<OverlayRef> createOverlay( + uint32_t w, uint32_t h, int32_t format) = 0; +}; + +// ---------------------------------------------------------------------------- + +class BnSurface : public BnInterface<ISurface> +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +// ---------------------------------------------------------------------------- + +}; // namespace android + +#endif // ANDROID_ISURFACE_H diff --git a/include/ui/ISurfaceComposer.h b/include/ui/ISurfaceComposer.h new file mode 100644 index 0000000..f9eeb30 --- /dev/null +++ b/include/ui/ISurfaceComposer.h @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_ISURFACE_COMPOSER_H +#define ANDROID_ISURFACE_COMPOSER_H + +#include <stdint.h> +#include <sys/types.h> + +#include <utils/RefBase.h> +#include <utils/Errors.h> +#include <utils/IInterface.h> + +#include <ui/PixelFormat.h> +#include <ui/ISurfaceFlingerClient.h> + +namespace android { + +// ---------------------------------------------------------------------------- + +class DisplayInfo; +class IGPUCallback; + +class ISurfaceComposer : public IInterface +{ +public: + DECLARE_META_INTERFACE(SurfaceComposer); + + enum { // (keep in sync with Surface.java) + eHidden = 0x00000004, + eGPU = 0x00000008, + eHardware = 0x00000010, + eDestroyBackbuffer = 0x00000020, + eSecure = 0x00000080, + eNonPremultiplied = 0x00000100, + ePushBuffers = 0x00000200, + + eFXSurfaceNormal = 0x00000000, + eFXSurfaceBlur = 0x00010000, + eFXSurfaceDim = 0x00020000, + eFXSurfaceMask = 0x000F0000, + }; + + enum { + ePositionChanged = 0x00000001, + eLayerChanged = 0x00000002, + eSizeChanged = 0x00000004, + eAlphaChanged = 0x00000008, + eMatrixChanged = 0x00000010, + eTransparentRegionChanged = 0x00000020, + eVisibilityChanged = 0x00000040, + eFreezeTintChanged = 0x00000080, + eDestroyed = 0x00000100 + }; + + enum { + eLayerHidden = 0x01, + eLayerFrozen = 0x02, + eLayerDither = 0x04, + eLayerFilter = 0x08, + eLayerBlurFreeze = 0x10 + }; + + enum { + eOrientationDefault = 0, + eOrientation90 = 1, + eOrientation180 = 2, + eOrientation270 = 3, + eOrientationSwapMask = 0x01 + }; + + /* create connection with surface flinger, requires + * ACCESS_SURFACE_FLINGER permission + */ + + virtual sp<ISurfaceFlingerClient> createConnection() = 0; + + /* retrieve the control block */ + virtual sp<IMemory> getCblk() const = 0; + + /* open/close transactions. recquires ACCESS_SURFACE_FLINGER permission */ + virtual void openGlobalTransaction() = 0; + virtual void closeGlobalTransaction() = 0; + + /* [un]freeze display. recquires ACCESS_SURFACE_FLINGER permission */ + virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags) = 0; + virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags) = 0; + + /* Set display orientation. recquires ACCESS_SURFACE_FLINGER permission */ + virtual int setOrientation(DisplayID dpy, int orientation) = 0; + + /* signal that we're done booting. + * recquires ACCESS_SURFACE_FLINGER permission + */ + virtual void bootFinished() = 0; + + /* get access to the GPU. Access is relinquished when releasing regs */ + struct gpu_info_t { + struct gpu_region_t { + sp<IMemory> region; + size_t reserved; + }; + sp<IMemory> regs; + size_t count; + gpu_region_t regions[2]; + }; + virtual status_t requestGPU( + const sp<IGPUCallback>& callback, + gpu_info_t* gpu) = 0; + + /* take the gpu back from any apps using it. They'll get a + * EGL_CONTEXT_LOST error */ + virtual status_t revokeGPU() = 0; + + /* Signal surfaceflinger that there might be some work to do + * This is an ASYNCHRONOUS call. + */ + virtual void signal() const = 0; +}; + +class IGPUCallback : public IInterface +{ +public: + DECLARE_META_INTERFACE(GPUCallback); + virtual void gpuLost() = 0; //one-way +}; + +// ---------------------------------------------------------------------------- + +class BnSurfaceComposer : public BnInterface<ISurfaceComposer> +{ +public: + enum { + // Note: BOOT_FINISHED must remain this value, it is called from + // Java by ActivityManagerService. + BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION, + CREATE_CONNECTION, + GET_CBLK, + OPEN_GLOBAL_TRANSACTION, + CLOSE_GLOBAL_TRANSACTION, + SET_ORIENTATION, + FREEZE_DISPLAY, + UNFREEZE_DISPLAY, + REQUEST_GPU, + REVOKE_GPU, + SIGNAL + }; + + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +class BnGPUCallback : public BnInterface<IGPUCallback> +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +// ---------------------------------------------------------------------------- + +}; // namespace android + +#endif // ANDROID_ISURFACE_COMPOSER_H diff --git a/include/ui/ISurfaceFlingerClient.h b/include/ui/ISurfaceFlingerClient.h new file mode 100644 index 0000000..5b9361d --- /dev/null +++ b/include/ui/ISurfaceFlingerClient.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_ISURFACE_FLINGER_CLIENT_H +#define ANDROID_ISURFACE_FLINGER_CLIENT_H + +#include <stdint.h> +#include <sys/types.h> + +#include <utils/Errors.h> +#include <utils/IInterface.h> +#include <utils/RefBase.h> + +#include <ui/ISurface.h> + +#include <ui/PixelFormat.h> + +namespace android { + +// ---------------------------------------------------------------------------- + +class Rect; +class Point; +class IMemory; +class ISurface; + +typedef int32_t ClientID; +typedef int32_t DisplayID; + +// ---------------------------------------------------------------------------- + +class layer_state_t; + +class ISurfaceFlingerClient : public IInterface +{ +public: + DECLARE_META_INTERFACE(SurfaceFlingerClient); + + struct surface_data_t { + int32_t token; + int32_t identity; + sp<IMemoryHeap> heap[2]; + status_t readFromParcel(const Parcel& parcel); + status_t writeToParcel(Parcel* parcel) const; + }; + + virtual void getControlBlocks(sp<IMemory>* ctl) const = 0; + + virtual sp<ISurface> createSurface( surface_data_t* data, + int pid, + DisplayID display, + uint32_t w, + uint32_t h, + PixelFormat format, + uint32_t flags) = 0; + + virtual status_t destroySurface(SurfaceID sid) = 0; + + virtual status_t setState(int32_t count, const layer_state_t* states) = 0; +}; + +// ---------------------------------------------------------------------------- + +class BnSurfaceFlingerClient : public BnInterface<ISurfaceFlingerClient> +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +// ---------------------------------------------------------------------------- + +}; // namespace android + +#endif // ANDROID_ISURFACE_FLINGER_CLIENT_H diff --git a/include/ui/KeyCharacterMap.h b/include/ui/KeyCharacterMap.h new file mode 100644 index 0000000..bad2cf8 --- /dev/null +++ b/include/ui/KeyCharacterMap.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _UI_KEY_CHARACTER_MAP_H +#define _UI_KEY_CHARACTER_MAP_H + +#include <stdint.h> +#include <utils/Vector.h> + +using namespace android; + +class KeyCharacterMap +{ +public: + ~KeyCharacterMap(); + + // see the javadoc for android.text.method.KeyCharacterMap for what + // these do + unsigned short get(int keycode, int meta); + unsigned short getNumber(int keycode); + unsigned short getMatch(int keycode, const unsigned short* chars, + int charsize, uint32_t modifiers); + unsigned short getDisplayLabel(int keycode); + bool getKeyData(int keycode, unsigned short *displayLabel, + unsigned short *number, unsigned short* results); + inline unsigned int getKeyboardType() { return m_type; } + bool getEvents(uint16_t* chars, size_t len, + Vector<int32_t>* keys, Vector<uint32_t>* modifiers); + + static KeyCharacterMap* load(int id); + + enum { + NUMERIC = 1, + Q14 = 2, + QWERTY = 3 // or AZERTY or whatever + }; + +#define META_MASK 3 + +private: + struct Key + { + int32_t keycode; + uint16_t display_label; + uint16_t number; + uint16_t data[META_MASK + 1]; + }; + + KeyCharacterMap(); + static KeyCharacterMap* try_file(const char* filename); + Key* find_key(int keycode); + bool find_char(uint16_t c, uint32_t* key, uint32_t* mods); + + unsigned int m_type; + unsigned int m_keyCount; + Key* m_keys; +}; + +#endif // _UI_KEY_CHARACTER_MAP_H diff --git a/include/ui/KeycodeLabels.h b/include/ui/KeycodeLabels.h new file mode 100644 index 0000000..efa6d2b --- /dev/null +++ b/include/ui/KeycodeLabels.h @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _UI_KEYCODE_LABELS_H +#define _UI_KEYCODE_LABELS_H + +struct KeycodeLabel { + const char *literal; + int value; +}; + +static const KeycodeLabel KEYCODES[] = { + { "SOFT_LEFT", 1 }, + { "SOFT_RIGHT", 2 }, + { "HOME", 3 }, + { "BACK", 4 }, + { "CALL", 5 }, + { "ENDCALL", 6 }, + { "0", 7 }, + { "1", 8 }, + { "2", 9 }, + { "3", 10 }, + { "4", 11 }, + { "5", 12 }, + { "6", 13 }, + { "7", 14 }, + { "8", 15 }, + { "9", 16 }, + { "STAR", 17 }, + { "POUND", 18 }, + { "DPAD_UP", 19 }, + { "DPAD_DOWN", 20 }, + { "DPAD_LEFT", 21 }, + { "DPAD_RIGHT", 22 }, + { "DPAD_CENTER", 23 }, + { "VOLUME_UP", 24 }, + { "VOLUME_DOWN", 25 }, + { "POWER", 26 }, + { "CAMERA", 27 }, + { "CLEAR", 28 }, + { "A", 29 }, + { "B", 30 }, + { "C", 31 }, + { "D", 32 }, + { "E", 33 }, + { "F", 34 }, + { "G", 35 }, + { "H", 36 }, + { "I", 37 }, + { "J", 38 }, + { "K", 39 }, + { "L", 40 }, + { "M", 41 }, + { "N", 42 }, + { "O", 43 }, + { "P", 44 }, + { "Q", 45 }, + { "R", 46 }, + { "S", 47 }, + { "T", 48 }, + { "U", 49 }, + { "V", 50 }, + { "W", 51 }, + { "X", 52 }, + { "Y", 53 }, + { "Z", 54 }, + { "COMMA", 55 }, + { "PERIOD", 56 }, + { "ALT_LEFT", 57 }, + { "ALT_RIGHT", 58 }, + { "SHIFT_LEFT", 59 }, + { "SHIFT_RIGHT", 60 }, + { "TAB", 61 }, + { "SPACE", 62 }, + { "SYM", 63 }, + { "EXPLORER", 64 }, + { "ENVELOPE", 65 }, + { "ENTER", 66 }, + { "DEL", 67 }, + { "GRAVE", 68 }, + { "MINUS", 69 }, + { "EQUALS", 70 }, + { "LEFT_BRACKET", 71 }, + { "RIGHT_BRACKET", 72 }, + { "BACKSLASH", 73 }, + { "SEMICOLON", 74 }, + { "APOSTROPHE", 75 }, + { "SLASH", 76 }, + { "AT", 77 }, + { "NUM", 78 }, + { "HEADSETHOOK", 79 }, + { "FOCUS", 80 }, + { "PLUS", 81 }, + { "MENU", 82 }, + { "NOTIFICATION", 83 }, + { "SEARCH", 84 }, + { "PLAYPAUSE", 85 }, + { "STOP", 86 }, + { "NEXTSONG", 87 }, + { "PREVIOUSSONG", 88 }, + { "REWIND", 89 }, + { "FORWARD", 90 }, + { "MUTE", 91 }, + + // NOTE: If you add a new keycode here you must also add it to: + // (enum KeyCode, in this file) + // frameworks/base/core/java/android/view/KeyEvent.java + // tools/puppet_master/PuppetMaster.nav_keys.py + // frameworks/base/core/res/res/values/attrs.xml + + { NULL, 0 } +}; + +// These constants need to match the above mappings. +typedef enum KeyCode { + kKeyCodeUnknown = 0, + + kKeyCodeSoftLeft = 1, + kKeyCodeSoftRight = 2, + kKeyCodeHome = 3, + kKeyCodeBack = 4, + kKeyCodeCall = 5, + kKeyCodeEndCall = 6, + kKeyCode0 = 7, + kKeyCode1 = 8, + kKeyCode2 = 9, + kKeyCode3 = 10, + kKeyCode4 = 11, + kKeyCode5 = 12, + kKeyCode6 = 13, + kKeyCode7 = 14, + kKeyCode8 = 15, + kKeyCode9 = 16, + kKeyCodeStar = 17, + kKeyCodePound = 18, + kKeyCodeDpadUp = 19, + kKeyCodeDpadDown = 20, + kKeyCodeDpadLeft = 21, + kKeyCodeDpadRight = 22, + kKeyCodeDpadCenter = 23, + kKeyCodeVolumeUp = 24, + kKeyCodeVolumeDown = 25, + kKeyCodePower = 26, + kKeyCodeCamera = 27, + kKeyCodeClear = 28, + kKeyCodeA = 29, + kKeyCodeB = 30, + kKeyCodeC = 31, + kKeyCodeD = 32, + kKeyCodeE = 33, + kKeyCodeF = 34, + kKeyCodeG = 35, + kKeyCodeH = 36, + kKeyCodeI = 37, + kKeyCodeJ = 38, + kKeyCodeK = 39, + kKeyCodeL = 40, + kKeyCodeM = 41, + kKeyCodeN = 42, + kKeyCodeO = 43, + kKeyCodeP = 44, + kKeyCodeQ = 45, + kKeyCodeR = 46, + kKeyCodeS = 47, + kKeyCodeT = 48, + kKeyCodeU = 49, + kKeyCodeV = 50, + kKeyCodeW = 51, + kKeyCodeX = 52, + kKeyCodeY = 53, + kKeyCodeZ = 54, + kKeyCodeComma = 55, + kKeyCodePeriod = 56, + kKeyCodeAltLeft = 57, + kKeyCodeAltRight = 58, + kKeyCodeShiftLeft = 59, + kKeyCodeShiftRight = 60, + kKeyCodeTab = 61, + kKeyCodeSpace = 62, + kKeyCodeSym = 63, + kKeyCodeExplorer = 64, + kKeyCodeEnvelope = 65, + kKeyCodeNewline = 66, + kKeyCodeDel = 67, + kKeyCodeGrave = 68, + kKeyCodeMinus = 69, + kKeyCodeEquals = 70, + kKeyCodeLeftBracket = 71, + kKeyCodeRightBracket = 72, + kKeyCodeBackslash = 73, + kKeyCodeSemicolon = 74, + kKeyCodeApostrophe = 75, + kKeyCodeSlash = 76, + kKeyCodeAt = 77, + kKeyCodeNum = 78, + kKeyCodeHeadSetHook = 79, + kKeyCodeFocus = 80, + kKeyCodePlus = 81, + kKeyCodeMenu = 82, + kKeyCodeNotification = 83, + kKeyCodeSearch = 84, + kKeyCodePlayPause = 85, + kKeyCodeStop = 86, + kKeyCodeNextSong = 87, + kKeyCodePreviousSong = 88, + kKeyCodeRewind = 89, + kKeyCodeForward = 90, + kKeyCodeMute = 91 +} KeyCode; + +static const KeycodeLabel FLAGS[] = { + { "WAKE", 0x00000001 }, + { "WAKE_DROPPED", 0x00000002 }, + { "SHIFT", 0x00000004 }, + { "CAPS_LOCK", 0x00000008 }, + { "ALT", 0x00000010 }, + { "ALT_GR", 0x00000020 }, + { "MENU", 0x00000040 }, + { "LAUNCHER", 0x00000080 }, + { NULL, 0 } +}; + +#endif // _UI_KEYCODE_LABELS_H diff --git a/include/ui/Overlay.h b/include/ui/Overlay.h new file mode 100644 index 0000000..66514b4 --- /dev/null +++ b/include/ui/Overlay.h @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_OVERLAY_H +#define ANDROID_OVERLAY_H + +#include <stdint.h> +#include <sys/types.h> + +#include <utils/Errors.h> +#include <utils/IInterface.h> +#include <utils/RefBase.h> +#include <utils/threads.h> + +#include <ui/PixelFormat.h> +#include <ui/IOverlay.h> + +#include <hardware/overlay.h> + +namespace android { + +class IMemory; +class IMemoryHeap; + +// ---------------------------------------------------------------------------- + +class OverlayRef : public LightRefBase<OverlayRef> +{ +public: + OverlayRef(overlay_handle_t, const sp<IOverlay>&, + uint32_t w, uint32_t h, int32_t f, uint32_t ws, uint32_t hs); + + static sp<OverlayRef> readFromParcel(const Parcel& data); + static status_t writeToParcel(Parcel* reply, const sp<OverlayRef>& o); + +private: + friend class LightRefBase<OverlayRef>; + friend class Overlay; + + OverlayRef(); + virtual ~OverlayRef(); + + overlay_handle_t mOverlayHandle; + sp<IOverlay> mOverlayChannel; + uint32_t mWidth; + uint32_t mHeight; + int32_t mFormat; + int32_t mWidthStride; + int32_t mHeightStride; + bool mOwnHandle; +}; + +// ---------------------------------------------------------------------------- + +class Overlay : public virtual RefBase +{ +public: + Overlay(const sp<OverlayRef>& overlayRef); + + /* destroys this overlay */ + void destroy(); + + /* get the HAL handle for this overlay */ + overlay_handle_t getHandleRef() const; + + /* blocks until an overlay buffer is available and return that buffer. */ + status_t dequeueBuffer(overlay_buffer_t* buffer); + + /* release the overlay buffer and post it */ + status_t queueBuffer(overlay_buffer_t buffer); + + /* returns the address of a given buffer if supported, NULL otherwise. */ + void* getBufferAddress(overlay_buffer_t buffer); + + /* get physical informations about the overlay */ + uint32_t getWidth() const; + uint32_t getHeight() const; + int32_t getFormat() const; + int32_t getWidthStride() const; + int32_t getHeightStride() const; + int32_t getBufferCount() const; + status_t getStatus() const; + +private: + virtual ~Overlay(); + + sp<OverlayRef> mOverlayRef; + overlay_data_device_t *mOverlayData; + status_t mStatus; +}; + +// ---------------------------------------------------------------------------- + +}; // namespace android + +#endif // ANDROID_OVERLAY_H diff --git a/include/ui/PixelFormat.h b/include/ui/PixelFormat.h new file mode 100644 index 0000000..14af823 --- /dev/null +++ b/include/ui/PixelFormat.h @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2005 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// + +// Pixel formats used across the system. +// These formats might not all be supported by all renderers, for instance +// skia or SurfaceFlinger are not required to support all of these formats +// (either as source or destination) + +// XXX: we should consolidate these formats and skia's + +#ifndef UI_PIXELFORMAT_H +#define UI_PIXELFORMAT_H + +#include <stdint.h> +#include <sys/types.h> +#include <utils/Errors.h> +#include <pixelflinger/format.h> + +namespace android { + +enum { + // + // these constants need to match those + // in graphics/PixelFormat.java & pixelflinger/format.h + // + PIXEL_FORMAT_UNKNOWN = 0, + PIXEL_FORMAT_NONE = 0, + + // logical pixel formats used by the SurfaceFlinger ----------------------- + PIXEL_FORMAT_CUSTOM = -4, + // Custom pixel-format described by a PixelFormatInfo structure + + PIXEL_FORMAT_TRANSLUCENT = -3, + // System chooses a format that supports translucency (many alpha bits) + + PIXEL_FORMAT_TRANSPARENT = -2, + // System chooses a format that supports transparency + // (at least 1 alpha bit) + + PIXEL_FORMAT_OPAQUE = -1, + // System chooses an opaque format (no alpha bits required) + + // real pixel formats supported for rendering ----------------------------- + + PIXEL_FORMAT_RGBA_8888 = GGL_PIXEL_FORMAT_RGBA_8888, // 4x8-bit RGBA + PIXEL_FORMAT_RGBX_8888 = GGL_PIXEL_FORMAT_RGBX_8888, // 4x8-bit RGB0 + PIXEL_FORMAT_RGB_888 = GGL_PIXEL_FORMAT_RGB_888, // 3x8-bit RGB + PIXEL_FORMAT_RGB_565 = GGL_PIXEL_FORMAT_RGB_565, // 16-bit RGB + PIXEL_FORMAT_BGRA_8888 = GGL_PIXEL_FORMAT_BGRA_8888, // 4x8-bit BGRA + PIXEL_FORMAT_RGBA_5551 = GGL_PIXEL_FORMAT_RGBA_5551, // 16-bit ARGB + PIXEL_FORMAT_RGBA_4444 = GGL_PIXEL_FORMAT_RGBA_4444, // 16-bit ARGB + PIXEL_FORMAT_A_8 = GGL_PIXEL_FORMAT_A_8, // 8-bit A + PIXEL_FORMAT_L_8 = GGL_PIXEL_FORMAT_L_8, // 8-bit L (R=G=B=L) + PIXEL_FORMAT_LA_88 = GGL_PIXEL_FORMAT_LA_88, // 16-bit LA + PIXEL_FORMAT_RGB_332 = GGL_PIXEL_FORMAT_RGB_332, // 8-bit RGB + + PIXEL_FORMAT_YCbCr_422_SP= GGL_PIXEL_FORMAT_YCbCr_422_SP, + PIXEL_FORMAT_YCbCr_420_SP= GGL_PIXEL_FORMAT_YCbCr_420_SP, + PIXEL_FORMAT_YCbCr_422_P = GGL_PIXEL_FORMAT_YCbCr_422_P, + PIXEL_FORMAT_YCbCr_420_P = GGL_PIXEL_FORMAT_YCbCr_420_P, + PIXEL_FORMAT_YCbCr_422_I = GGL_PIXEL_FORMAT_YCbCr_422_I, + PIXEL_FORMAT_YCbCr_420_I = GGL_PIXEL_FORMAT_YCbCr_420_I, + + // New formats can be added if they're also defined in + // pixelflinger/format.h +}; + +typedef int32_t PixelFormat; + +struct PixelFormatInfo +{ + enum { // components + ALPHA = 1, + RGB = 2, + RGBA = 3, + LUMINANCE = 4, + LUMINANCE_ALPHA = 5, + Y_CB_CR_SP = 6, + Y_CB_CR_P = 7, + Y_CB_CR_I = 8, + }; + + inline PixelFormatInfo() : version(sizeof(PixelFormatInfo)) { } + size_t getScanlineSize(unsigned int width) const; + size_t version; + PixelFormat format; + size_t bytesPerPixel; + size_t bitsPerPixel; + uint8_t h_alpha; + uint8_t l_alpha; + uint8_t h_red; + uint8_t l_red; + uint8_t h_green; + uint8_t l_green; + uint8_t h_blue; + uint8_t l_blue; + uint8_t components; + uint8_t reserved0[3]; + uint32_t reserved1; +}; + +// Consider caching the results of these functions are they're not +// guaranteed to be fast. +ssize_t bytesPerPixel(PixelFormat format); +ssize_t bitsPerPixel(PixelFormat format); +status_t getPixelFormatInfo(PixelFormat format, PixelFormatInfo* info); + +}; // namespace android + +#endif // UI_PIXELFORMAT_H diff --git a/include/ui/Point.h b/include/ui/Point.h new file mode 100644 index 0000000..dbbad1e --- /dev/null +++ b/include/ui/Point.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_UI_POINT +#define ANDROID_UI_POINT + +#include <utils/TypeHelpers.h> + +namespace android { + +class Point +{ +public: + int x; + int y; + + // we don't provide copy-ctor and operator= on purpose + // because we want the compiler generated versions + + // Default constructor doesn't initialize the Point + inline Point() + { + } + + inline Point(int _x, int _y) : x(_x), y(_y) + { + } + + inline bool operator == (const Point& rhs) const { + return (x == rhs.x) && (y == rhs.y); + } + inline bool operator != (const Point& rhs) const { + return !operator == (rhs); + } + + inline bool isOrigin() const { + return !(x|y); + } + + // operator < defines an order which allows to use points in sorted + // vectors. + bool operator < (const Point& rhs) const { + return y<rhs.y || (y==rhs.y && x<rhs.x); + } + + inline Point& operator - () { + x=-x; + y=-y; + return *this; + } + + inline Point& operator += (const Point& rhs) { + x += rhs.x; + y += rhs.y; + return *this; + } + inline Point& operator -= (const Point& rhs) { + x -= rhs.x; + y -= rhs.y; + return *this; + } + + Point operator + (const Point& rhs) const { + return Point(x+rhs.x, y+rhs.y); + } + Point operator - (const Point& rhs) const { + return Point(x-rhs.x, y-rhs.y); + } +}; + +ANDROID_BASIC_TYPES_TRAITS(Point) + +}; // namespace android + +#endif // ANDROID_UI_POINT diff --git a/include/ui/Rect.h b/include/ui/Rect.h new file mode 100644 index 0000000..d232847 --- /dev/null +++ b/include/ui/Rect.h @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_UI_RECT +#define ANDROID_UI_RECT + +#include <utils/TypeHelpers.h> +#include <ui/Point.h> + +namespace android { + +class Rect +{ +public: + int left; + int top; + int right; + int bottom; + + // we don't provide copy-ctor and operator= on purpose + // because we want the compiler generated versions + + inline Rect() + { + } + + inline Rect(int w, int h) + : left(0), top(0), right(w), bottom(h) + { + } + + inline Rect(int l, int t, int r, int b) + : left(l), top(t), right(r), bottom(b) + { + } + + inline Rect(const Point& lt, const Point& rb) + : left(lt.x), top(lt.y), right(rb.x), bottom(rb.y) + { + } + + void makeInvalid(); + + // a valid rectangle has a non negative width and height + inline bool isValid() const { + return (width()>=0) && (height()>=0); + } + + // an empty rect has a zero width or height, or is invalid + inline bool isEmpty() const { + return (width()<=0) || (height()<=0); + } + + inline void set(const Rect& rhs) { + operator = (rhs); + } + + // rectangle's width + inline int width() const { + return right-left; + } + + // rectangle's height + inline int height() const { + return bottom-top; + } + + // returns left-top Point non-const reference, can be assigned + inline Point& leftTop() { + return reinterpret_cast<Point&>(left); + } + // returns right bottom non-const reference, can be assigned + inline Point& rightBottom() { + return reinterpret_cast<Point&>(right); + } + + // the following 4 functions return the 4 corners of the rect as Point + inline const Point& leftTop() const { + return reinterpret_cast<const Point&>(left); + } + inline const Point& rightBottom() const { + return reinterpret_cast<const Point&>(right); + } + Point rightTop() const { + return Point(right, top); + } + Point leftBottom() const { + return Point(left, bottom); + } + + // comparisons + inline bool operator == (const Rect& rhs) const { + return (left == rhs.left) && (top == rhs.top) && + (right == rhs.right) && (bottom == rhs.bottom); + } + + inline bool operator != (const Rect& rhs) const { + return !operator == (rhs); + } + + // operator < defines an order which allows to use rectangles in sorted + // vectors. + bool operator < (const Rect& rhs) const; + + Rect& offsetToOrigin() { + right -= left; + bottom -= top; + left = top = 0; + return *this; + } + Rect& offsetTo(const Point& p) { + return offsetTo(p.x, p.y); + } + Rect& offsetBy(const Point& dp) { + return offsetBy(dp.x, dp.y); + } + Rect& operator += (const Point& rhs) { + return offsetBy(rhs.x, rhs.y); + } + Rect& operator -= (const Point& rhs) { + return offsetBy(-rhs.x, -rhs.y); + } + Rect operator + (const Point& rhs) const; + Rect operator - (const Point& rhs) const; + + void translate(int dx, int dy) { // legacy, don't use. + offsetBy(dx, dy); + } + + Rect& offsetTo(int x, int y); + Rect& offsetBy(int x, int y); + bool intersect(const Rect& with, Rect* result) const; +}; + +ANDROID_BASIC_TYPES_TRAITS(Rect) + +}; // namespace android + +#endif // ANDROID_UI_RECT diff --git a/include/ui/Region.h b/include/ui/Region.h new file mode 100644 index 0000000..7689673 --- /dev/null +++ b/include/ui/Region.h @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_UI_REGION_H +#define ANDROID_UI_REGION_H + +#include <stdint.h> +#include <sys/types.h> + +#include <utils/Vector.h> +#include <utils/Parcel.h> + +#include <ui/Rect.h> + +#include <hardware/copybit.h> + +#include <core/SkRegion.h> + +namespace android { +// --------------------------------------------------------------------------- + +class String8; + +// --------------------------------------------------------------------------- +class Region +{ +public: + Region(); + Region(const Region& rhs); + explicit Region(const SkRegion& rhs); + explicit Region(const Rect& rhs); + explicit Region(const Parcel& parcel); + explicit Region(const void* buffer); + ~Region(); + + Region& operator = (const Region& rhs); + + inline bool isEmpty() const { return mRegion.isEmpty(); } + inline bool isRect() const { return mRegion.isRect(); } + + Rect bounds() const; + + const SkRegion& toSkRegion() const; + + void clear(); + void set(const Rect& r); + + Region& orSelf(const Rect& rhs); + Region& andSelf(const Rect& rhs); + + // boolean operators, applied on this + Region& orSelf(const Region& rhs); + Region& andSelf(const Region& rhs); + Region& subtractSelf(const Region& rhs); + + // these translate rhs first + Region& translateSelf(int dx, int dy); + Region& orSelf(const Region& rhs, int dx, int dy); + Region& andSelf(const Region& rhs, int dx, int dy); + Region& subtractSelf(const Region& rhs, int dx, int dy); + + // boolean operators + Region merge(const Region& rhs) const; + Region intersect(const Region& rhs) const; + Region subtract(const Region& rhs) const; + + // these translate rhs first + Region translate(int dx, int dy) const; + Region merge(const Region& rhs, int dx, int dy) const; + Region intersect(const Region& rhs, int dx, int dy) const; + Region subtract(const Region& rhs, int dx, int dy) const; + + // convenience operators overloads + inline Region operator | (const Region& rhs) const; + inline Region operator & (const Region& rhs) const; + inline Region operator - (const Region& rhs) const; + inline Region operator + (const Point& pt) const; + + inline Region& operator |= (const Region& rhs); + inline Region& operator &= (const Region& rhs); + inline Region& operator -= (const Region& rhs); + inline Region& operator += (const Point& pt); + + class iterator { + SkRegion::Iterator mIt; + public: + iterator(const Region& r); + inline operator bool () const { return !done(); } + int iterate(Rect* rect); + private: + inline bool done() const { + return const_cast<SkRegion::Iterator&>(mIt).done(); + } + }; + + size_t rects(Vector<Rect>& rectList) const; + + // flatten/unflatten a region to/from a Parcel + status_t write(Parcel& parcel) const; + status_t read(const Parcel& parcel); + + // flatten/unflatten a region to/from a raw buffer + ssize_t write(void* buffer, size_t size) const; + static ssize_t writeEmpty(void* buffer, size_t size); + + ssize_t read(const void* buffer); + static bool isEmpty(void* buffer); + + void dump(String8& out, const char* what, uint32_t flags=0) const; + void dump(const char* what, uint32_t flags=0) const; + +private: + SkRegion mRegion; +}; + + +Region Region::operator | (const Region& rhs) const { + return merge(rhs); +} +Region Region::operator & (const Region& rhs) const { + return intersect(rhs); +} +Region Region::operator - (const Region& rhs) const { + return subtract(rhs); +} +Region Region::operator + (const Point& pt) const { + return translate(pt.x, pt.y); +} + + +Region& Region::operator |= (const Region& rhs) { + return orSelf(rhs); +} +Region& Region::operator &= (const Region& rhs) { + return andSelf(rhs); +} +Region& Region::operator -= (const Region& rhs) { + return subtractSelf(rhs); +} +Region& Region::operator += (const Point& pt) { + return translateSelf(pt.x, pt.y); +} + +// --------------------------------------------------------------------------- + +struct region_iterator : public copybit_region_t { + region_iterator(const Region& region) : i(region) { + this->next = iterate; + } +private: + static int iterate(copybit_region_t const * self, copybit_rect_t* rect) { + return static_cast<const region_iterator*>(self) + ->i.iterate(reinterpret_cast<Rect*>(rect)); + } + mutable Region::iterator i; +}; +// --------------------------------------------------------------------------- +}; // namespace android + +#endif // ANDROID_UI_REGION_H + diff --git a/include/ui/Surface.h b/include/ui/Surface.h new file mode 100644 index 0000000..33953a9 --- /dev/null +++ b/include/ui/Surface.h @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_UI_SURFACE_H +#define ANDROID_UI_SURFACE_H + +#include <stdint.h> +#include <sys/types.h> + +#include <utils/RefBase.h> +#include <utils/threads.h> + +#include <ui/ISurface.h> +#include <ui/PixelFormat.h> +#include <ui/Region.h> +#include <ui/ISurfaceFlingerClient.h> + +namespace android { + +// --------------------------------------------------------------------------- + +class Rect; +class SurfaceComposerClient; + +class Surface : public RefBase +{ + +public: + struct SurfaceInfo { + uint32_t w; + uint32_t h; + uint32_t bpr; + PixelFormat format; + void* bits; + void* base; + uint32_t reserved[2]; + }; + + bool isValid() const { return this && mToken>=0 && mClient!=0; } + SurfaceID ID() const { return mToken; } + + status_t lock(SurfaceInfo* info, bool blocking = true); + status_t lock(SurfaceInfo* info, Region* dirty, bool blocking = true); + status_t unlockAndPost(); + status_t unlock(); + + void* heapBase(int i) const; + uint32_t getFlags() const { return mFlags; } + + // setSwapRectangle() is mainly used by EGL + void setSwapRectangle(const Rect& r); + const Rect& swapRectangle() const; + status_t nextBuffer(SurfaceInfo* info); + + sp<Surface> dup() const; + static sp<Surface> readFromParcel(Parcel* parcel); + static status_t writeToParcel(const sp<Surface>& surface, Parcel* parcel); + static bool isSameSurface(const sp<Surface>& lhs, const sp<Surface>& rhs); + + status_t setLayer(int32_t layer); + status_t setPosition(int32_t x, int32_t y); + status_t setSize(uint32_t w, uint32_t h); + status_t hide(); + status_t show(int32_t layer = -1); + status_t freeze(); + status_t unfreeze(); + status_t setFlags(uint32_t flags, uint32_t mask); + status_t setTransparentRegionHint(const Region& transparent); + status_t setAlpha(float alpha=1.0f); + status_t setMatrix(float dsdx, float dtdx, float dsdy, float dtdy); + status_t setFreezeTint(uint32_t tint); + + uint32_t getIdentity() const { return mIdentity; } +private: + friend class SurfaceComposerClient; + + // camera and camcorder need access to the ISurface binder interface for preview + friend class Camera; + friend class MediaRecorder; + // mediaplayer needs access to ISurface for display + friend class MediaPlayer; + friend class Test; + const sp<ISurface>& getISurface() const { return mSurface; } + + // can't be copied + Surface& operator = (Surface& rhs); + Surface(const Surface& rhs); + + Surface(const sp<SurfaceComposerClient>& client, + const sp<ISurface>& surface, + const ISurfaceFlingerClient::surface_data_t& data, + uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, + bool owner = true); + + Surface(Surface const* rhs); + + ~Surface(); + + Region dirtyRegion() const; + void setDirtyRegion(const Region& region) const; + + // this locks protects calls to lockSurface() / unlockSurface() + // and is called by SurfaceComposerClient. + Mutex& getLock() const { return mSurfaceLock; } + + sp<SurfaceComposerClient> mClient; + sp<ISurface> mSurface; + sp<IMemoryHeap> mHeap[2]; + SurfaceID mToken; + uint32_t mIdentity; + PixelFormat mFormat; + uint32_t mFlags; + const bool mOwner; + mutable void* mSurfaceHeapBase[2]; + mutable Region mDirtyRegion; + mutable Rect mSwapRectangle; + mutable uint8_t mBackbufferIndex; + mutable Mutex mSurfaceLock; +}; + +}; // namespace android + +#endif // ANDROID_UI_SURFACE_H + diff --git a/include/ui/SurfaceComposerClient.h b/include/ui/SurfaceComposerClient.h new file mode 100644 index 0000000..5d9222d --- /dev/null +++ b/include/ui/SurfaceComposerClient.h @@ -0,0 +1,179 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_SURFACE_COMPOSER_CLIENT_H +#define ANDROID_SURFACE_COMPOSER_CLIENT_H + +#include <stdint.h> +#include <sys/types.h> + +#include <utils/SortedVector.h> +#include <utils/KeyedVector.h> +#include <utils/RefBase.h> +#include <utils/threads.h> + +#include <ui/PixelFormat.h> +#include <ui/ISurfaceComposer.h> +#include <ui/Region.h> +#include <ui/Surface.h> + +namespace android { + +// --------------------------------------------------------------------------- + +class Region; +class SurfaceFlingerSynchro; +struct per_client_cblk_t; +struct layer_cblk_t; + +class SurfaceComposerClient : virtual public RefBase +{ +public: + SurfaceComposerClient(); + virtual ~SurfaceComposerClient(); + + // Always make sure we could initialize + status_t initCheck() const; + + // Return the connection of this client + sp<IBinder> connection() const; + + // Retrieve a client for an existing connection. + static sp<SurfaceComposerClient> + clientForConnection(const sp<IBinder>& conn); + + // Forcibly remove connection before all references have gone away. + void dispose(); + + // ------------------------------------------------------------------------ + // surface creation / destruction + + //! Create a surface + sp<Surface> createSurface( + int pid, //!< pid of the process the surfacec is for + DisplayID display, //!< Display to create this surface on + uint32_t w, //!< width in pixel + uint32_t h, //!< height in pixel + PixelFormat format, //!< pixel-format desired + uint32_t flags = 0 //!< usage flags + ); + + // ------------------------------------------------------------------------ + // Composer parameters + // All composer parameters must be changed within a transaction + // several surfaces can be updated in one transaction, all changes are + // committed at once when the transaction is closed. + // CloseTransaction() usually requires an IPC with the server. + + //! Open a composer transaction + status_t openTransaction(); + + //! commit the transaction + status_t closeTransaction(); + + //! Open a composer transaction on all active SurfaceComposerClients. + static void openGlobalTransaction(); + + //! Close a composer transaction on all active SurfaceComposerClients. + static void closeGlobalTransaction(); + + //! Freeze the specified display but not transactions. + static status_t freezeDisplay(DisplayID dpy, uint32_t flags = 0); + + //! Resume updates on the specified display. + static status_t unfreezeDisplay(DisplayID dpy, uint32_t flags = 0); + + //! Set the orientation of the given display + static int setOrientation(DisplayID dpy, int orientation); + + // Query the number of displays + static ssize_t getNumberOfDisplays(); + + // Get information about a display + static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info); + static ssize_t getDisplayWidth(DisplayID dpy); + static ssize_t getDisplayHeight(DisplayID dpy); + static ssize_t getDisplayOrientation(DisplayID dpy); + + +private: + friend class Surface; + + SurfaceComposerClient(const sp<ISurfaceComposer>& sm, + const sp<IBinder>& conn); + + status_t hide(Surface* surface); + status_t show(Surface* surface, int32_t layer = -1); + status_t freeze(Surface* surface); + status_t unfreeze(Surface* surface); + status_t setFlags(Surface* surface, uint32_t flags, uint32_t mask); + status_t setTransparentRegionHint(Surface* surface, const Region& transparent); + status_t setLayer(Surface* surface, int32_t layer); + status_t setAlpha(Surface* surface, float alpha=1.0f); + status_t setFreezeTint(Surface* surface, uint32_t tint); + status_t setMatrix(Surface* surface, float dsdx, float dtdx, float dsdy, float dtdy); + status_t setPosition(Surface* surface, int32_t x, int32_t y); + status_t setSize(Surface* surface, uint32_t w, uint32_t h); + + //! Unlock the surface, and specify the dirty region if any + status_t unlockAndPostSurface(Surface* surface); + status_t unlockSurface(Surface* surface); + + status_t lockSurface(Surface* surface, + Surface::SurfaceInfo* info, + Region* dirty, + bool blocking = true); + + status_t nextBuffer(Surface* surface, + Surface::SurfaceInfo* info); + + status_t destroySurface(SurfaceID sid); + + void _init(const sp<ISurfaceComposer>& sm, + const sp<ISurfaceFlingerClient>& conn); + void _signal_server(); + static void _send_dirty_region(layer_cblk_t* lcblk, const Region& dirty); + + inline layer_state_t* _get_state_l(const sp<Surface>& surface); + layer_state_t* _lockLayerState(const sp<Surface>& surface); + inline void _unlockLayerState(); + + status_t validateSurface( + per_client_cblk_t const* cblk, Surface const * surface); + + void pinHeap(const sp<IMemoryHeap>& heap); + + mutable Mutex mLock; + layer_state_t* mPrebuiltLayerState; + SortedVector<layer_state_t> mStates; + int32_t mTransactionOpen; + + // these don't need to be protected because they never change + // after assignment + status_t mStatus; + per_client_cblk_t* mControl; + sp<IMemory> mControlMemory; + sp<ISurfaceFlingerClient> mClient; + sp<IMemoryHeap> mSurfaceHeap; + uint8_t* mSurfaceHeapBase; + void* mGL; + SurfaceFlingerSynchro* mSignalServer; +}; + +}; // namespace android + +#endif // ANDROID_SURFACE_COMPOSER_CLIENT_H + |