From cc08e688f5b82b4ebd076ad138b2749e8c86ad5e Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Thu, 15 Apr 2010 18:48:26 -0700 Subject: added setCrop() to android_native_window_t hooked up the new method up to Surface.cpp the actual crop is not implemented in SF yet Change-Id: Ic6e313c98fd880f127a051a0ccc71808bd689751 --- include/private/surfaceflinger/SharedBufferStack.h | 29 ++++++++++++----- include/surfaceflinger/ISurfaceFlingerClient.h | 9 +++++ include/surfaceflinger/Surface.h | 3 ++ include/ui/egl/android_natives.h | 38 +++++++++++++++++++--- 4 files changed, 65 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/private/surfaceflinger/SharedBufferStack.h b/include/private/surfaceflinger/SharedBufferStack.h index 3b9768b..6ace5bc 100644 --- a/include/private/surfaceflinger/SharedBufferStack.h +++ b/include/private/surfaceflinger/SharedBufferStack.h @@ -70,9 +70,9 @@ class SharedClient; // ---------------------------------------------------------------------------- // 4 * (11 + 7 + (1 + 2*NUM_RECT_MAX) * NUM_BUFFER_MAX) * NUM_LAYERS_MAX -// 4 * (11 + 7 + (1 + 2*6)*16) * 31 -// 904 * 31 -// = ~27 KiB (28024) +// 4 * (11 + 7 + (1 + 2*7)*16) * 31 +// 1032 * 31 +// = ~27 KiB (31992) class SharedBufferStack { @@ -82,21 +82,31 @@ class SharedBufferStack friend class SharedBufferServer; public: + struct Statistics { // 4 longs + typedef int32_t usecs_t; + usecs_t totalTime; + usecs_t reserved[3]; + }; + + struct SmallRect { + uint16_t l, t, r, b; + }; + struct FlatRegion { // 52 bytes = 4 * (1 + 2*N) static const unsigned int NUM_RECT_MAX = 6; uint32_t count; - uint16_t rects[4*NUM_RECT_MAX]; + SmallRect rects[NUM_RECT_MAX]; }; - struct Statistics { // 4 longs - typedef int32_t usecs_t; - usecs_t totalTime; - usecs_t reserved[3]; + struct BufferData { + FlatRegion dirtyRegion; + SmallRect crop; }; SharedBufferStack(); void init(int32_t identity); status_t setDirtyRegion(int buffer, const Region& reg); + status_t setCrop(int buffer, const Rect& reg); Region getDirtyRegion(int buffer) const; // these attributes are part of the conditions/updates @@ -113,7 +123,7 @@ public: int32_t reserved32[6]; Statistics stats; int32_t reserved; - FlatRegion dirtyRegion[NUM_BUFFER_MAX]; // 832 bytes + BufferData buffers[NUM_BUFFER_MAX]; // 960 bytes }; // ---------------------------------------------------------------------------- @@ -243,6 +253,7 @@ public: status_t queue(int buf); bool needNewBuffer(int buffer) const; status_t setDirtyRegion(int buffer, const Region& reg); + status_t setCrop(int buffer, const Rect& reg); private: friend struct Condition; diff --git a/include/surfaceflinger/ISurfaceFlingerClient.h b/include/surfaceflinger/ISurfaceFlingerClient.h index d257645..c96432f 100644 --- a/include/surfaceflinger/ISurfaceFlingerClient.h +++ b/include/surfaceflinger/ISurfaceFlingerClient.h @@ -59,6 +59,9 @@ public: virtual sp getControlBlock() const = 0; + /* + * Requires ACCESS_SURFACE_FLINGER permission + */ virtual sp createSurface( surface_data_t* data, int pid, const String8& name, @@ -68,8 +71,14 @@ public: PixelFormat format, uint32_t flags) = 0; + /* + * Requires ACCESS_SURFACE_FLINGER permission + */ virtual status_t destroySurface(SurfaceID sid) = 0; + /* + * Requires ACCESS_SURFACE_FLINGER permission + */ virtual status_t setState(int32_t count, const layer_state_t* states) = 0; }; diff --git a/include/surfaceflinger/Surface.h b/include/surfaceflinger/Surface.h index 4c8d023..68809a9 100644 --- a/include/surfaceflinger/Surface.h +++ b/include/surfaceflinger/Surface.h @@ -215,10 +215,12 @@ private: void dispatch_setUsage(va_list args); int dispatch_connect(va_list args); int dispatch_disconnect(va_list args); + int dispatch_crop(va_list args); void setUsage(uint32_t reqUsage); int connect(int api); int disconnect(int api); + int crop(Rect const* rect); uint32_t getUsage() const; int getConnectedApi() const; @@ -237,6 +239,7 @@ private: Rect mSwapRectangle; uint32_t mUsage; int mConnected; + Rect mNextBufferCrop; // protected by mSurfaceLock. These are also used from lock/unlock // but in that case, they must be called form the same thread. diff --git a/include/ui/egl/android_natives.h b/include/ui/egl/android_natives.h index 773fd93..471c3c7 100644 --- a/include/ui/egl/android_natives.h +++ b/include/ui/egl/android_natives.h @@ -41,6 +41,14 @@ extern "C" { struct android_native_buffer_t; +typedef struct android_native_rect_t +{ + int32_t left; + int32_t top; + int32_t right; + int32_t bottom; +} android_native_rect_t; + // --------------------------------------------------------------------------- typedef struct android_native_base_t @@ -63,15 +71,16 @@ typedef struct android_native_base_t /* attributes queriable with query() */ enum { NATIVE_WINDOW_WIDTH = 0, - NATIVE_WINDOW_HEIGHT = 1, - NATIVE_WINDOW_FORMAT = 2, + NATIVE_WINDOW_HEIGHT, + NATIVE_WINDOW_FORMAT, }; /* valid operations for the (*perform)() hook */ enum { NATIVE_WINDOW_SET_USAGE = 0, - NATIVE_WINDOW_CONNECT = 1, - NATIVE_WINDOW_DISCONNECT = 2 + NATIVE_WINDOW_CONNECT, + NATIVE_WINDOW_DISCONNECT, + NATIVE_WINDOW_SET_CROP, }; /* parameter for NATIVE_WINDOW_[DIS]CONNECT */ @@ -125,7 +134,7 @@ typedef struct android_native_window_t * * Returns 0 on success or -errno on error. */ - int (*dequeueBuffer)(struct android_native_window_t* window, + int (*dequeueBuffer)(struct android_native_window_t* window, struct android_native_buffer_t** buffer); /* @@ -171,6 +180,7 @@ typedef struct android_native_window_t * NATIVE_WINDOW_SET_USAGE * NATIVE_WINDOW_CONNECT * NATIVE_WINDOW_DISCONNECT + * NATIVE_WINDOW_SET_CROP * */ @@ -221,6 +231,24 @@ static inline int native_window_disconnect( return window->perform(window, NATIVE_WINDOW_DISCONNECT, api); } +/* + * native_window_set_crop(..., crop) sets which region of the next queued + * buffers needs to be considered. + * A buffer's crop region is scaled to match the surface's size. + * + * The specified crop region applies to all buffers queued after it is called. + * + * if 'crop' is NULL, subsequently queued buffers won't be cropped. + * + * An error is returned if for instance the crop region is invalid, + * out of the buffer's bound or if the window is invalid. + */ +static inline int native_window_set_crop( + android_native_window_t* window, + android_native_rect_t const * crop) +{ + return window->perform(window, NATIVE_WINDOW_SET_CROP, crop); +} // --------------------------------------------------------------------------- -- cgit v1.1