Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 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 UTILS_BITSET_H
|
|
|
|
#define UTILS_BITSET_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2012-03-16 21:45:49 +00:00
|
|
|
#include <utils/TypeHelpers.h>
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
/*
|
2020-07-11 23:38:19 +00:00
|
|
|
* A class to provide efficient manipulation of bitsets.
|
2017-12-19 00:14:13 +00:00
|
|
|
*
|
2020-07-11 23:38:19 +00:00
|
|
|
* Consider using std::bitset<32> or std::bitset<64> if all you want is a class to do basic bit
|
|
|
|
* manipulation (i.e. AND / OR / XOR / flip / etc). These classes are only needed if you want to
|
|
|
|
* efficiently perform operations like finding the first set bit in a bitset and you want to
|
|
|
|
* avoid using the built-in functions (e.g. __builtin_clz) on std::bitset::to_ulong.
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
// A simple set of 32 bits that can be individually marked or cleared.
|
|
|
|
struct BitSet32 {
|
|
|
|
uint32_t value;
|
|
|
|
|
2014-03-19 18:23:01 +00:00
|
|
|
inline BitSet32() : value(0UL) { }
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
explicit inline BitSet32(uint32_t value) : value(value) { }
|
|
|
|
|
|
|
|
// Gets the value associated with a particular bit index.
|
2014-03-19 18:23:01 +00:00
|
|
|
static inline uint32_t valueForBit(uint32_t n) { return 0x80000000UL >> n; }
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
// Clears the bit set.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline void clear() { clear(value); }
|
|
|
|
|
|
|
|
static inline void clear(uint32_t& value) { value = 0UL; }
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
// Returns the number of marked bits in the set.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t count() const { return count(value); }
|
|
|
|
|
2020-07-11 23:07:14 +00:00
|
|
|
static inline uint32_t count(uint32_t value) {
|
|
|
|
return static_cast<uint32_t>(__builtin_popcountl(value));
|
|
|
|
}
|
2010-09-27 05:20:12 +00:00
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// Returns true if the bit set does not contain any marked bits.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline bool isEmpty() const { return isEmpty(value); }
|
|
|
|
|
|
|
|
static inline bool isEmpty(uint32_t value) { return ! value; }
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2011-07-02 00:59:27 +00:00
|
|
|
// Returns true if the bit set does not contain any unmarked bits.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline bool isFull() const { return isFull(value); }
|
|
|
|
|
|
|
|
static inline bool isFull(uint32_t value) { return value == 0xffffffffUL; }
|
2011-07-02 00:59:27 +00:00
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// Returns true if the specified bit is marked.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline bool hasBit(uint32_t n) const { return hasBit(value, n); }
|
|
|
|
|
|
|
|
static inline bool hasBit(uint32_t value, uint32_t n) { return value & valueForBit(n); }
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
// Marks the specified bit.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline void markBit(uint32_t n) { markBit(value, n); }
|
|
|
|
|
|
|
|
static inline void markBit (uint32_t& value, uint32_t n) { value |= valueForBit(n); }
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
// Clears the specified bit.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline void clearBit(uint32_t n) { clearBit(value, n); }
|
|
|
|
|
|
|
|
static inline void clearBit(uint32_t& value, uint32_t n) { value &= ~ valueForBit(n); }
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
// Finds the first marked bit in the set.
|
|
|
|
// Result is undefined if all bits are unmarked.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t firstMarkedBit() const { return firstMarkedBit(value); }
|
|
|
|
|
2014-04-12 01:23:11 +00:00
|
|
|
static uint32_t firstMarkedBit(uint32_t value) { return clz_checked(value); }
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
// Finds the first unmarked bit in the set.
|
|
|
|
// Result is undefined if all bits are marked.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t firstUnmarkedBit() const { return firstUnmarkedBit(value); }
|
|
|
|
|
2014-04-12 01:23:11 +00:00
|
|
|
static inline uint32_t firstUnmarkedBit(uint32_t value) { return clz_checked(~ value); }
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2011-03-15 02:39:54 +00:00
|
|
|
// Finds the last marked bit in the set.
|
|
|
|
// Result is undefined if all bits are unmarked.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t lastMarkedBit() const { return lastMarkedBit(value); }
|
|
|
|
|
2014-04-12 01:23:11 +00:00
|
|
|
static inline uint32_t lastMarkedBit(uint32_t value) { return 31 - ctz_checked(value); }
|
2011-03-15 02:39:54 +00:00
|
|
|
|
2011-07-27 23:04:54 +00:00
|
|
|
// Finds the first marked bit in the set and clears it. Returns the bit index.
|
|
|
|
// Result is undefined if all bits are unmarked.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t clearFirstMarkedBit() { return clearFirstMarkedBit(value); }
|
|
|
|
|
|
|
|
static inline uint32_t clearFirstMarkedBit(uint32_t& value) {
|
|
|
|
uint32_t n = firstMarkedBit(value);
|
|
|
|
clearBit(value, n);
|
2011-07-27 23:04:54 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finds the first unmarked bit in the set and marks it. Returns the bit index.
|
|
|
|
// Result is undefined if all bits are marked.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t markFirstUnmarkedBit() { return markFirstUnmarkedBit(value); }
|
|
|
|
|
|
|
|
static inline uint32_t markFirstUnmarkedBit(uint32_t& value) {
|
|
|
|
uint32_t n = firstUnmarkedBit(value);
|
|
|
|
markBit(value, n);
|
2011-07-27 23:04:54 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finds the last marked bit in the set and clears it. Returns the bit index.
|
|
|
|
// Result is undefined if all bits are unmarked.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t clearLastMarkedBit() { return clearLastMarkedBit(value); }
|
|
|
|
|
|
|
|
static inline uint32_t clearLastMarkedBit(uint32_t& value) {
|
|
|
|
uint32_t n = lastMarkedBit(value);
|
|
|
|
clearBit(value, n);
|
2011-07-27 23:04:54 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-03-10 01:39:48 +00:00
|
|
|
// Gets the index of the specified bit in the set, which is the number of
|
|
|
|
// marked bits that appear before the specified bit.
|
|
|
|
inline uint32_t getIndexOfBit(uint32_t n) const {
|
2014-03-19 18:23:01 +00:00
|
|
|
return getIndexOfBit(value, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t getIndexOfBit(uint32_t value, uint32_t n) {
|
2020-07-11 23:07:14 +00:00
|
|
|
return static_cast<uint32_t>(__builtin_popcountl(value & ~(0xffffffffUL >> n)));
|
2011-03-10 01:39:48 +00:00
|
|
|
}
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
inline bool operator== (const BitSet32& other) const { return value == other.value; }
|
|
|
|
inline bool operator!= (const BitSet32& other) const { return value != other.value; }
|
2013-05-21 21:11:34 +00:00
|
|
|
inline BitSet32 operator& (const BitSet32& other) const {
|
|
|
|
return BitSet32(value & other.value);
|
|
|
|
}
|
|
|
|
inline BitSet32& operator&= (const BitSet32& other) {
|
|
|
|
value &= other.value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
inline BitSet32 operator| (const BitSet32& other) const {
|
|
|
|
return BitSet32(value | other.value);
|
|
|
|
}
|
|
|
|
inline BitSet32& operator|= (const BitSet32& other) {
|
|
|
|
value |= other.value;
|
|
|
|
return *this;
|
|
|
|
}
|
2014-04-12 01:23:11 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// We use these helpers as the signature of __builtin_c{l,t}z has "unsigned int" for the
|
|
|
|
// input, which is only guaranteed to be 16b, not 32. The compiler should optimize this away.
|
|
|
|
static inline uint32_t clz_checked(uint32_t value) {
|
|
|
|
if (sizeof(unsigned int) == sizeof(uint32_t)) {
|
2020-07-11 23:07:14 +00:00
|
|
|
return static_cast<uint32_t>(__builtin_clz(value));
|
2014-04-12 01:23:11 +00:00
|
|
|
} else {
|
2020-07-11 23:07:14 +00:00
|
|
|
return static_cast<uint32_t>(__builtin_clzl(value));
|
2014-04-12 01:23:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t ctz_checked(uint32_t value) {
|
|
|
|
if (sizeof(unsigned int) == sizeof(uint32_t)) {
|
2020-07-11 23:07:14 +00:00
|
|
|
return static_cast<uint32_t>(__builtin_ctz(value));
|
2014-04-12 01:23:11 +00:00
|
|
|
} else {
|
2020-07-11 23:07:14 +00:00
|
|
|
return static_cast<uint32_t>(__builtin_ctzl(value));
|
2014-04-12 01:23:11 +00:00
|
|
|
}
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 21:45:49 +00:00
|
|
|
ANDROID_BASIC_TYPES_TRAITS(BitSet32)
|
|
|
|
|
2014-03-19 00:25:20 +00:00
|
|
|
// A simple set of 64 bits that can be individually marked or cleared.
|
|
|
|
struct BitSet64 {
|
|
|
|
uint64_t value;
|
|
|
|
|
|
|
|
inline BitSet64() : value(0ULL) { }
|
|
|
|
explicit inline BitSet64(uint64_t value) : value(value) { }
|
|
|
|
|
|
|
|
// Gets the value associated with a particular bit index.
|
|
|
|
static inline uint64_t valueForBit(uint32_t n) { return 0x8000000000000000ULL >> n; }
|
|
|
|
|
|
|
|
// Clears the bit set.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline void clear() { clear(value); }
|
|
|
|
|
|
|
|
static inline void clear(uint64_t& value) { value = 0ULL; }
|
2014-03-19 00:25:20 +00:00
|
|
|
|
|
|
|
// Returns the number of marked bits in the set.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t count() const { return count(value); }
|
|
|
|
|
2020-07-11 23:07:14 +00:00
|
|
|
static inline uint32_t count(uint64_t value) {
|
|
|
|
return static_cast<uint32_t>(__builtin_popcountll(value));
|
|
|
|
}
|
2014-03-19 00:25:20 +00:00
|
|
|
|
|
|
|
// Returns true if the bit set does not contain any marked bits.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline bool isEmpty() const { return isEmpty(value); }
|
|
|
|
|
|
|
|
static inline bool isEmpty(uint64_t value) { return ! value; }
|
2014-03-19 00:25:20 +00:00
|
|
|
|
|
|
|
// Returns true if the bit set does not contain any unmarked bits.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline bool isFull() const { return isFull(value); }
|
|
|
|
|
|
|
|
static inline bool isFull(uint64_t value) { return value == 0xffffffffffffffffULL; }
|
2014-03-19 00:25:20 +00:00
|
|
|
|
|
|
|
// Returns true if the specified bit is marked.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline bool hasBit(uint32_t n) const { return hasBit(value, n); }
|
|
|
|
|
|
|
|
static inline bool hasBit(uint64_t value, uint32_t n) { return value & valueForBit(n); }
|
2014-03-19 00:25:20 +00:00
|
|
|
|
|
|
|
// Marks the specified bit.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline void markBit(uint32_t n) { markBit(value, n); }
|
|
|
|
|
|
|
|
static inline void markBit(uint64_t& value, uint32_t n) { value |= valueForBit(n); }
|
2014-03-19 00:25:20 +00:00
|
|
|
|
|
|
|
// Clears the specified bit.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline void clearBit(uint32_t n) { clearBit(value, n); }
|
|
|
|
|
|
|
|
static inline void clearBit(uint64_t& value, uint32_t n) { value &= ~ valueForBit(n); }
|
2014-03-19 00:25:20 +00:00
|
|
|
|
|
|
|
// Finds the first marked bit in the set.
|
|
|
|
// Result is undefined if all bits are unmarked.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t firstMarkedBit() const { return firstMarkedBit(value); }
|
|
|
|
|
2020-07-11 23:07:14 +00:00
|
|
|
static inline uint32_t firstMarkedBit(uint64_t value) {
|
|
|
|
return static_cast<uint32_t>(__builtin_clzll(value));
|
|
|
|
}
|
2014-03-19 00:25:20 +00:00
|
|
|
|
|
|
|
// Finds the first unmarked bit in the set.
|
|
|
|
// Result is undefined if all bits are marked.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t firstUnmarkedBit() const { return firstUnmarkedBit(value); }
|
|
|
|
|
2020-07-11 23:07:14 +00:00
|
|
|
static inline uint32_t firstUnmarkedBit(uint64_t value) {
|
|
|
|
return static_cast<uint32_t>(__builtin_clzll(~value));
|
|
|
|
}
|
2014-03-19 00:25:20 +00:00
|
|
|
|
|
|
|
// Finds the last marked bit in the set.
|
|
|
|
// Result is undefined if all bits are unmarked.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t lastMarkedBit() const { return lastMarkedBit(value); }
|
|
|
|
|
2020-07-11 23:07:14 +00:00
|
|
|
static inline uint32_t lastMarkedBit(uint64_t value) {
|
|
|
|
return static_cast<uint32_t>(63 - __builtin_ctzll(value));
|
|
|
|
}
|
2014-03-19 00:25:20 +00:00
|
|
|
|
|
|
|
// Finds the first marked bit in the set and clears it. Returns the bit index.
|
|
|
|
// Result is undefined if all bits are unmarked.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t clearFirstMarkedBit() { return clearFirstMarkedBit(value); }
|
|
|
|
|
|
|
|
static inline uint32_t clearFirstMarkedBit(uint64_t& value) {
|
2020-07-11 23:07:14 +00:00
|
|
|
uint32_t n = firstMarkedBit(value);
|
2014-03-19 18:23:01 +00:00
|
|
|
clearBit(value, n);
|
2014-03-19 00:25:20 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finds the first unmarked bit in the set and marks it. Returns the bit index.
|
|
|
|
// Result is undefined if all bits are marked.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t markFirstUnmarkedBit() { return markFirstUnmarkedBit(value); }
|
|
|
|
|
|
|
|
static inline uint32_t markFirstUnmarkedBit(uint64_t& value) {
|
2020-07-11 23:07:14 +00:00
|
|
|
uint32_t n = firstUnmarkedBit(value);
|
2014-03-19 18:23:01 +00:00
|
|
|
markBit(value, n);
|
2014-03-19 00:25:20 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finds the last marked bit in the set and clears it. Returns the bit index.
|
|
|
|
// Result is undefined if all bits are unmarked.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t clearLastMarkedBit() { return clearLastMarkedBit(value); }
|
|
|
|
|
|
|
|
static inline uint32_t clearLastMarkedBit(uint64_t& value) {
|
2020-07-11 23:07:14 +00:00
|
|
|
uint32_t n = lastMarkedBit(value);
|
2014-03-19 18:23:01 +00:00
|
|
|
clearBit(value, n);
|
2014-03-19 00:25:20 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gets the index of the specified bit in the set, which is the number of
|
|
|
|
// marked bits that appear before the specified bit.
|
2014-03-19 18:23:01 +00:00
|
|
|
inline uint32_t getIndexOfBit(uint32_t n) const { return getIndexOfBit(value, n); }
|
|
|
|
|
|
|
|
static inline uint32_t getIndexOfBit(uint64_t value, uint32_t n) {
|
2020-07-11 23:07:14 +00:00
|
|
|
return static_cast<uint32_t>(__builtin_popcountll(value & ~(0xffffffffffffffffULL >> n)));
|
2014-03-19 00:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator== (const BitSet64& other) const { return value == other.value; }
|
|
|
|
inline bool operator!= (const BitSet64& other) const { return value != other.value; }
|
|
|
|
inline BitSet64 operator& (const BitSet64& other) const {
|
|
|
|
return BitSet64(value & other.value);
|
|
|
|
}
|
|
|
|
inline BitSet64& operator&= (const BitSet64& other) {
|
|
|
|
value &= other.value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
inline BitSet64 operator| (const BitSet64& other) const {
|
|
|
|
return BitSet64(value | other.value);
|
|
|
|
}
|
|
|
|
inline BitSet64& operator|= (const BitSet64& other) {
|
|
|
|
value |= other.value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-19 00:45:37 +00:00
|
|
|
ANDROID_BASIC_TYPES_TRAITS(BitSet64)
|
2014-03-19 00:25:20 +00:00
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
} // namespace android
|
|
|
|
|
|
|
|
#endif // UTILS_BITSET_H
|