mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-02-20 13:43:57 +08:00
openpilot v0.6 release
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2009 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_ANDROID_NATIVES_H
|
||||
#define ANDROID_ANDROID_NATIVES_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <hardware/gralloc.h>
|
||||
#include <system/window.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/* FIXME: this is legacy for pixmaps */
|
||||
typedef struct egl_native_pixmap_t
|
||||
{
|
||||
int32_t version; /* must be 32 */
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
int32_t stride;
|
||||
uint8_t* data;
|
||||
uint8_t format;
|
||||
uint8_t rfu[3];
|
||||
union {
|
||||
uint32_t compressedFormat;
|
||||
int32_t vstride;
|
||||
};
|
||||
int32_t reserved;
|
||||
} egl_native_pixmap_t;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <utils/RefBase.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
/*
|
||||
* This helper class turns a ANativeXXX object type into a C++
|
||||
* reference-counted object; with proper type conversions.
|
||||
*/
|
||||
template <typename NATIVE_TYPE, typename TYPE, typename REF>
|
||||
class ANativeObjectBase : public NATIVE_TYPE, public REF
|
||||
{
|
||||
public:
|
||||
// Disambiguate between the incStrong in REF and NATIVE_TYPE
|
||||
void incStrong(const void* id) const {
|
||||
REF::incStrong(id);
|
||||
}
|
||||
void decStrong(const void* id) const {
|
||||
REF::decStrong(id);
|
||||
}
|
||||
|
||||
protected:
|
||||
typedef ANativeObjectBase<NATIVE_TYPE, TYPE, REF> BASE;
|
||||
ANativeObjectBase() : NATIVE_TYPE(), REF() {
|
||||
NATIVE_TYPE::common.incRef = incRef;
|
||||
NATIVE_TYPE::common.decRef = decRef;
|
||||
}
|
||||
static inline TYPE* getSelf(NATIVE_TYPE* self) {
|
||||
return static_cast<TYPE*>(self);
|
||||
}
|
||||
static inline TYPE const* getSelf(NATIVE_TYPE const* self) {
|
||||
return static_cast<TYPE const *>(self);
|
||||
}
|
||||
static inline TYPE* getSelf(android_native_base_t* base) {
|
||||
return getSelf(reinterpret_cast<NATIVE_TYPE*>(base));
|
||||
}
|
||||
static inline TYPE const * getSelf(android_native_base_t const* base) {
|
||||
return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base));
|
||||
}
|
||||
static void incRef(android_native_base_t* base) {
|
||||
ANativeObjectBase* self = getSelf(base);
|
||||
self->incStrong(self);
|
||||
}
|
||||
static void decRef(android_native_base_t* base) {
|
||||
ANativeObjectBase* self = getSelf(base);
|
||||
self->decStrong(self);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
#endif // __cplusplus
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif /* ANDROID_ANDROID_NATIVES_H */
|
||||
52
phonelibs/android_frameworks_native/include/ui/DisplayInfo.h
Normal file
52
phonelibs/android_frameworks_native/include/ui/DisplayInfo.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 <utils/Timers.h>
|
||||
|
||||
#include <ui/PixelFormat.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
struct DisplayInfo {
|
||||
uint32_t w;
|
||||
uint32_t h;
|
||||
float xdpi;
|
||||
float ydpi;
|
||||
float fps;
|
||||
float density;
|
||||
uint8_t orientation;
|
||||
bool secure;
|
||||
nsecs_t appVsyncOffset;
|
||||
nsecs_t presentationDeadline;
|
||||
int colorTransform;
|
||||
};
|
||||
|
||||
/* Display orientations as defined in Surface.java and ISurfaceComposer.h. */
|
||||
enum {
|
||||
DISPLAY_ORIENTATION_0 = 0,
|
||||
DISPLAY_ORIENTATION_90 = 1,
|
||||
DISPLAY_ORIENTATION_180 = 2,
|
||||
DISPLAY_ORIENTATION_270 = 3
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_COMPOSER_DISPLAY_INFO_H
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2014 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_STAT_INFO_H
|
||||
#define ANDROID_UI_DISPLAY_STAT_INFO_H
|
||||
|
||||
#include <utils/Timers.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
struct DisplayStatInfo {
|
||||
nsecs_t vsyncTime;
|
||||
nsecs_t vsyncPeriod;
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_COMPOSER_DISPLAY_STAT_INFO_H
|
||||
117
phonelibs/android_frameworks_native/include/ui/Fence.h
Normal file
117
phonelibs/android_frameworks_native/include/ui/Fence.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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_FENCE_H
|
||||
#define ANDROID_FENCE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ui/ANativeObjectBase.h>
|
||||
#include <ui/PixelFormat.h>
|
||||
#include <ui/Rect.h>
|
||||
#include <utils/Flattenable.h>
|
||||
#include <utils/String8.h>
|
||||
#include <utils/Timers.h>
|
||||
|
||||
struct ANativeWindowBuffer;
|
||||
|
||||
namespace android {
|
||||
|
||||
// ===========================================================================
|
||||
// Fence
|
||||
// ===========================================================================
|
||||
|
||||
class Fence
|
||||
: public LightRefBase<Fence>, public Flattenable<Fence>
|
||||
{
|
||||
public:
|
||||
static const sp<Fence> NO_FENCE;
|
||||
|
||||
// TIMEOUT_NEVER may be passed to the wait method to indicate that it
|
||||
// should wait indefinitely for the fence to signal.
|
||||
enum { TIMEOUT_NEVER = -1 };
|
||||
|
||||
// Construct a new Fence object with an invalid file descriptor. This
|
||||
// should be done when the Fence object will be set up by unflattening
|
||||
// serialized data.
|
||||
Fence();
|
||||
|
||||
// Construct a new Fence object to manage a given fence file descriptor.
|
||||
// When the new Fence object is destructed the file descriptor will be
|
||||
// closed.
|
||||
Fence(int fenceFd);
|
||||
|
||||
// Check whether the Fence has an open fence file descriptor. Most Fence
|
||||
// methods treat an invalid file descriptor just like a valid fence that
|
||||
// is already signalled, so using this is usually not necessary.
|
||||
bool isValid() const { return mFenceFd != -1; }
|
||||
|
||||
// wait waits for up to timeout milliseconds for the fence to signal. If
|
||||
// the fence signals then NO_ERROR is returned. If the timeout expires
|
||||
// before the fence signals then -ETIME is returned. A timeout of
|
||||
// TIMEOUT_NEVER may be used to indicate that the call should wait
|
||||
// indefinitely for the fence to signal.
|
||||
status_t wait(int timeout);
|
||||
|
||||
// waitForever is a convenience function for waiting forever for a fence to
|
||||
// signal (just like wait(TIMEOUT_NEVER)), but issuing an error to the
|
||||
// system log and fence state to the kernel log if the wait lasts longer
|
||||
// than a warning timeout.
|
||||
// The logname argument should be a string identifying
|
||||
// the caller and will be included in the log message.
|
||||
status_t waitForever(const char* logname);
|
||||
|
||||
// merge combines two Fence objects, creating a new Fence object that
|
||||
// becomes signaled when both f1 and f2 are signaled (even if f1 or f2 is
|
||||
// destroyed before it becomes signaled). The name argument specifies the
|
||||
// human-readable name to associated with the new Fence object.
|
||||
static sp<Fence> merge(const String8& name, const sp<Fence>& f1,
|
||||
const sp<Fence>& f2);
|
||||
|
||||
// Return a duplicate of the fence file descriptor. The caller is
|
||||
// responsible for closing the returned file descriptor. On error, -1 will
|
||||
// be returned and errno will indicate the problem.
|
||||
int dup() const;
|
||||
|
||||
// getSignalTime returns the system monotonic clock time at which the
|
||||
// fence transitioned to the signaled state. If the fence is not signaled
|
||||
// then INT64_MAX is returned. If the fence is invalid or if an error
|
||||
// occurs then -1 is returned.
|
||||
nsecs_t getSignalTime() const;
|
||||
|
||||
// Flattenable interface
|
||||
size_t getFlattenedSize() const;
|
||||
size_t getFdCount() const;
|
||||
status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
|
||||
status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
|
||||
|
||||
private:
|
||||
// Only allow instantiation using ref counting.
|
||||
friend class LightRefBase<Fence>;
|
||||
~Fence();
|
||||
|
||||
// Disallow copying
|
||||
Fence(const Fence& rhs);
|
||||
Fence& operator = (const Fence& rhs);
|
||||
const Fence& operator = (const Fence& rhs) const;
|
||||
|
||||
int mFenceFd;
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_FENCE_H
|
||||
64
phonelibs/android_frameworks_native/include/ui/FrameStats.h
Normal file
64
phonelibs/android_frameworks_native/include/ui/FrameStats.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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_FRAME_STATS_H
|
||||
#define ANDROID_UI_FRAME_STATS_H
|
||||
|
||||
#include <utils/Flattenable.h>
|
||||
#include <utils/Timers.h>
|
||||
#include <utils/Vector.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
class FrameStats : public LightFlattenable<FrameStats> {
|
||||
public:
|
||||
FrameStats() : refreshPeriodNano(0) {};
|
||||
|
||||
/*
|
||||
* Approximate refresh time, in nanoseconds.
|
||||
*/
|
||||
nsecs_t refreshPeriodNano;
|
||||
|
||||
/*
|
||||
* The times in nanoseconds for when the frame contents were posted by the producer (e.g.
|
||||
* the application). They are either explicitly set or defaulted to the time when
|
||||
* Surface::queueBuffer() was called.
|
||||
*/
|
||||
Vector<nsecs_t> desiredPresentTimesNano;
|
||||
|
||||
/*
|
||||
* The times in milliseconds for when the frame contents were presented on the screen.
|
||||
*/
|
||||
Vector<nsecs_t> actualPresentTimesNano;
|
||||
|
||||
/*
|
||||
* The times in nanoseconds for when the frame contents were ready to be presented. Note that
|
||||
* a frame can be posted and still it contents being rendered asynchronously in GL. In such a
|
||||
* case these are the times when the frame contents were completely rendered (i.e. their fences
|
||||
* signaled).
|
||||
*/
|
||||
Vector<nsecs_t> frameReadyTimesNano;
|
||||
|
||||
// LightFlattenable
|
||||
bool isFixedSize() const;
|
||||
size_t getFlattenedSize() const;
|
||||
status_t flatten(void* buffer, size_t size) const;
|
||||
status_t unflatten(void const* buffer, size_t size);
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_UI_FRAME_STATS_H
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 INCLUDED_FROM_FRAMEBUFFER_NATIVE_WINDOW_CPP
|
||||
#warning "FramebufferNativeWindow is deprecated"
|
||||
#endif
|
||||
|
||||
#ifndef ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H
|
||||
#define ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
#include <utils/threads.h>
|
||||
#include <utils/String8.h>
|
||||
|
||||
#include <ui/ANativeObjectBase.h>
|
||||
#include <ui/Rect.h>
|
||||
|
||||
#define MIN_NUM_FRAME_BUFFERS 2
|
||||
#define MAX_NUM_FRAME_BUFFERS 3
|
||||
|
||||
extern "C" EGLNativeWindowType android_createDisplaySurface(void);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
namespace android {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class Surface;
|
||||
class NativeBuffer;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class FramebufferNativeWindow
|
||||
: public ANativeObjectBase<
|
||||
ANativeWindow,
|
||||
FramebufferNativeWindow,
|
||||
LightRefBase<FramebufferNativeWindow> >
|
||||
{
|
||||
public:
|
||||
FramebufferNativeWindow();
|
||||
|
||||
framebuffer_device_t const * getDevice() const { return fbDev; }
|
||||
|
||||
bool isUpdateOnDemand() const { return mUpdateOnDemand; }
|
||||
status_t setUpdateRectangle(const Rect& updateRect);
|
||||
status_t compositionComplete();
|
||||
|
||||
void dump(String8& result);
|
||||
|
||||
// for debugging only
|
||||
int getCurrentBufferIndex() const;
|
||||
|
||||
private:
|
||||
friend class LightRefBase<FramebufferNativeWindow>;
|
||||
~FramebufferNativeWindow(); // this class cannot be overloaded
|
||||
static int setSwapInterval(ANativeWindow* window, int interval);
|
||||
static int dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, int* fenceFd);
|
||||
static int queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd);
|
||||
static int query(const ANativeWindow* window, int what, int* value);
|
||||
static int perform(ANativeWindow* window, int operation, ...);
|
||||
|
||||
static int dequeueBuffer_DEPRECATED(ANativeWindow* window, ANativeWindowBuffer** buffer);
|
||||
static int queueBuffer_DEPRECATED(ANativeWindow* window, ANativeWindowBuffer* buffer);
|
||||
static int lockBuffer_DEPRECATED(ANativeWindow* window, ANativeWindowBuffer* buffer);
|
||||
|
||||
framebuffer_device_t* fbDev;
|
||||
alloc_device_t* grDev;
|
||||
|
||||
sp<NativeBuffer> buffers[MAX_NUM_FRAME_BUFFERS];
|
||||
sp<NativeBuffer> front;
|
||||
|
||||
mutable Mutex mutex;
|
||||
Condition mCondition;
|
||||
int32_t mNumBuffers;
|
||||
int32_t mNumFreeBuffers;
|
||||
int32_t mBufferHead;
|
||||
int32_t mCurrentBufferIndex;
|
||||
bool mUpdateOnDemand;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H
|
||||
|
||||
183
phonelibs/android_frameworks_native/include/ui/GraphicBuffer.h
Normal file
183
phonelibs/android_frameworks_native/include/ui/GraphicBuffer.h
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* 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_GRAPHIC_BUFFER_H
|
||||
#define ANDROID_GRAPHIC_BUFFER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ui/ANativeObjectBase.h>
|
||||
#include <ui/PixelFormat.h>
|
||||
#include <ui/Rect.h>
|
||||
#include <utils/Flattenable.h>
|
||||
#include <utils/RefBase.h>
|
||||
|
||||
|
||||
struct ANativeWindowBuffer;
|
||||
|
||||
namespace android {
|
||||
|
||||
class GraphicBufferMapper;
|
||||
|
||||
// ===========================================================================
|
||||
// GraphicBuffer
|
||||
// ===========================================================================
|
||||
|
||||
class GraphicBuffer
|
||||
: public ANativeObjectBase< ANativeWindowBuffer, GraphicBuffer, RefBase >,
|
||||
public Flattenable<GraphicBuffer>
|
||||
{
|
||||
friend class Flattenable<GraphicBuffer>;
|
||||
public:
|
||||
|
||||
enum {
|
||||
USAGE_SW_READ_NEVER = GRALLOC_USAGE_SW_READ_NEVER,
|
||||
USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY,
|
||||
USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN,
|
||||
USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK,
|
||||
|
||||
USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER,
|
||||
USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY,
|
||||
USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN,
|
||||
USAGE_SW_WRITE_MASK = GRALLOC_USAGE_SW_WRITE_MASK,
|
||||
|
||||
USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK,
|
||||
|
||||
USAGE_PROTECTED = GRALLOC_USAGE_PROTECTED,
|
||||
|
||||
USAGE_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE,
|
||||
USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER,
|
||||
USAGE_HW_2D = GRALLOC_USAGE_HW_2D,
|
||||
USAGE_HW_COMPOSER = GRALLOC_USAGE_HW_COMPOSER,
|
||||
USAGE_HW_VIDEO_ENCODER = GRALLOC_USAGE_HW_VIDEO_ENCODER,
|
||||
USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK,
|
||||
|
||||
USAGE_CURSOR = GRALLOC_USAGE_CURSOR,
|
||||
};
|
||||
|
||||
GraphicBuffer();
|
||||
|
||||
// creates w * h buffer
|
||||
GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
|
||||
uint32_t inUsage);
|
||||
|
||||
// create a buffer from an existing handle
|
||||
GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
|
||||
uint32_t inUsage, uint32_t inStride, native_handle_t* inHandle,
|
||||
bool keepOwnership);
|
||||
|
||||
// create a buffer from an existing ANativeWindowBuffer
|
||||
GraphicBuffer(ANativeWindowBuffer* buffer, bool keepOwnership);
|
||||
|
||||
// return status
|
||||
status_t initCheck() const;
|
||||
|
||||
uint32_t getWidth() const { return static_cast<uint32_t>(width); }
|
||||
uint32_t getHeight() const { return static_cast<uint32_t>(height); }
|
||||
uint32_t getStride() const { return static_cast<uint32_t>(stride); }
|
||||
uint32_t getUsage() const { return static_cast<uint32_t>(usage); }
|
||||
PixelFormat getPixelFormat() const { return format; }
|
||||
Rect getBounds() const { return Rect(width, height); }
|
||||
uint64_t getId() const { return mId; }
|
||||
|
||||
uint32_t getGenerationNumber() const { return mGenerationNumber; }
|
||||
void setGenerationNumber(uint32_t generation) {
|
||||
mGenerationNumber = generation;
|
||||
}
|
||||
|
||||
status_t reallocate(uint32_t inWidth, uint32_t inHeight,
|
||||
PixelFormat inFormat, uint32_t inUsage);
|
||||
|
||||
bool needsReallocation(uint32_t inWidth, uint32_t inHeight,
|
||||
PixelFormat inFormat, uint32_t inUsage);
|
||||
|
||||
status_t lock(uint32_t inUsage, void** vaddr);
|
||||
status_t lock(uint32_t inUsage, const Rect& rect, void** vaddr);
|
||||
// For HAL_PIXEL_FORMAT_YCbCr_420_888
|
||||
status_t lockYCbCr(uint32_t inUsage, android_ycbcr *ycbcr);
|
||||
status_t lockYCbCr(uint32_t inUsage, const Rect& rect,
|
||||
android_ycbcr *ycbcr);
|
||||
status_t unlock();
|
||||
status_t lockAsync(uint32_t inUsage, void** vaddr, int fenceFd);
|
||||
status_t lockAsync(uint32_t inUsage, const Rect& rect, void** vaddr,
|
||||
int fenceFd);
|
||||
status_t lockAsyncYCbCr(uint32_t inUsage, android_ycbcr *ycbcr,
|
||||
int fenceFd);
|
||||
status_t lockAsyncYCbCr(uint32_t inUsage, const Rect& rect,
|
||||
android_ycbcr *ycbcr, int fenceFd);
|
||||
status_t unlockAsync(int *fenceFd);
|
||||
|
||||
ANativeWindowBuffer* getNativeBuffer() const;
|
||||
|
||||
// for debugging
|
||||
static void dumpAllocationsToSystemLog();
|
||||
|
||||
// Flattenable protocol
|
||||
size_t getFlattenedSize() const;
|
||||
size_t getFdCount() const;
|
||||
status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
|
||||
status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
|
||||
|
||||
private:
|
||||
~GraphicBuffer();
|
||||
|
||||
enum {
|
||||
ownNone = 0,
|
||||
ownHandle = 1,
|
||||
ownData = 2,
|
||||
};
|
||||
|
||||
inline const GraphicBufferMapper& getBufferMapper() const {
|
||||
return mBufferMapper;
|
||||
}
|
||||
inline GraphicBufferMapper& getBufferMapper() {
|
||||
return mBufferMapper;
|
||||
}
|
||||
uint8_t mOwner;
|
||||
|
||||
private:
|
||||
friend class Surface;
|
||||
friend class BpSurface;
|
||||
friend class BnSurface;
|
||||
friend class LightRefBase<GraphicBuffer>;
|
||||
GraphicBuffer(const GraphicBuffer& rhs);
|
||||
GraphicBuffer& operator = (const GraphicBuffer& rhs);
|
||||
const GraphicBuffer& operator = (const GraphicBuffer& rhs) const;
|
||||
|
||||
status_t initSize(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
|
||||
uint32_t inUsage);
|
||||
|
||||
void free_handle();
|
||||
|
||||
GraphicBufferMapper& mBufferMapper;
|
||||
ssize_t mInitCheck;
|
||||
|
||||
// If we're wrapping another buffer then this reference will make sure it
|
||||
// doesn't get freed.
|
||||
sp<ANativeWindowBuffer> mWrappedBuffer;
|
||||
|
||||
uint64_t mId;
|
||||
|
||||
// Stores the generation number of this buffer. If this number does not
|
||||
// match the BufferQueue's internal generation number (set through
|
||||
// IGBP::setGenerationNumber), attempts to attach the buffer will fail.
|
||||
uint32_t mGenerationNumber;
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_GRAPHIC_BUFFER_H
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
**
|
||||
** Copyright 2009, 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_BUFFER_ALLOCATOR_H
|
||||
#define ANDROID_BUFFER_ALLOCATOR_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <cutils/native_handle.h>
|
||||
|
||||
#include <utils/Errors.h>
|
||||
#include <utils/KeyedVector.h>
|
||||
#include <utils/threads.h>
|
||||
#include <utils/Singleton.h>
|
||||
|
||||
#include <ui/PixelFormat.h>
|
||||
|
||||
#include <hardware/gralloc.h>
|
||||
|
||||
|
||||
namespace android {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class String8;
|
||||
|
||||
class GraphicBufferAllocator : public Singleton<GraphicBufferAllocator>
|
||||
{
|
||||
public:
|
||||
enum {
|
||||
USAGE_SW_READ_NEVER = GRALLOC_USAGE_SW_READ_NEVER,
|
||||
USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY,
|
||||
USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN,
|
||||
USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK,
|
||||
|
||||
USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER,
|
||||
USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY,
|
||||
USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN,
|
||||
USAGE_SW_WRITE_MASK = GRALLOC_USAGE_SW_WRITE_MASK,
|
||||
|
||||
USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK,
|
||||
|
||||
USAGE_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE,
|
||||
USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER,
|
||||
USAGE_HW_2D = GRALLOC_USAGE_HW_2D,
|
||||
USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK
|
||||
};
|
||||
|
||||
static inline GraphicBufferAllocator& get() { return getInstance(); }
|
||||
|
||||
status_t alloc(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage,
|
||||
buffer_handle_t* handle, uint32_t* stride);
|
||||
|
||||
status_t free(buffer_handle_t handle);
|
||||
|
||||
void dump(String8& res) const;
|
||||
static void dumpToSystemLog();
|
||||
|
||||
private:
|
||||
struct alloc_rec_t {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t stride;
|
||||
PixelFormat format;
|
||||
uint32_t usage;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
static Mutex sLock;
|
||||
static KeyedVector<buffer_handle_t, alloc_rec_t> sAllocList;
|
||||
|
||||
friend class Singleton<GraphicBufferAllocator>;
|
||||
GraphicBufferAllocator();
|
||||
~GraphicBufferAllocator();
|
||||
|
||||
alloc_device_t *mAllocDev;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_BUFFER_ALLOCATOR_H
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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_BUFFER_MAPPER_H
|
||||
#define ANDROID_UI_BUFFER_MAPPER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <utils/Singleton.h>
|
||||
|
||||
#include <hardware/gralloc.h>
|
||||
|
||||
|
||||
struct gralloc_module_t;
|
||||
|
||||
namespace android {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class Rect;
|
||||
|
||||
class GraphicBufferMapper : public Singleton<GraphicBufferMapper>
|
||||
{
|
||||
public:
|
||||
static inline GraphicBufferMapper& get() { return getInstance(); }
|
||||
|
||||
status_t registerBuffer(buffer_handle_t handle);
|
||||
|
||||
status_t unregisterBuffer(buffer_handle_t handle);
|
||||
|
||||
status_t lock(buffer_handle_t handle,
|
||||
uint32_t usage, const Rect& bounds, void** vaddr);
|
||||
|
||||
status_t lockYCbCr(buffer_handle_t handle,
|
||||
uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr);
|
||||
|
||||
status_t unlock(buffer_handle_t handle);
|
||||
|
||||
status_t lockAsync(buffer_handle_t handle,
|
||||
uint32_t usage, const Rect& bounds, void** vaddr, int fenceFd);
|
||||
|
||||
status_t lockAsyncYCbCr(buffer_handle_t handle,
|
||||
uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr,
|
||||
int fenceFd);
|
||||
|
||||
status_t unlockAsync(buffer_handle_t handle, int *fenceFd);
|
||||
|
||||
#ifdef EXYNOS4_ENHANCEMENTS
|
||||
status_t getphys(buffer_handle_t handle, void** paddr);
|
||||
#endif
|
||||
|
||||
// dumps information about the mapping of this handle
|
||||
void dump(buffer_handle_t handle);
|
||||
|
||||
private:
|
||||
friend class Singleton<GraphicBufferMapper>;
|
||||
GraphicBufferMapper();
|
||||
gralloc_module_t const *mAllocMod;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_UI_BUFFER_MAPPER_H
|
||||
|
||||
72
phonelibs/android_frameworks_native/include/ui/PixelFormat.h
Normal file
72
phonelibs/android_frameworks_native/include/ui/PixelFormat.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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)
|
||||
|
||||
|
||||
#ifndef UI_PIXELFORMAT_H
|
||||
#define UI_PIXELFORMAT_H
|
||||
|
||||
#include <hardware/hardware.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 = HAL_PIXEL_FORMAT_RGBA_8888, // 4x8-bit RGBA
|
||||
PIXEL_FORMAT_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888, // 4x8-bit RGB0
|
||||
PIXEL_FORMAT_RGB_888 = HAL_PIXEL_FORMAT_RGB_888, // 3x8-bit RGB
|
||||
PIXEL_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565, // 16-bit RGB
|
||||
PIXEL_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888, // 4x8-bit BGRA
|
||||
PIXEL_FORMAT_RGBA_5551 = 6, // 16-bit ARGB
|
||||
PIXEL_FORMAT_RGBA_4444 = 7, // 16-bit ARGB
|
||||
};
|
||||
|
||||
typedef int32_t PixelFormat;
|
||||
|
||||
uint32_t bytesPerPixel(PixelFormat format);
|
||||
uint32_t bitsPerPixel(PixelFormat format);
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // UI_PIXELFORMAT_H
|
||||
88
phonelibs/android_frameworks_native/include/ui/Point.h
Normal file
88
phonelibs/android_frameworks_native/include/ui/Point.h
Normal file
@@ -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/Flattenable.h>
|
||||
#include <utils/TypeHelpers.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
class Point : public LightFlattenablePod<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;
|
||||
}
|
||||
|
||||
const Point operator + (const Point& rhs) const {
|
||||
const Point result(x+rhs.x, y+rhs.y);
|
||||
return result;
|
||||
}
|
||||
const Point operator - (const Point& rhs) const {
|
||||
const Point result(x-rhs.x, y-rhs.y);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
ANDROID_BASIC_TYPES_TRAITS(Point)
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_UI_POINT
|
||||
197
phonelibs/android_frameworks_native/include/ui/Rect.h
Normal file
197
phonelibs/android_frameworks_native/include/ui/Rect.h
Normal file
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* 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/Flattenable.h>
|
||||
#include <utils/Log.h>
|
||||
#include <utils/TypeHelpers.h>
|
||||
#include <ui/Point.h>
|
||||
|
||||
#include <android/rect.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
class Rect : public ARect, public LightFlattenablePod<Rect>
|
||||
{
|
||||
public:
|
||||
typedef ARect::value_type value_type;
|
||||
|
||||
static const Rect INVALID_RECT;
|
||||
|
||||
// we don't provide copy-ctor and operator= on purpose
|
||||
// because we want the compiler generated versions
|
||||
|
||||
inline Rect() {
|
||||
left = right = top = bottom = 0;
|
||||
}
|
||||
|
||||
inline Rect(int32_t w, int32_t h) {
|
||||
left = top = 0;
|
||||
right = w;
|
||||
bottom = h;
|
||||
}
|
||||
|
||||
inline Rect(uint32_t w, uint32_t h) {
|
||||
if (w > INT32_MAX) {
|
||||
ALOG(LOG_WARN, "Rect",
|
||||
"Width %u too large for Rect class, clamping", w);
|
||||
w = INT32_MAX;
|
||||
}
|
||||
if (h > INT32_MAX) {
|
||||
ALOG(LOG_WARN, "Rect",
|
||||
"Height %u too large for Rect class, clamping", h);
|
||||
h = INT32_MAX;
|
||||
}
|
||||
left = top = 0;
|
||||
right = w;
|
||||
bottom = h;
|
||||
}
|
||||
|
||||
inline Rect(int32_t l, int32_t t, int32_t r, int32_t 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();
|
||||
|
||||
inline void clear() {
|
||||
left = top = right = bottom = 0;
|
||||
}
|
||||
|
||||
// a valid rectangle has a non negative width and height
|
||||
inline bool isValid() const {
|
||||
return (getWidth() >= 0) && (getHeight() >= 0);
|
||||
}
|
||||
|
||||
// an empty rect has a zero width or height, or is invalid
|
||||
inline bool isEmpty() const {
|
||||
return (getWidth() <= 0) || (getHeight() <= 0);
|
||||
}
|
||||
|
||||
// rectangle's width
|
||||
inline int32_t getWidth() const {
|
||||
return right - left;
|
||||
}
|
||||
|
||||
// rectangle's height
|
||||
inline int32_t getHeight() const {
|
||||
return bottom - top;
|
||||
}
|
||||
|
||||
inline Rect getBounds() const {
|
||||
return Rect(right - left, bottom - top);
|
||||
}
|
||||
|
||||
void setLeftTop(const Point& lt) {
|
||||
left = lt.x;
|
||||
top = lt.y;
|
||||
}
|
||||
|
||||
void setRightBottom(const Point& rb) {
|
||||
right = rb.x;
|
||||
bottom = rb.y;
|
||||
}
|
||||
|
||||
// the following 4 functions return the 4 corners of the rect as Point
|
||||
Point leftTop() const {
|
||||
return Point(left, top);
|
||||
}
|
||||
Point rightBottom() const {
|
||||
return Point(right, bottom);
|
||||
}
|
||||
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;
|
||||
|
||||
const Rect operator + (const Point& rhs) const;
|
||||
const Rect operator - (const Point& rhs) const;
|
||||
|
||||
Rect& operator += (const Point& rhs) {
|
||||
return offsetBy(rhs.x, rhs.y);
|
||||
}
|
||||
Rect& operator -= (const Point& rhs) {
|
||||
return offsetBy(-rhs.x, -rhs.y);
|
||||
}
|
||||
|
||||
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& offsetTo(int32_t x, int32_t y);
|
||||
Rect& offsetBy(int32_t x, int32_t y);
|
||||
|
||||
bool intersect(const Rect& with, Rect* result) const;
|
||||
|
||||
// Create a new Rect by transforming this one using a graphics HAL
|
||||
// transform. This rectangle is defined in a coordinate space starting at
|
||||
// the origin and extending to (width, height). If the transform includes
|
||||
// a ROT90 then the output rectangle is defined in a space extending to
|
||||
// (height, width). Otherwise the output rectangle is in the same space as
|
||||
// the input.
|
||||
Rect transform(uint32_t xform, int32_t width, int32_t height) const;
|
||||
|
||||
// this calculates (Region(*this) - exclude).bounds() efficiently
|
||||
Rect reduce(const Rect& exclude) const;
|
||||
|
||||
|
||||
// for backward compatibility
|
||||
inline int32_t width() const { return getWidth(); }
|
||||
inline int32_t height() const { return getHeight(); }
|
||||
inline void set(const Rect& rhs) { operator = (rhs); }
|
||||
};
|
||||
|
||||
ANDROID_BASIC_TYPES_TRAITS(Rect)
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_UI_RECT
|
||||
223
phonelibs/android_frameworks_native/include/ui/Region.h
Normal file
223
phonelibs/android_frameworks_native/include/ui/Region.h
Normal file
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* 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 <ui/Rect.h>
|
||||
#include <utils/Flattenable.h>
|
||||
|
||||
namespace android {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class SharedBuffer;
|
||||
class String8;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
class Region : public LightFlattenable<Region>
|
||||
{
|
||||
public:
|
||||
static const Region INVALID_REGION;
|
||||
|
||||
Region();
|
||||
Region(const Region& rhs);
|
||||
explicit Region(const Rect& rhs);
|
||||
~Region();
|
||||
|
||||
static Region createTJunctionFreeRegion(const Region& r);
|
||||
|
||||
Region& operator = (const Region& rhs);
|
||||
|
||||
inline bool isEmpty() const { return getBounds().isEmpty(); }
|
||||
inline bool isRect() const { return mStorage.size() == 1; }
|
||||
|
||||
inline Rect getBounds() const { return mStorage[mStorage.size() - 1]; }
|
||||
inline Rect bounds() const { return getBounds(); }
|
||||
|
||||
bool contains(const Point& point) const;
|
||||
bool contains(int x, int y) const;
|
||||
|
||||
// the region becomes its bounds
|
||||
Region& makeBoundsSelf();
|
||||
|
||||
void clear();
|
||||
void set(const Rect& r);
|
||||
void set(int32_t w, int32_t h);
|
||||
void set(uint32_t w, uint32_t h);
|
||||
|
||||
Region& orSelf(const Rect& rhs);
|
||||
Region& xorSelf(const Rect& rhs);
|
||||
Region& andSelf(const Rect& rhs);
|
||||
Region& subtractSelf(const Rect& rhs);
|
||||
|
||||
// boolean operators, applied on this
|
||||
Region& orSelf(const Region& rhs);
|
||||
Region& xorSelf(const Region& rhs);
|
||||
Region& andSelf(const Region& rhs);
|
||||
Region& subtractSelf(const Region& rhs);
|
||||
|
||||
// boolean operators
|
||||
const Region merge(const Rect& rhs) const;
|
||||
const Region mergeExclusive(const Rect& rhs) const;
|
||||
const Region intersect(const Rect& rhs) const;
|
||||
const Region subtract(const Rect& rhs) const;
|
||||
|
||||
// boolean operators
|
||||
const Region merge(const Region& rhs) const;
|
||||
const Region mergeExclusive(const Region& rhs) const;
|
||||
const Region intersect(const Region& rhs) const;
|
||||
const Region subtract(const Region& rhs) const;
|
||||
|
||||
// these translate rhs first
|
||||
Region& translateSelf(int dx, int dy);
|
||||
Region& orSelf(const Region& rhs, int dx, int dy);
|
||||
Region& xorSelf(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);
|
||||
|
||||
// these translate rhs first
|
||||
const Region translate(int dx, int dy) const;
|
||||
const Region merge(const Region& rhs, int dx, int dy) const;
|
||||
const Region mergeExclusive(const Region& rhs, int dx, int dy) const;
|
||||
const Region intersect(const Region& rhs, int dx, int dy) const;
|
||||
const Region subtract(const Region& rhs, int dx, int dy) const;
|
||||
|
||||
// convenience operators overloads
|
||||
inline const Region operator | (const Region& rhs) const;
|
||||
inline const Region operator ^ (const Region& rhs) const;
|
||||
inline const Region operator & (const Region& rhs) const;
|
||||
inline const Region operator - (const Region& rhs) const;
|
||||
inline const 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 Region& rhs);
|
||||
inline Region& operator += (const Point& pt);
|
||||
|
||||
|
||||
// returns true if the regions share the same underlying storage
|
||||
bool isTriviallyEqual(const Region& region) const;
|
||||
|
||||
|
||||
/* various ways to access the rectangle list */
|
||||
|
||||
|
||||
// STL-like iterators
|
||||
typedef Rect const* const_iterator;
|
||||
const_iterator begin() const;
|
||||
const_iterator end() const;
|
||||
|
||||
// returns an array of rect which has the same life-time has this
|
||||
// Region object.
|
||||
Rect const* getArray(size_t* count) const;
|
||||
|
||||
// returns a SharedBuffer as well as the number of rects.
|
||||
// ownership is transfered to the caller.
|
||||
// the caller must call SharedBuffer::release() to free the memory.
|
||||
SharedBuffer const* getSharedBuffer(size_t* count) const;
|
||||
|
||||
/* no user serviceable parts here... */
|
||||
|
||||
// add a rectangle to the internal list. This rectangle must
|
||||
// be sorted in Y and X and must not make the region invalid.
|
||||
void addRectUnchecked(int l, int t, int r, int b);
|
||||
|
||||
inline bool isFixedSize() const { return false; }
|
||||
size_t getFlattenedSize() const;
|
||||
status_t flatten(void* buffer, size_t size) const;
|
||||
status_t unflatten(void const* buffer, size_t size);
|
||||
|
||||
void dump(String8& out, const char* what, uint32_t flags=0) const;
|
||||
void dump(const char* what, uint32_t flags=0) const;
|
||||
|
||||
private:
|
||||
class rasterizer;
|
||||
friend class rasterizer;
|
||||
|
||||
Region& operationSelf(const Rect& r, int op);
|
||||
Region& operationSelf(const Region& r, int op);
|
||||
Region& operationSelf(const Region& r, int dx, int dy, int op);
|
||||
const Region operation(const Rect& rhs, int op) const;
|
||||
const Region operation(const Region& rhs, int op) const;
|
||||
const Region operation(const Region& rhs, int dx, int dy, int op) const;
|
||||
|
||||
static void boolean_operation(int op, Region& dst,
|
||||
const Region& lhs, const Region& rhs, int dx, int dy);
|
||||
static void boolean_operation(int op, Region& dst,
|
||||
const Region& lhs, const Rect& rhs, int dx, int dy);
|
||||
|
||||
static void boolean_operation(int op, Region& dst,
|
||||
const Region& lhs, const Region& rhs);
|
||||
static void boolean_operation(int op, Region& dst,
|
||||
const Region& lhs, const Rect& rhs);
|
||||
|
||||
static void translate(Region& reg, int dx, int dy);
|
||||
static void translate(Region& dst, const Region& reg, int dx, int dy);
|
||||
|
||||
static bool validate(const Region& reg,
|
||||
const char* name, bool silent = false);
|
||||
|
||||
// mStorage is a (manually) sorted array of Rects describing the region
|
||||
// with an extra Rect as the last element which is set to the
|
||||
// bounds of the region. However, if the region is
|
||||
// a simple Rect then mStorage contains only that rect.
|
||||
Vector<Rect> mStorage;
|
||||
};
|
||||
|
||||
|
||||
const Region Region::operator | (const Region& rhs) const {
|
||||
return merge(rhs);
|
||||
}
|
||||
const Region Region::operator ^ (const Region& rhs) const {
|
||||
return mergeExclusive(rhs);
|
||||
}
|
||||
const Region Region::operator & (const Region& rhs) const {
|
||||
return intersect(rhs);
|
||||
}
|
||||
const Region Region::operator - (const Region& rhs) const {
|
||||
return subtract(rhs);
|
||||
}
|
||||
const 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 xorSelf(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);
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_UI_REGION_H
|
||||
|
||||
257
phonelibs/android_frameworks_native/include/ui/TMatHelpers.h
Normal file
257
phonelibs/android_frameworks_native/include/ui/TMatHelpers.h
Normal file
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Copyright 2013 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 TMAT_IMPLEMENTATION
|
||||
#error "Don't include TMatHelpers.h directly. use ui/mat*.h instead"
|
||||
#else
|
||||
#undef TMAT_IMPLEMENTATION
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef UI_TMAT_HELPERS_H
|
||||
#define UI_TMAT_HELPERS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <math.h>
|
||||
#include <utils/Debug.h>
|
||||
#include <utils/String8.h>
|
||||
|
||||
#define PURE __attribute__((pure))
|
||||
|
||||
namespace android {
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* No user serviceable parts here.
|
||||
*
|
||||
* Don't use this file directly, instead include ui/mat*.h
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Matrix utilities
|
||||
*/
|
||||
|
||||
namespace matrix {
|
||||
|
||||
inline int PURE transpose(int v) { return v; }
|
||||
inline float PURE transpose(float v) { return v; }
|
||||
inline double PURE transpose(double v) { return v; }
|
||||
|
||||
inline int PURE trace(int v) { return v; }
|
||||
inline float PURE trace(float v) { return v; }
|
||||
inline double PURE trace(double v) { return v; }
|
||||
|
||||
template<typename MATRIX>
|
||||
MATRIX PURE inverse(const MATRIX& src) {
|
||||
|
||||
COMPILE_TIME_ASSERT_FUNCTION_SCOPE( MATRIX::COL_SIZE == MATRIX::ROW_SIZE );
|
||||
|
||||
typename MATRIX::value_type t;
|
||||
const size_t N = MATRIX::col_size();
|
||||
size_t swap;
|
||||
MATRIX tmp(src);
|
||||
MATRIX inverse(1);
|
||||
|
||||
for (size_t i=0 ; i<N ; i++) {
|
||||
// look for largest element in column
|
||||
swap = i;
|
||||
for (size_t j=i+1 ; j<N ; j++) {
|
||||
if (fabs(tmp[j][i]) > fabs(tmp[i][i])) {
|
||||
swap = j;
|
||||
}
|
||||
}
|
||||
|
||||
if (swap != i) {
|
||||
/* swap rows. */
|
||||
for (size_t k=0 ; k<N ; k++) {
|
||||
t = tmp[i][k];
|
||||
tmp[i][k] = tmp[swap][k];
|
||||
tmp[swap][k] = t;
|
||||
|
||||
t = inverse[i][k];
|
||||
inverse[i][k] = inverse[swap][k];
|
||||
inverse[swap][k] = t;
|
||||
}
|
||||
}
|
||||
|
||||
t = 1 / tmp[i][i];
|
||||
for (size_t k=0 ; k<N ; k++) {
|
||||
tmp[i][k] *= t;
|
||||
inverse[i][k] *= t;
|
||||
}
|
||||
for (size_t j=0 ; j<N ; j++) {
|
||||
if (j != i) {
|
||||
t = tmp[j][i];
|
||||
for (size_t k=0 ; k<N ; k++) {
|
||||
tmp[j][k] -= tmp[i][k] * t;
|
||||
inverse[j][k] -= inverse[i][k] * t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return inverse;
|
||||
}
|
||||
|
||||
template<typename MATRIX_R, typename MATRIX_A, typename MATRIX_B>
|
||||
MATRIX_R PURE multiply(const MATRIX_A& lhs, const MATRIX_B& rhs) {
|
||||
// pre-requisite:
|
||||
// lhs : D columns, R rows
|
||||
// rhs : C columns, D rows
|
||||
// res : C columns, R rows
|
||||
|
||||
COMPILE_TIME_ASSERT_FUNCTION_SCOPE( MATRIX_A::ROW_SIZE == MATRIX_B::COL_SIZE );
|
||||
COMPILE_TIME_ASSERT_FUNCTION_SCOPE( MATRIX_R::ROW_SIZE == MATRIX_B::ROW_SIZE );
|
||||
COMPILE_TIME_ASSERT_FUNCTION_SCOPE( MATRIX_R::COL_SIZE == MATRIX_A::COL_SIZE );
|
||||
|
||||
MATRIX_R res(MATRIX_R::NO_INIT);
|
||||
for (size_t r=0 ; r<MATRIX_R::row_size() ; r++) {
|
||||
res[r] = lhs * rhs[r];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// transpose. this handles matrices of matrices
|
||||
template <typename MATRIX>
|
||||
MATRIX PURE transpose(const MATRIX& m) {
|
||||
// for now we only handle square matrix transpose
|
||||
COMPILE_TIME_ASSERT_FUNCTION_SCOPE( MATRIX::ROW_SIZE == MATRIX::COL_SIZE );
|
||||
MATRIX result(MATRIX::NO_INIT);
|
||||
for (size_t r=0 ; r<MATRIX::row_size() ; r++)
|
||||
for (size_t c=0 ; c<MATRIX::col_size() ; c++)
|
||||
result[c][r] = transpose(m[r][c]);
|
||||
return result;
|
||||
}
|
||||
|
||||
// trace. this handles matrices of matrices
|
||||
template <typename MATRIX>
|
||||
typename MATRIX::value_type PURE trace(const MATRIX& m) {
|
||||
COMPILE_TIME_ASSERT_FUNCTION_SCOPE( MATRIX::ROW_SIZE == MATRIX::COL_SIZE );
|
||||
typename MATRIX::value_type result(0);
|
||||
for (size_t r=0 ; r<MATRIX::row_size() ; r++)
|
||||
result += trace(m[r][r]);
|
||||
return result;
|
||||
}
|
||||
|
||||
// trace. this handles matrices of matrices
|
||||
template <typename MATRIX>
|
||||
typename MATRIX::col_type PURE diag(const MATRIX& m) {
|
||||
COMPILE_TIME_ASSERT_FUNCTION_SCOPE( MATRIX::ROW_SIZE == MATRIX::COL_SIZE );
|
||||
typename MATRIX::col_type result(MATRIX::col_type::NO_INIT);
|
||||
for (size_t r=0 ; r<MATRIX::row_size() ; r++)
|
||||
result[r] = m[r][r];
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename MATRIX>
|
||||
String8 asString(const MATRIX& m) {
|
||||
String8 s;
|
||||
for (size_t c=0 ; c<MATRIX::col_size() ; c++) {
|
||||
s.append("| ");
|
||||
for (size_t r=0 ; r<MATRIX::row_size() ; r++) {
|
||||
s.appendFormat("%7.2f ", m[r][c]);
|
||||
}
|
||||
s.append("|\n");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
}; // namespace matrix
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* TMatProductOperators implements basic arithmetic and basic compound assignments
|
||||
* operators on a vector of type BASE<T>.
|
||||
*
|
||||
* BASE only needs to implement operator[] and size().
|
||||
* By simply inheriting from TMatProductOperators<BASE, T> BASE will automatically
|
||||
* get all the functionality here.
|
||||
*/
|
||||
|
||||
template <template<typename T> class BASE, typename T>
|
||||
class TMatProductOperators {
|
||||
public:
|
||||
// multiply by a scalar
|
||||
BASE<T>& operator *= (T v) {
|
||||
BASE<T>& lhs(static_cast< BASE<T>& >(*this));
|
||||
for (size_t r=0 ; r<lhs.row_size() ; r++) {
|
||||
lhs[r] *= v;
|
||||
}
|
||||
return lhs;
|
||||
}
|
||||
|
||||
// divide by a scalar
|
||||
BASE<T>& operator /= (T v) {
|
||||
BASE<T>& lhs(static_cast< BASE<T>& >(*this));
|
||||
for (size_t r=0 ; r<lhs.row_size() ; r++) {
|
||||
lhs[r] /= v;
|
||||
}
|
||||
return lhs;
|
||||
}
|
||||
|
||||
// matrix * matrix, result is a matrix of the same type than the lhs matrix
|
||||
template<typename U>
|
||||
friend BASE<T> PURE operator *(const BASE<T>& lhs, const BASE<U>& rhs) {
|
||||
return matrix::multiply<BASE<T> >(lhs, rhs);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* TMatSquareFunctions implements functions on a matrix of type BASE<T>.
|
||||
*
|
||||
* BASE only needs to implement:
|
||||
* - operator[]
|
||||
* - col_type
|
||||
* - row_type
|
||||
* - COL_SIZE
|
||||
* - ROW_SIZE
|
||||
*
|
||||
* By simply inheriting from TMatSquareFunctions<BASE, T> BASE will automatically
|
||||
* get all the functionality here.
|
||||
*/
|
||||
|
||||
template<template<typename U> class BASE, typename T>
|
||||
class TMatSquareFunctions {
|
||||
public:
|
||||
/*
|
||||
* NOTE: the functions below ARE NOT member methods. They are friend functions
|
||||
* with they definition inlined with their declaration. This makes these
|
||||
* template functions available to the compiler when (and only when) this class
|
||||
* is instantiated, at which point they're only templated on the 2nd parameter
|
||||
* (the first one, BASE<T> being known).
|
||||
*/
|
||||
friend BASE<T> PURE inverse(const BASE<T>& m) { return matrix::inverse(m); }
|
||||
friend BASE<T> PURE transpose(const BASE<T>& m) { return matrix::transpose(m); }
|
||||
friend T PURE trace(const BASE<T>& m) { return matrix::trace(m); }
|
||||
};
|
||||
|
||||
template <template<typename T> class BASE, typename T>
|
||||
class TMatDebug {
|
||||
public:
|
||||
String8 asString() const {
|
||||
return matrix::asString( static_cast< const BASE<T>& >(*this) );
|
||||
}
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
|
||||
#undef PURE
|
||||
|
||||
#endif /* UI_TMAT_HELPERS_H */
|
||||
381
phonelibs/android_frameworks_native/include/ui/TVecHelpers.h
Normal file
381
phonelibs/android_frameworks_native/include/ui/TVecHelpers.h
Normal file
@@ -0,0 +1,381 @@
|
||||
/*
|
||||
* Copyright 2013 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 TVEC_IMPLEMENTATION
|
||||
#error "Don't include TVecHelpers.h directly. use ui/vec*.h instead"
|
||||
#else
|
||||
#undef TVEC_IMPLEMENTATION
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef UI_TVEC_HELPERS_H
|
||||
#define UI_TVEC_HELPERS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define PURE __attribute__((pure))
|
||||
|
||||
namespace android {
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* No user serviceable parts here.
|
||||
*
|
||||
* Don't use this file directly, instead include ui/vec{2|3|4}.h
|
||||
*/
|
||||
|
||||
/*
|
||||
* This class casts itself into anything and assign itself from anything!
|
||||
* Use with caution!
|
||||
*/
|
||||
template <typename TYPE>
|
||||
struct Impersonator {
|
||||
Impersonator& operator = (const TYPE& rhs) {
|
||||
reinterpret_cast<TYPE&>(*this) = rhs;
|
||||
return *this;
|
||||
}
|
||||
operator TYPE& () {
|
||||
return reinterpret_cast<TYPE&>(*this);
|
||||
}
|
||||
operator TYPE const& () const {
|
||||
return reinterpret_cast<TYPE const&>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* TVec{Add|Product}Operators implements basic arithmetic and basic compound assignments
|
||||
* operators on a vector of type BASE<T>.
|
||||
*
|
||||
* BASE only needs to implement operator[] and size().
|
||||
* By simply inheriting from TVec{Add|Product}Operators<BASE, T> BASE will automatically
|
||||
* get all the functionality here.
|
||||
*/
|
||||
|
||||
template <template<typename T> class BASE, typename T>
|
||||
class TVecAddOperators {
|
||||
public:
|
||||
/* compound assignment from a another vector of the same size but different
|
||||
* element type.
|
||||
*/
|
||||
template <typename OTHER>
|
||||
BASE<T>& operator += (const BASE<OTHER>& v) {
|
||||
BASE<T>& rhs = static_cast<BASE<T>&>(*this);
|
||||
for (size_t i=0 ; i<BASE<T>::size() ; i++) {
|
||||
rhs[i] += v[i];
|
||||
}
|
||||
return rhs;
|
||||
}
|
||||
template <typename OTHER>
|
||||
BASE<T>& operator -= (const BASE<OTHER>& v) {
|
||||
BASE<T>& rhs = static_cast<BASE<T>&>(*this);
|
||||
for (size_t i=0 ; i<BASE<T>::size() ; i++) {
|
||||
rhs[i] -= v[i];
|
||||
}
|
||||
return rhs;
|
||||
}
|
||||
|
||||
/* compound assignment from a another vector of the same type.
|
||||
* These operators can be used for implicit conversion and handle operations
|
||||
* like "vector *= scalar" by letting the compiler implicitly convert a scalar
|
||||
* to a vector (assuming the BASE<T> allows it).
|
||||
*/
|
||||
BASE<T>& operator += (const BASE<T>& v) {
|
||||
BASE<T>& rhs = static_cast<BASE<T>&>(*this);
|
||||
for (size_t i=0 ; i<BASE<T>::size() ; i++) {
|
||||
rhs[i] += v[i];
|
||||
}
|
||||
return rhs;
|
||||
}
|
||||
BASE<T>& operator -= (const BASE<T>& v) {
|
||||
BASE<T>& rhs = static_cast<BASE<T>&>(*this);
|
||||
for (size_t i=0 ; i<BASE<T>::size() ; i++) {
|
||||
rhs[i] -= v[i];
|
||||
}
|
||||
return rhs;
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: the functions below ARE NOT member methods. They are friend functions
|
||||
* with they definition inlined with their declaration. This makes these
|
||||
* template functions available to the compiler when (and only when) this class
|
||||
* is instantiated, at which point they're only templated on the 2nd parameter
|
||||
* (the first one, BASE<T> being known).
|
||||
*/
|
||||
|
||||
/* The operators below handle operation between vectors of the same side
|
||||
* but of a different element type.
|
||||
*/
|
||||
template<typename RT>
|
||||
friend inline
|
||||
BASE<T> PURE operator +(const BASE<T>& lv, const BASE<RT>& rv) {
|
||||
return BASE<T>(lv) += rv;
|
||||
}
|
||||
template<typename RT>
|
||||
friend inline
|
||||
BASE<T> PURE operator -(const BASE<T>& lv, const BASE<RT>& rv) {
|
||||
return BASE<T>(lv) -= rv;
|
||||
}
|
||||
|
||||
/* The operators below (which are not templates once this class is instanced,
|
||||
* i.e.: BASE<T> is known) can be used for implicit conversion on both sides.
|
||||
* These handle operations like "vector * scalar" and "scalar * vector" by
|
||||
* letting the compiler implicitly convert a scalar to a vector (assuming
|
||||
* the BASE<T> allows it).
|
||||
*/
|
||||
friend inline
|
||||
BASE<T> PURE operator +(const BASE<T>& lv, const BASE<T>& rv) {
|
||||
return BASE<T>(lv) += rv;
|
||||
}
|
||||
friend inline
|
||||
BASE<T> PURE operator -(const BASE<T>& lv, const BASE<T>& rv) {
|
||||
return BASE<T>(lv) -= rv;
|
||||
}
|
||||
};
|
||||
|
||||
template <template<typename T> class BASE, typename T>
|
||||
class TVecProductOperators {
|
||||
public:
|
||||
/* compound assignment from a another vector of the same size but different
|
||||
* element type.
|
||||
*/
|
||||
template <typename OTHER>
|
||||
BASE<T>& operator *= (const BASE<OTHER>& v) {
|
||||
BASE<T>& rhs = static_cast<BASE<T>&>(*this);
|
||||
for (size_t i=0 ; i<BASE<T>::size() ; i++) {
|
||||
rhs[i] *= v[i];
|
||||
}
|
||||
return rhs;
|
||||
}
|
||||
template <typename OTHER>
|
||||
BASE<T>& operator /= (const BASE<OTHER>& v) {
|
||||
BASE<T>& rhs = static_cast<BASE<T>&>(*this);
|
||||
for (size_t i=0 ; i<BASE<T>::size() ; i++) {
|
||||
rhs[i] /= v[i];
|
||||
}
|
||||
return rhs;
|
||||
}
|
||||
|
||||
/* compound assignment from a another vector of the same type.
|
||||
* These operators can be used for implicit conversion and handle operations
|
||||
* like "vector *= scalar" by letting the compiler implicitly convert a scalar
|
||||
* to a vector (assuming the BASE<T> allows it).
|
||||
*/
|
||||
BASE<T>& operator *= (const BASE<T>& v) {
|
||||
BASE<T>& rhs = static_cast<BASE<T>&>(*this);
|
||||
for (size_t i=0 ; i<BASE<T>::size() ; i++) {
|
||||
rhs[i] *= v[i];
|
||||
}
|
||||
return rhs;
|
||||
}
|
||||
BASE<T>& operator /= (const BASE<T>& v) {
|
||||
BASE<T>& rhs = static_cast<BASE<T>&>(*this);
|
||||
for (size_t i=0 ; i<BASE<T>::size() ; i++) {
|
||||
rhs[i] /= v[i];
|
||||
}
|
||||
return rhs;
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: the functions below ARE NOT member methods. They are friend functions
|
||||
* with they definition inlined with their declaration. This makes these
|
||||
* template functions available to the compiler when (and only when) this class
|
||||
* is instantiated, at which point they're only templated on the 2nd parameter
|
||||
* (the first one, BASE<T> being known).
|
||||
*/
|
||||
|
||||
/* The operators below handle operation between vectors of the same side
|
||||
* but of a different element type.
|
||||
*/
|
||||
template<typename RT>
|
||||
friend inline
|
||||
BASE<T> PURE operator *(const BASE<T>& lv, const BASE<RT>& rv) {
|
||||
return BASE<T>(lv) *= rv;
|
||||
}
|
||||
template<typename RT>
|
||||
friend inline
|
||||
BASE<T> PURE operator /(const BASE<T>& lv, const BASE<RT>& rv) {
|
||||
return BASE<T>(lv) /= rv;
|
||||
}
|
||||
|
||||
/* The operators below (which are not templates once this class is instanced,
|
||||
* i.e.: BASE<T> is known) can be used for implicit conversion on both sides.
|
||||
* These handle operations like "vector * scalar" and "scalar * vector" by
|
||||
* letting the compiler implicitly convert a scalar to a vector (assuming
|
||||
* the BASE<T> allows it).
|
||||
*/
|
||||
friend inline
|
||||
BASE<T> PURE operator *(const BASE<T>& lv, const BASE<T>& rv) {
|
||||
return BASE<T>(lv) *= rv;
|
||||
}
|
||||
friend inline
|
||||
BASE<T> PURE operator /(const BASE<T>& lv, const BASE<T>& rv) {
|
||||
return BASE<T>(lv) /= rv;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* TVecUnaryOperators implements unary operators on a vector of type BASE<T>.
|
||||
*
|
||||
* BASE only needs to implement operator[] and size().
|
||||
* By simply inheriting from TVecUnaryOperators<BASE, T> BASE will automatically
|
||||
* get all the functionality here.
|
||||
*
|
||||
* These operators are implemented as friend functions of TVecUnaryOperators<BASE, T>
|
||||
*/
|
||||
template <template<typename T> class BASE, typename T>
|
||||
class TVecUnaryOperators {
|
||||
public:
|
||||
BASE<T>& operator ++ () {
|
||||
BASE<T>& rhs = static_cast<BASE<T>&>(*this);
|
||||
for (size_t i=0 ; i<BASE<T>::size() ; i++) {
|
||||
++rhs[i];
|
||||
}
|
||||
return rhs;
|
||||
}
|
||||
BASE<T>& operator -- () {
|
||||
BASE<T>& rhs = static_cast<BASE<T>&>(*this);
|
||||
for (size_t i=0 ; i<BASE<T>::size() ; i++) {
|
||||
--rhs[i];
|
||||
}
|
||||
return rhs;
|
||||
}
|
||||
BASE<T> operator - () const {
|
||||
BASE<T> r(BASE<T>::NO_INIT);
|
||||
BASE<T> const& rv(static_cast<BASE<T> const&>(*this));
|
||||
for (size_t i=0 ; i<BASE<T>::size() ; i++) {
|
||||
r[i] = -rv[i];
|
||||
}
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* TVecComparisonOperators implements relational/comparison operators
|
||||
* on a vector of type BASE<T>.
|
||||
*
|
||||
* BASE only needs to implement operator[] and size().
|
||||
* By simply inheriting from TVecComparisonOperators<BASE, T> BASE will automatically
|
||||
* get all the functionality here.
|
||||
*/
|
||||
template <template<typename T> class BASE, typename T>
|
||||
class TVecComparisonOperators {
|
||||
public:
|
||||
/*
|
||||
* NOTE: the functions below ARE NOT member methods. They are friend functions
|
||||
* with they definition inlined with their declaration. This makes these
|
||||
* template functions available to the compiler when (and only when) this class
|
||||
* is instantiated, at which point they're only templated on the 2nd parameter
|
||||
* (the first one, BASE<T> being known).
|
||||
*/
|
||||
template<typename RT>
|
||||
friend inline
|
||||
bool PURE operator ==(const BASE<T>& lv, const BASE<RT>& rv) {
|
||||
for (size_t i = 0; i < BASE<T>::size(); i++)
|
||||
if (lv[i] != rv[i])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename RT>
|
||||
friend inline
|
||||
bool PURE operator !=(const BASE<T>& lv, const BASE<RT>& rv) {
|
||||
return !operator ==(lv, rv);
|
||||
}
|
||||
|
||||
template<typename RT>
|
||||
friend inline
|
||||
bool PURE operator >(const BASE<T>& lv, const BASE<RT>& rv) {
|
||||
for (size_t i = 0; i < BASE<T>::size(); i++)
|
||||
if (lv[i] <= rv[i])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename RT>
|
||||
friend inline
|
||||
bool PURE operator <=(const BASE<T>& lv, const BASE<RT>& rv) {
|
||||
return !(lv > rv);
|
||||
}
|
||||
|
||||
template<typename RT>
|
||||
friend inline
|
||||
bool PURE operator <(const BASE<T>& lv, const BASE<RT>& rv) {
|
||||
for (size_t i = 0; i < BASE<T>::size(); i++)
|
||||
if (lv[i] >= rv[i])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename RT>
|
||||
friend inline
|
||||
bool PURE operator >=(const BASE<T>& lv, const BASE<RT>& rv) {
|
||||
return !(lv < rv);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* TVecFunctions implements functions on a vector of type BASE<T>.
|
||||
*
|
||||
* BASE only needs to implement operator[] and size().
|
||||
* By simply inheriting from TVecFunctions<BASE, T> BASE will automatically
|
||||
* get all the functionality here.
|
||||
*/
|
||||
template <template<typename T> class BASE, typename T>
|
||||
class TVecFunctions {
|
||||
public:
|
||||
/*
|
||||
* NOTE: the functions below ARE NOT member methods. They are friend functions
|
||||
* with they definition inlined with their declaration. This makes these
|
||||
* template functions available to the compiler when (and only when) this class
|
||||
* is instantiated, at which point they're only templated on the 2nd parameter
|
||||
* (the first one, BASE<T> being known).
|
||||
*/
|
||||
template<typename RT>
|
||||
friend inline
|
||||
T PURE dot(const BASE<T>& lv, const BASE<RT>& rv) {
|
||||
T r(0);
|
||||
for (size_t i = 0; i < BASE<T>::size(); i++)
|
||||
r += lv[i]*rv[i];
|
||||
return r;
|
||||
}
|
||||
|
||||
friend inline
|
||||
T PURE length(const BASE<T>& lv) {
|
||||
return sqrt( dot(lv, lv) );
|
||||
}
|
||||
|
||||
template<typename RT>
|
||||
friend inline
|
||||
T PURE distance(const BASE<T>& lv, const BASE<RT>& rv) {
|
||||
return length(rv - lv);
|
||||
}
|
||||
|
||||
friend inline
|
||||
BASE<T> PURE normalize(const BASE<T>& lv) {
|
||||
return lv * (1 / length(lv));
|
||||
}
|
||||
};
|
||||
|
||||
#undef PURE
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
|
||||
|
||||
#endif /* UI_TVEC_HELPERS_H */
|
||||
29
phonelibs/android_frameworks_native/include/ui/UiConfig.h
Normal file
29
phonelibs/android_frameworks_native/include/ui/UiConfig.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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_CONFIG_H
|
||||
#define ANDROID_UI_CONFIG_H
|
||||
|
||||
#include <utils/String8.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
// Append the libui configuration details to configStr.
|
||||
void appendUiConfigString(String8& configStr);
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif /*ANDROID_UI_CONFIG_H*/
|
||||
395
phonelibs/android_frameworks_native/include/ui/mat4.h
Normal file
395
phonelibs/android_frameworks_native/include/ui/mat4.h
Normal file
@@ -0,0 +1,395 @@
|
||||
/*
|
||||
* Copyright 2013 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_MAT4_H
|
||||
#define UI_MAT4_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ui/vec4.h>
|
||||
#include <utils/String8.h>
|
||||
|
||||
#define TMAT_IMPLEMENTATION
|
||||
#include <ui/TMatHelpers.h>
|
||||
|
||||
#define PURE __attribute__((pure))
|
||||
|
||||
namespace android {
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
template <typename T>
|
||||
class tmat44 : public TVecUnaryOperators<tmat44, T>,
|
||||
public TVecComparisonOperators<tmat44, T>,
|
||||
public TVecAddOperators<tmat44, T>,
|
||||
public TMatProductOperators<tmat44, T>,
|
||||
public TMatSquareFunctions<tmat44, T>,
|
||||
public TMatDebug<tmat44, T>
|
||||
{
|
||||
public:
|
||||
enum no_init { NO_INIT };
|
||||
typedef T value_type;
|
||||
typedef T& reference;
|
||||
typedef T const& const_reference;
|
||||
typedef size_t size_type;
|
||||
typedef tvec4<T> col_type;
|
||||
typedef tvec4<T> row_type;
|
||||
|
||||
// size of a column (i.e.: number of rows)
|
||||
enum { COL_SIZE = col_type::SIZE };
|
||||
static inline size_t col_size() { return COL_SIZE; }
|
||||
|
||||
// size of a row (i.e.: number of columns)
|
||||
enum { ROW_SIZE = row_type::SIZE };
|
||||
static inline size_t row_size() { return ROW_SIZE; }
|
||||
static inline size_t size() { return row_size(); } // for TVec*<>
|
||||
|
||||
private:
|
||||
|
||||
/*
|
||||
* <-- N columns -->
|
||||
*
|
||||
* a00 a10 a20 ... aN0 ^
|
||||
* a01 a11 a21 ... aN1 |
|
||||
* a02 a12 a22 ... aN2 M rows
|
||||
* ... |
|
||||
* a0M a1M a2M ... aNM v
|
||||
*
|
||||
* COL_SIZE = M
|
||||
* ROW_SIZE = N
|
||||
* m[0] = [a00 a01 a02 ... a01M]
|
||||
*/
|
||||
|
||||
col_type mValue[ROW_SIZE];
|
||||
|
||||
public:
|
||||
// array access
|
||||
inline col_type const& operator [] (size_t i) const { return mValue[i]; }
|
||||
inline col_type& operator [] (size_t i) { return mValue[i]; }
|
||||
|
||||
T const* asArray() const { return &mValue[0][0]; }
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// we don't provide copy-ctor and operator= on purpose
|
||||
// because we want the compiler generated versions
|
||||
|
||||
/*
|
||||
* constructors
|
||||
*/
|
||||
|
||||
// leaves object uninitialized. use with caution.
|
||||
explicit tmat44(no_init) { }
|
||||
|
||||
// initialize to identity
|
||||
tmat44();
|
||||
|
||||
// initialize to Identity*scalar.
|
||||
template<typename U>
|
||||
explicit tmat44(U v);
|
||||
|
||||
// sets the diagonal to the passed vector
|
||||
template <typename U>
|
||||
explicit tmat44(const tvec4<U>& rhs);
|
||||
|
||||
// construct from another matrix of the same size
|
||||
template <typename U>
|
||||
explicit tmat44(const tmat44<U>& rhs);
|
||||
|
||||
// construct from 4 column vectors
|
||||
template <typename A, typename B, typename C, typename D>
|
||||
tmat44(const tvec4<A>& v0, const tvec4<B>& v1, const tvec4<C>& v2, const tvec4<D>& v3);
|
||||
|
||||
// construct from 16 scalars
|
||||
template <
|
||||
typename A, typename B, typename C, typename D,
|
||||
typename E, typename F, typename G, typename H,
|
||||
typename I, typename J, typename K, typename L,
|
||||
typename M, typename N, typename O, typename P>
|
||||
tmat44( A m00, B m01, C m02, D m03,
|
||||
E m10, F m11, G m12, H m13,
|
||||
I m20, J m21, K m22, L m23,
|
||||
M m30, N m31, O m32, P m33);
|
||||
|
||||
// construct from a C array
|
||||
template <typename U>
|
||||
explicit tmat44(U const* rawArray);
|
||||
|
||||
/*
|
||||
* helpers
|
||||
*/
|
||||
|
||||
static tmat44 ortho(T left, T right, T bottom, T top, T near, T far);
|
||||
|
||||
static tmat44 frustum(T left, T right, T bottom, T top, T near, T far);
|
||||
|
||||
template <typename A, typename B, typename C>
|
||||
static tmat44 lookAt(const tvec3<A>& eye, const tvec3<B>& center, const tvec3<C>& up);
|
||||
|
||||
template <typename A>
|
||||
static tmat44 translate(const tvec4<A>& t);
|
||||
|
||||
template <typename A>
|
||||
static tmat44 scale(const tvec4<A>& s);
|
||||
|
||||
template <typename A, typename B>
|
||||
static tmat44 rotate(A radian, const tvec3<B>& about);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// Constructors
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Since the matrix code could become pretty big quickly, we don't inline most
|
||||
* operations.
|
||||
*/
|
||||
|
||||
template <typename T>
|
||||
tmat44<T>::tmat44() {
|
||||
mValue[0] = col_type(1,0,0,0);
|
||||
mValue[1] = col_type(0,1,0,0);
|
||||
mValue[2] = col_type(0,0,1,0);
|
||||
mValue[3] = col_type(0,0,0,1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
tmat44<T>::tmat44(U v) {
|
||||
mValue[0] = col_type(v,0,0,0);
|
||||
mValue[1] = col_type(0,v,0,0);
|
||||
mValue[2] = col_type(0,0,v,0);
|
||||
mValue[3] = col_type(0,0,0,v);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
tmat44<T>::tmat44(const tvec4<U>& v) {
|
||||
mValue[0] = col_type(v.x,0,0,0);
|
||||
mValue[1] = col_type(0,v.y,0,0);
|
||||
mValue[2] = col_type(0,0,v.z,0);
|
||||
mValue[3] = col_type(0,0,0,v.w);
|
||||
}
|
||||
|
||||
// construct from 16 scalars
|
||||
template<typename T>
|
||||
template <
|
||||
typename A, typename B, typename C, typename D,
|
||||
typename E, typename F, typename G, typename H,
|
||||
typename I, typename J, typename K, typename L,
|
||||
typename M, typename N, typename O, typename P>
|
||||
tmat44<T>::tmat44( A m00, B m01, C m02, D m03,
|
||||
E m10, F m11, G m12, H m13,
|
||||
I m20, J m21, K m22, L m23,
|
||||
M m30, N m31, O m32, P m33) {
|
||||
mValue[0] = col_type(m00, m01, m02, m03);
|
||||
mValue[1] = col_type(m10, m11, m12, m13);
|
||||
mValue[2] = col_type(m20, m21, m22, m23);
|
||||
mValue[3] = col_type(m30, m31, m32, m33);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
tmat44<T>::tmat44(const tmat44<U>& rhs) {
|
||||
for (size_t r=0 ; r<row_size() ; r++)
|
||||
mValue[r] = rhs[r];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename A, typename B, typename C, typename D>
|
||||
tmat44<T>::tmat44(const tvec4<A>& v0, const tvec4<B>& v1, const tvec4<C>& v2, const tvec4<D>& v3) {
|
||||
mValue[0] = v0;
|
||||
mValue[1] = v1;
|
||||
mValue[2] = v2;
|
||||
mValue[3] = v3;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
tmat44<T>::tmat44(U const* rawArray) {
|
||||
for (size_t r=0 ; r<row_size() ; r++)
|
||||
for (size_t c=0 ; c<col_size() ; c++)
|
||||
mValue[r][c] = *rawArray++;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <typename T>
|
||||
tmat44<T> tmat44<T>::ortho(T left, T right, T bottom, T top, T near, T far) {
|
||||
tmat44<T> m;
|
||||
m[0][0] = 2 / (right - left);
|
||||
m[1][1] = 2 / (top - bottom);
|
||||
m[2][2] = -2 / (far - near);
|
||||
m[3][0] = -(right + left) / (right - left);
|
||||
m[3][1] = -(top + bottom) / (top - bottom);
|
||||
m[3][2] = -(far + near) / (far - near);
|
||||
return m;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
tmat44<T> tmat44<T>::frustum(T left, T right, T bottom, T top, T near, T far) {
|
||||
tmat44<T> m;
|
||||
T A = (right + left) / (right - left);
|
||||
T B = (top + bottom) / (top - bottom);
|
||||
T C = (far + near) / (far - near);
|
||||
T D = (2 * far * near) / (far - near);
|
||||
m[0][0] = (2 * near) / (right - left);
|
||||
m[1][1] = (2 * near) / (top - bottom);
|
||||
m[2][0] = A;
|
||||
m[2][1] = B;
|
||||
m[2][2] = C;
|
||||
m[2][3] =-1;
|
||||
m[3][2] = D;
|
||||
m[3][3] = 0;
|
||||
return m;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename A, typename B, typename C>
|
||||
tmat44<T> tmat44<T>::lookAt(const tvec3<A>& eye, const tvec3<B>& center, const tvec3<C>& up) {
|
||||
tvec3<T> L(normalize(center - eye));
|
||||
tvec3<T> S(normalize( cross(L, up) ));
|
||||
tvec3<T> U(cross(S, L));
|
||||
return tmat44<T>(
|
||||
tvec4<T>( S, 0),
|
||||
tvec4<T>( U, 0),
|
||||
tvec4<T>(-L, 0),
|
||||
tvec4<T>(-eye, 1));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename A>
|
||||
tmat44<T> tmat44<T>::translate(const tvec4<A>& t) {
|
||||
tmat44<T> r;
|
||||
r[3] = t;
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename A>
|
||||
tmat44<T> tmat44<T>::scale(const tvec4<A>& s) {
|
||||
tmat44<T> r;
|
||||
r[0][0] = s[0];
|
||||
r[1][1] = s[1];
|
||||
r[2][2] = s[2];
|
||||
r[3][3] = s[3];
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename A, typename B>
|
||||
tmat44<T> tmat44<T>::rotate(A radian, const tvec3<B>& about) {
|
||||
tmat44<T> rotation;
|
||||
T* r = const_cast<T*>(rotation.asArray());
|
||||
T c = cos(radian);
|
||||
T s = sin(radian);
|
||||
if (about.x==1 && about.y==0 && about.z==0) {
|
||||
r[5] = c; r[10]= c;
|
||||
r[6] = s; r[9] = -s;
|
||||
} else if (about.x==0 && about.y==1 && about.z==0) {
|
||||
r[0] = c; r[10]= c;
|
||||
r[8] = s; r[2] = -s;
|
||||
} else if (about.x==0 && about.y==0 && about.z==1) {
|
||||
r[0] = c; r[5] = c;
|
||||
r[1] = s; r[4] = -s;
|
||||
} else {
|
||||
tvec3<B> nabout = normalize(about);
|
||||
B x = nabout.x;
|
||||
B y = nabout.y;
|
||||
B z = nabout.z;
|
||||
T nc = 1 - c;
|
||||
T xy = x * y;
|
||||
T yz = y * z;
|
||||
T zx = z * x;
|
||||
T xs = x * s;
|
||||
T ys = y * s;
|
||||
T zs = z * s;
|
||||
r[ 0] = x*x*nc + c; r[ 4] = xy*nc - zs; r[ 8] = zx*nc + ys;
|
||||
r[ 1] = xy*nc + zs; r[ 5] = y*y*nc + c; r[ 9] = yz*nc - xs;
|
||||
r[ 2] = zx*nc - ys; r[ 6] = yz*nc + xs; r[10] = z*z*nc + c;
|
||||
}
|
||||
return rotation;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// Arithmetic operators outside of class
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
/* We use non-friend functions here to prevent the compiler from using
|
||||
* implicit conversions, for instance of a scalar to a vector. The result would
|
||||
* not be what the caller expects.
|
||||
*
|
||||
* Also note that the order of the arguments in the inner loop is important since
|
||||
* it determines the output type (only relevant when T != U).
|
||||
*/
|
||||
|
||||
// matrix * vector, result is a vector of the same type than the input vector
|
||||
template <typename T, typename U>
|
||||
typename tmat44<U>::col_type PURE operator *(const tmat44<T>& lv, const tvec4<U>& rv) {
|
||||
typename tmat44<U>::col_type result;
|
||||
for (size_t r=0 ; r<tmat44<T>::row_size() ; r++)
|
||||
result += rv[r]*lv[r];
|
||||
return result;
|
||||
}
|
||||
|
||||
// vector * matrix, result is a vector of the same type than the input vector
|
||||
template <typename T, typename U>
|
||||
typename tmat44<U>::row_type PURE operator *(const tvec4<U>& rv, const tmat44<T>& lv) {
|
||||
typename tmat44<U>::row_type result(tmat44<U>::row_type::NO_INIT);
|
||||
for (size_t r=0 ; r<tmat44<T>::row_size() ; r++)
|
||||
result[r] = dot(rv, lv[r]);
|
||||
return result;
|
||||
}
|
||||
|
||||
// matrix * scalar, result is a matrix of the same type than the input matrix
|
||||
template <typename T, typename U>
|
||||
tmat44<T> PURE operator *(const tmat44<T>& lv, U rv) {
|
||||
tmat44<T> result(tmat44<T>::NO_INIT);
|
||||
for (size_t r=0 ; r<tmat44<T>::row_size() ; r++)
|
||||
result[r] = lv[r]*rv;
|
||||
return result;
|
||||
}
|
||||
|
||||
// scalar * matrix, result is a matrix of the same type than the input matrix
|
||||
template <typename T, typename U>
|
||||
tmat44<T> PURE operator *(U rv, const tmat44<T>& lv) {
|
||||
tmat44<T> result(tmat44<T>::NO_INIT);
|
||||
for (size_t r=0 ; r<tmat44<T>::row_size() ; r++)
|
||||
result[r] = lv[r]*rv;
|
||||
return result;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
/* FIXME: this should go into TMatSquareFunctions<> but for some reason
|
||||
* BASE<T>::col_type is not accessible from there (???)
|
||||
*/
|
||||
template<typename T>
|
||||
typename tmat44<T>::col_type PURE diag(const tmat44<T>& m) {
|
||||
return matrix::diag(m);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
typedef tmat44<float> mat4;
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
|
||||
#undef PURE
|
||||
|
||||
#endif /* UI_MAT4_H */
|
||||
91
phonelibs/android_frameworks_native/include/ui/vec2.h
Normal file
91
phonelibs/android_frameworks_native/include/ui/vec2.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright 2013 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_VEC2_H
|
||||
#define UI_VEC2_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define TVEC_IMPLEMENTATION
|
||||
#include <ui/TVecHelpers.h>
|
||||
|
||||
namespace android {
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
template <typename T>
|
||||
class tvec2 : public TVecProductOperators<tvec2, T>,
|
||||
public TVecAddOperators<tvec2, T>,
|
||||
public TVecUnaryOperators<tvec2, T>,
|
||||
public TVecComparisonOperators<tvec2, T>,
|
||||
public TVecFunctions<tvec2, T>
|
||||
{
|
||||
public:
|
||||
enum no_init { NO_INIT };
|
||||
typedef T value_type;
|
||||
typedef T& reference;
|
||||
typedef T const& const_reference;
|
||||
typedef size_t size_type;
|
||||
|
||||
union {
|
||||
struct { T x, y; };
|
||||
struct { T s, t; };
|
||||
struct { T r, g; };
|
||||
};
|
||||
|
||||
enum { SIZE = 2 };
|
||||
inline static size_type size() { return SIZE; }
|
||||
|
||||
// array access
|
||||
inline T const& operator [] (size_t i) const { return (&x)[i]; }
|
||||
inline T& operator [] (size_t i) { return (&x)[i]; }
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// we don't provide copy-ctor and operator= on purpose
|
||||
// because we want the compiler generated versions
|
||||
|
||||
// constructors
|
||||
|
||||
// leaves object uninitialized. use with caution.
|
||||
explicit tvec2(no_init) { }
|
||||
|
||||
// default constructor
|
||||
tvec2() : x(0), y(0) { }
|
||||
|
||||
// handles implicit conversion to a tvec4. must not be explicit.
|
||||
template<typename A>
|
||||
tvec2(A v) : x(v), y(v) { }
|
||||
|
||||
template<typename A, typename B>
|
||||
tvec2(A x, B y) : x(x), y(y) { }
|
||||
|
||||
template<typename A>
|
||||
explicit tvec2(const tvec2<A>& v) : x(v.x), y(v.y) { }
|
||||
|
||||
template<typename A>
|
||||
tvec2(const Impersonator< tvec2<A> >& v)
|
||||
: x(((const tvec2<A>&)v).x),
|
||||
y(((const tvec2<A>&)v).y) { }
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
typedef tvec2<float> vec2;
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
|
||||
#endif /* UI_VEC4_H */
|
||||
113
phonelibs/android_frameworks_native/include/ui/vec3.h
Normal file
113
phonelibs/android_frameworks_native/include/ui/vec3.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright 2013 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_VEC3_H
|
||||
#define UI_VEC3_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ui/vec2.h>
|
||||
|
||||
namespace android {
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
template <typename T>
|
||||
class tvec3 : public TVecProductOperators<tvec3, T>,
|
||||
public TVecAddOperators<tvec3, T>,
|
||||
public TVecUnaryOperators<tvec3, T>,
|
||||
public TVecComparisonOperators<tvec3, T>,
|
||||
public TVecFunctions<tvec3, T>
|
||||
{
|
||||
public:
|
||||
enum no_init { NO_INIT };
|
||||
typedef T value_type;
|
||||
typedef T& reference;
|
||||
typedef T const& const_reference;
|
||||
typedef size_t size_type;
|
||||
|
||||
union {
|
||||
struct { T x, y, z; };
|
||||
struct { T s, t, p; };
|
||||
struct { T r, g, b; };
|
||||
Impersonator< tvec2<T> > xy;
|
||||
Impersonator< tvec2<T> > st;
|
||||
Impersonator< tvec2<T> > rg;
|
||||
};
|
||||
|
||||
enum { SIZE = 3 };
|
||||
inline static size_type size() { return SIZE; }
|
||||
|
||||
// array access
|
||||
inline T const& operator [] (size_t i) const { return (&x)[i]; }
|
||||
inline T& operator [] (size_t i) { return (&x)[i]; }
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// we don't provide copy-ctor and operator= on purpose
|
||||
// because we want the compiler generated versions
|
||||
|
||||
// constructors
|
||||
// leaves object uninitialized. use with caution.
|
||||
explicit tvec3(no_init) { }
|
||||
|
||||
// default constructor
|
||||
tvec3() : x(0), y(0), z(0) { }
|
||||
|
||||
// handles implicit conversion to a tvec4. must not be explicit.
|
||||
template<typename A>
|
||||
tvec3(A v) : x(v), y(v), z(v) { }
|
||||
|
||||
template<typename A, typename B, typename C>
|
||||
tvec3(A x, B y, C z) : x(x), y(y), z(z) { }
|
||||
|
||||
template<typename A, typename B>
|
||||
tvec3(const tvec2<A>& v, B z) : x(v.x), y(v.y), z(z) { }
|
||||
|
||||
template<typename A>
|
||||
explicit tvec3(const tvec3<A>& v) : x(v.x), y(v.y), z(v.z) { }
|
||||
|
||||
template<typename A>
|
||||
tvec3(const Impersonator< tvec3<A> >& v)
|
||||
: x(((const tvec3<A>&)v).x),
|
||||
y(((const tvec3<A>&)v).y),
|
||||
z(((const tvec3<A>&)v).z) { }
|
||||
|
||||
template<typename A, typename B>
|
||||
tvec3(const Impersonator< tvec2<A> >& v, B z)
|
||||
: x(((const tvec2<A>&)v).x),
|
||||
y(((const tvec2<A>&)v).y),
|
||||
z(z) { }
|
||||
|
||||
// cross product works only on vectors of size 3
|
||||
template <typename RT>
|
||||
friend inline
|
||||
tvec3 __attribute__((pure)) cross(const tvec3& u, const tvec3<RT>& v) {
|
||||
return tvec3(
|
||||
u.y*v.z - u.z*v.y,
|
||||
u.z*v.x - u.x*v.z,
|
||||
u.x*v.y - u.y*v.x);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
typedef tvec3<float> vec3;
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
|
||||
#endif /* UI_VEC4_H */
|
||||
118
phonelibs/android_frameworks_native/include/ui/vec4.h
Normal file
118
phonelibs/android_frameworks_native/include/ui/vec4.h
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright 2013 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_VEC4_H
|
||||
#define UI_VEC4_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ui/vec3.h>
|
||||
|
||||
namespace android {
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
template <typename T>
|
||||
class tvec4 : public TVecProductOperators<tvec4, T>,
|
||||
public TVecAddOperators<tvec4, T>,
|
||||
public TVecUnaryOperators<tvec4, T>,
|
||||
public TVecComparisonOperators<tvec4, T>,
|
||||
public TVecFunctions<tvec4, T>
|
||||
{
|
||||
public:
|
||||
enum no_init { NO_INIT };
|
||||
typedef T value_type;
|
||||
typedef T& reference;
|
||||
typedef T const& const_reference;
|
||||
typedef size_t size_type;
|
||||
|
||||
union {
|
||||
struct { T x, y, z, w; };
|
||||
struct { T s, t, p, q; };
|
||||
struct { T r, g, b, a; };
|
||||
Impersonator< tvec2<T> > xy;
|
||||
Impersonator< tvec2<T> > st;
|
||||
Impersonator< tvec2<T> > rg;
|
||||
Impersonator< tvec3<T> > xyz;
|
||||
Impersonator< tvec3<T> > stp;
|
||||
Impersonator< tvec3<T> > rgb;
|
||||
};
|
||||
|
||||
enum { SIZE = 4 };
|
||||
inline static size_type size() { return SIZE; }
|
||||
|
||||
// array access
|
||||
inline T const& operator [] (size_t i) const { return (&x)[i]; }
|
||||
inline T& operator [] (size_t i) { return (&x)[i]; }
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// we don't provide copy-ctor and operator= on purpose
|
||||
// because we want the compiler generated versions
|
||||
|
||||
// constructors
|
||||
|
||||
// leaves object uninitialized. use with caution.
|
||||
explicit tvec4(no_init) { }
|
||||
|
||||
// default constructor
|
||||
tvec4() : x(0), y(0), z(0), w(0) { }
|
||||
|
||||
// handles implicit conversion to a tvec4. must not be explicit.
|
||||
template<typename A>
|
||||
tvec4(A v) : x(v), y(v), z(v), w(v) { }
|
||||
|
||||
template<typename A, typename B, typename C, typename D>
|
||||
tvec4(A x, B y, C z, D w) : x(x), y(y), z(z), w(w) { }
|
||||
|
||||
template<typename A, typename B, typename C>
|
||||
tvec4(const tvec2<A>& v, B z, C w) : x(v.x), y(v.y), z(z), w(w) { }
|
||||
|
||||
template<typename A, typename B>
|
||||
tvec4(const tvec3<A>& v, B w) : x(v.x), y(v.y), z(v.z), w(w) { }
|
||||
|
||||
template<typename A>
|
||||
explicit tvec4(const tvec4<A>& v) : x(v.x), y(v.y), z(v.z), w(v.w) { }
|
||||
|
||||
template<typename A>
|
||||
tvec4(const Impersonator< tvec4<A> >& v)
|
||||
: x(((const tvec4<A>&)v).x),
|
||||
y(((const tvec4<A>&)v).y),
|
||||
z(((const tvec4<A>&)v).z),
|
||||
w(((const tvec4<A>&)v).w) { }
|
||||
|
||||
template<typename A, typename B>
|
||||
tvec4(const Impersonator< tvec3<A> >& v, B w)
|
||||
: x(((const tvec3<A>&)v).x),
|
||||
y(((const tvec3<A>&)v).y),
|
||||
z(((const tvec3<A>&)v).z),
|
||||
w(w) { }
|
||||
|
||||
template<typename A, typename B, typename C>
|
||||
tvec4(const Impersonator< tvec2<A> >& v, B z, C w)
|
||||
: x(((const tvec2<A>&)v).x),
|
||||
y(((const tvec2<A>&)v).y),
|
||||
z(z),
|
||||
w(w) { }
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
typedef tvec4<float> vec4;
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
|
||||
#endif /* UI_VEC4_H */
|
||||
Reference in New Issue
Block a user