Loading libs/binder/Parcel.cpp +39 −0 Original line number Original line Diff line number Diff line Loading @@ -599,17 +599,53 @@ bool Parcel::hasFileDescriptors() const return mHasFds; return mHasFds; } } void Parcel::updateWorkSourceRequestHeaderPosition() const { // Only update the request headers once. We only want to point // to the first headers read/written. if (!mRequestHeaderPresent) { mWorkSourceRequestHeaderPosition = dataPosition(); mRequestHeaderPresent = true; } } // Write RPC headers. (previously just the interface token) // Write RPC headers. (previously just the interface token) status_t Parcel::writeInterfaceToken(const String16& interface) status_t Parcel::writeInterfaceToken(const String16& interface) { { const IPCThreadState* threadState = IPCThreadState::self(); const IPCThreadState* threadState = IPCThreadState::self(); writeInt32(threadState->getStrictModePolicy() | STRICT_MODE_PENALTY_GATHER); writeInt32(threadState->getStrictModePolicy() | STRICT_MODE_PENALTY_GATHER); updateWorkSourceRequestHeaderPosition(); writeInt32(threadState->shouldPropagateWorkSource() ? writeInt32(threadState->shouldPropagateWorkSource() ? threadState->getCallingWorkSourceUid() : IPCThreadState::kUnsetWorkSource); threadState->getCallingWorkSourceUid() : IPCThreadState::kUnsetWorkSource); // currently the interface identification token is just its name as a string // currently the interface identification token is just its name as a string return writeString16(interface); return writeString16(interface); } } bool Parcel::replaceCallingWorkSourceUid(uid_t uid) { if (!mRequestHeaderPresent) { return false; } const size_t initialPosition = dataPosition(); setDataPosition(mWorkSourceRequestHeaderPosition); status_t err = writeInt32(uid); setDataPosition(initialPosition); return err == NO_ERROR; } uid_t Parcel::readCallingWorkSourceUid() { if (!mRequestHeaderPresent) { return IPCThreadState::kUnsetWorkSource; } const size_t initialPosition = dataPosition(); setDataPosition(mWorkSourceRequestHeaderPosition); uid_t uid = readInt32(); setDataPosition(initialPosition); return uid; } bool Parcel::checkInterface(IBinder* binder) const bool Parcel::checkInterface(IBinder* binder) const { { return enforceInterface(binder->getInterfaceDescriptor()); return enforceInterface(binder->getInterfaceDescriptor()); Loading @@ -634,6 +670,7 @@ bool Parcel::enforceInterface(const String16& interface, threadState->setStrictModePolicy(strictPolicy); threadState->setStrictModePolicy(strictPolicy); } } // WorkSource. // WorkSource. updateWorkSourceRequestHeaderPosition(); int32_t workSource = readInt32(); int32_t workSource = readInt32(); threadState->setCallingWorkSourceUidWithoutPropagation(workSource); threadState->setCallingWorkSourceUidWithoutPropagation(workSource); // Interface descriptor. // Interface descriptor. Loading Loading @@ -2889,6 +2926,8 @@ void Parcel::initState() mAllowFds = true; mAllowFds = true; mOwner = nullptr; mOwner = nullptr; mOpenAshmemSize = 0; mOpenAshmemSize = 0; mWorkSourceRequestHeaderPosition = 0; mRequestHeaderPresent = false; // racing multiple init leads only to multiple identical write // racing multiple init leads only to multiple identical write if (gMaxFds == 0) { if (gMaxFds == 0) { Loading libs/binder/include/binder/Parcel.h +10 −0 Original line number Original line Diff line number Diff line Loading @@ -395,6 +395,12 @@ public: static size_t getGlobalAllocSize(); static size_t getGlobalAllocSize(); static size_t getGlobalAllocCount(); static size_t getGlobalAllocCount(); bool replaceCallingWorkSourceUid(uid_t uid); // Returns the work source provided by the caller. This can only be trusted for trusted calling // uid. uid_t readCallingWorkSourceUid(); void readRequestHeaders() const; private: private: typedef void (*release_func)(Parcel* parcel, typedef void (*release_func)(Parcel* parcel, const uint8_t* data, size_t dataSize, const uint8_t* data, size_t dataSize, Loading Loading @@ -429,6 +435,7 @@ private: void initState(); void initState(); void scanForFds() const; void scanForFds() const; status_t validateReadData(size_t len) const; status_t validateReadData(size_t len) const; void updateWorkSourceRequestHeaderPosition() const; template<class T> template<class T> status_t readAligned(T *pArg) const; status_t readAligned(T *pArg) const; Loading Loading @@ -477,6 +484,9 @@ private: mutable size_t mNextObjectHint; mutable size_t mNextObjectHint; mutable bool mObjectsSorted; mutable bool mObjectsSorted; mutable bool mRequestHeaderPresent; mutable size_t mWorkSourceRequestHeaderPosition; mutable bool mFdsKnown; mutable bool mFdsKnown; mutable bool mHasFds; mutable bool mHasFds; bool mAllowFds; bool mAllowFds; Loading libs/gui/LayerState.cpp +9 −11 Original line number Original line Diff line number Diff line Loading @@ -98,8 +98,8 @@ status_t layer_state_t::write(Parcel& output) const output.writeInt32(cachedBuffer.bufferId); output.writeInt32(cachedBuffer.bufferId); output.writeParcelable(metadata); output.writeParcelable(metadata); output.writeFloat(colorAlpha); output.writeFloat(bgColorAlpha); output.writeUint32(static_cast<uint32_t>(colorDataspace)); output.writeUint32(static_cast<uint32_t>(bgColorDataspace)); return NO_ERROR; return NO_ERROR; } } Loading Loading @@ -175,8 +175,8 @@ status_t layer_state_t::read(const Parcel& input) cachedBuffer.bufferId = input.readInt32(); cachedBuffer.bufferId = input.readInt32(); input.readParcelable(&metadata); input.readParcelable(&metadata); colorAlpha = input.readFloat(); bgColorAlpha = input.readFloat(); colorDataspace = static_cast<ui::Dataspace>(input.readUint32()); bgColorDataspace = static_cast<ui::Dataspace>(input.readUint32()); return NO_ERROR; return NO_ERROR; } } Loading Loading @@ -390,13 +390,11 @@ void layer_state_t::merge(const layer_state_t& other) { what |= eCachedBufferChanged; what |= eCachedBufferChanged; cachedBuffer = other.cachedBuffer; cachedBuffer = other.cachedBuffer; } } if (other.what & eColorAlphaChanged) { if (other.what & eBackgroundColorChanged) { what |= eColorAlphaChanged; what |= eBackgroundColorChanged; colorAlpha = other.colorAlpha; color = other.color; } bgColorAlpha = other.bgColorAlpha; if (other.what & eColorDataspaceChanged) { bgColorDataspace = other.bgColorDataspace; what |= eColorDataspaceChanged; colorDataspace = other.colorDataspace; } } if (other.what & eMetadataChanged) { if (other.what & eMetadataChanged) { what |= eMetadataChanged; what |= eMetadataChanged; Loading libs/gui/SurfaceComposerClient.cpp +6 −19 Original line number Original line Diff line number Diff line Loading @@ -678,31 +678,18 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColor return *this; return *this; } } SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorAlpha( SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBackgroundColor( const sp<SurfaceControl>& sc, float alpha) { const sp<SurfaceControl>& sc, const half3& color, float alpha, ui::Dataspace dataspace) { layer_state_t* s = getLayerState(sc); if (!s) { mStatus = BAD_INDEX; return *this; } s->what |= layer_state_t::eColorAlphaChanged; s->colorAlpha = alpha; registerSurfaceControlForCallback(sc); return *this; } SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorDataspace( const sp<SurfaceControl>& sc, ui::Dataspace dataspace) { layer_state_t* s = getLayerState(sc); layer_state_t* s = getLayerState(sc); if (!s) { if (!s) { mStatus = BAD_INDEX; mStatus = BAD_INDEX; return *this; return *this; } } s->what |= layer_state_t::eColorDataspaceChanged; s->what |= layer_state_t::eBackgroundColorChanged; s->colorDataspace = dataspace; s->color = color; s->bgColorAlpha = alpha; s->bgColorDataspace = dataspace; registerSurfaceControlForCallback(sc); registerSurfaceControlForCallback(sc); return *this; return *this; Loading libs/gui/include/gui/LayerState.h +9 −8 Original line number Original line Diff line number Diff line Loading @@ -86,9 +86,8 @@ struct layer_state_t { eCornerRadiusChanged = 0x80000000, eCornerRadiusChanged = 0x80000000, eFrameChanged = 0x1'00000000, eFrameChanged = 0x1'00000000, eCachedBufferChanged = 0x2'00000000, eCachedBufferChanged = 0x2'00000000, eColorAlphaChanged = 0x4'00000000, eBackgroundColorChanged = 0x4'00000000, eColorDataspaceChanged = 0x8'00000000, eMetadataChanged = 0x8'00000000, eMetadataChanged = 0x10'00000000, }; }; layer_state_t() layer_state_t() Loading @@ -115,8 +114,8 @@ struct layer_state_t { surfaceDamageRegion(), surfaceDamageRegion(), api(-1), api(-1), colorTransform(mat4()), colorTransform(mat4()), colorAlpha(0), bgColorAlpha(0), colorDataspace(ui::Dataspace::UNKNOWN) { bgColorDataspace(ui::Dataspace::UNKNOWN) { matrix.dsdx = matrix.dtdy = 1.0f; matrix.dsdx = matrix.dtdy = 1.0f; matrix.dsdy = matrix.dtdx = 0.0f; matrix.dsdy = matrix.dtdx = 0.0f; hdrMetadata.validTypes = 0; hdrMetadata.validTypes = 0; Loading Loading @@ -187,10 +186,12 @@ struct layer_state_t { cached_buffer_t cachedBuffer; cached_buffer_t cachedBuffer; float colorAlpha; ui::Dataspace colorDataspace; LayerMetadata metadata; LayerMetadata metadata; // The following refer to the alpha, and dataspace, respectively of // the background color layer float bgColorAlpha; ui::Dataspace bgColorDataspace; }; }; struct ComposerState { struct ComposerState { Loading Loading
libs/binder/Parcel.cpp +39 −0 Original line number Original line Diff line number Diff line Loading @@ -599,17 +599,53 @@ bool Parcel::hasFileDescriptors() const return mHasFds; return mHasFds; } } void Parcel::updateWorkSourceRequestHeaderPosition() const { // Only update the request headers once. We only want to point // to the first headers read/written. if (!mRequestHeaderPresent) { mWorkSourceRequestHeaderPosition = dataPosition(); mRequestHeaderPresent = true; } } // Write RPC headers. (previously just the interface token) // Write RPC headers. (previously just the interface token) status_t Parcel::writeInterfaceToken(const String16& interface) status_t Parcel::writeInterfaceToken(const String16& interface) { { const IPCThreadState* threadState = IPCThreadState::self(); const IPCThreadState* threadState = IPCThreadState::self(); writeInt32(threadState->getStrictModePolicy() | STRICT_MODE_PENALTY_GATHER); writeInt32(threadState->getStrictModePolicy() | STRICT_MODE_PENALTY_GATHER); updateWorkSourceRequestHeaderPosition(); writeInt32(threadState->shouldPropagateWorkSource() ? writeInt32(threadState->shouldPropagateWorkSource() ? threadState->getCallingWorkSourceUid() : IPCThreadState::kUnsetWorkSource); threadState->getCallingWorkSourceUid() : IPCThreadState::kUnsetWorkSource); // currently the interface identification token is just its name as a string // currently the interface identification token is just its name as a string return writeString16(interface); return writeString16(interface); } } bool Parcel::replaceCallingWorkSourceUid(uid_t uid) { if (!mRequestHeaderPresent) { return false; } const size_t initialPosition = dataPosition(); setDataPosition(mWorkSourceRequestHeaderPosition); status_t err = writeInt32(uid); setDataPosition(initialPosition); return err == NO_ERROR; } uid_t Parcel::readCallingWorkSourceUid() { if (!mRequestHeaderPresent) { return IPCThreadState::kUnsetWorkSource; } const size_t initialPosition = dataPosition(); setDataPosition(mWorkSourceRequestHeaderPosition); uid_t uid = readInt32(); setDataPosition(initialPosition); return uid; } bool Parcel::checkInterface(IBinder* binder) const bool Parcel::checkInterface(IBinder* binder) const { { return enforceInterface(binder->getInterfaceDescriptor()); return enforceInterface(binder->getInterfaceDescriptor()); Loading @@ -634,6 +670,7 @@ bool Parcel::enforceInterface(const String16& interface, threadState->setStrictModePolicy(strictPolicy); threadState->setStrictModePolicy(strictPolicy); } } // WorkSource. // WorkSource. updateWorkSourceRequestHeaderPosition(); int32_t workSource = readInt32(); int32_t workSource = readInt32(); threadState->setCallingWorkSourceUidWithoutPropagation(workSource); threadState->setCallingWorkSourceUidWithoutPropagation(workSource); // Interface descriptor. // Interface descriptor. Loading Loading @@ -2889,6 +2926,8 @@ void Parcel::initState() mAllowFds = true; mAllowFds = true; mOwner = nullptr; mOwner = nullptr; mOpenAshmemSize = 0; mOpenAshmemSize = 0; mWorkSourceRequestHeaderPosition = 0; mRequestHeaderPresent = false; // racing multiple init leads only to multiple identical write // racing multiple init leads only to multiple identical write if (gMaxFds == 0) { if (gMaxFds == 0) { Loading
libs/binder/include/binder/Parcel.h +10 −0 Original line number Original line Diff line number Diff line Loading @@ -395,6 +395,12 @@ public: static size_t getGlobalAllocSize(); static size_t getGlobalAllocSize(); static size_t getGlobalAllocCount(); static size_t getGlobalAllocCount(); bool replaceCallingWorkSourceUid(uid_t uid); // Returns the work source provided by the caller. This can only be trusted for trusted calling // uid. uid_t readCallingWorkSourceUid(); void readRequestHeaders() const; private: private: typedef void (*release_func)(Parcel* parcel, typedef void (*release_func)(Parcel* parcel, const uint8_t* data, size_t dataSize, const uint8_t* data, size_t dataSize, Loading Loading @@ -429,6 +435,7 @@ private: void initState(); void initState(); void scanForFds() const; void scanForFds() const; status_t validateReadData(size_t len) const; status_t validateReadData(size_t len) const; void updateWorkSourceRequestHeaderPosition() const; template<class T> template<class T> status_t readAligned(T *pArg) const; status_t readAligned(T *pArg) const; Loading Loading @@ -477,6 +484,9 @@ private: mutable size_t mNextObjectHint; mutable size_t mNextObjectHint; mutable bool mObjectsSorted; mutable bool mObjectsSorted; mutable bool mRequestHeaderPresent; mutable size_t mWorkSourceRequestHeaderPosition; mutable bool mFdsKnown; mutable bool mFdsKnown; mutable bool mHasFds; mutable bool mHasFds; bool mAllowFds; bool mAllowFds; Loading
libs/gui/LayerState.cpp +9 −11 Original line number Original line Diff line number Diff line Loading @@ -98,8 +98,8 @@ status_t layer_state_t::write(Parcel& output) const output.writeInt32(cachedBuffer.bufferId); output.writeInt32(cachedBuffer.bufferId); output.writeParcelable(metadata); output.writeParcelable(metadata); output.writeFloat(colorAlpha); output.writeFloat(bgColorAlpha); output.writeUint32(static_cast<uint32_t>(colorDataspace)); output.writeUint32(static_cast<uint32_t>(bgColorDataspace)); return NO_ERROR; return NO_ERROR; } } Loading Loading @@ -175,8 +175,8 @@ status_t layer_state_t::read(const Parcel& input) cachedBuffer.bufferId = input.readInt32(); cachedBuffer.bufferId = input.readInt32(); input.readParcelable(&metadata); input.readParcelable(&metadata); colorAlpha = input.readFloat(); bgColorAlpha = input.readFloat(); colorDataspace = static_cast<ui::Dataspace>(input.readUint32()); bgColorDataspace = static_cast<ui::Dataspace>(input.readUint32()); return NO_ERROR; return NO_ERROR; } } Loading Loading @@ -390,13 +390,11 @@ void layer_state_t::merge(const layer_state_t& other) { what |= eCachedBufferChanged; what |= eCachedBufferChanged; cachedBuffer = other.cachedBuffer; cachedBuffer = other.cachedBuffer; } } if (other.what & eColorAlphaChanged) { if (other.what & eBackgroundColorChanged) { what |= eColorAlphaChanged; what |= eBackgroundColorChanged; colorAlpha = other.colorAlpha; color = other.color; } bgColorAlpha = other.bgColorAlpha; if (other.what & eColorDataspaceChanged) { bgColorDataspace = other.bgColorDataspace; what |= eColorDataspaceChanged; colorDataspace = other.colorDataspace; } } if (other.what & eMetadataChanged) { if (other.what & eMetadataChanged) { what |= eMetadataChanged; what |= eMetadataChanged; Loading
libs/gui/SurfaceComposerClient.cpp +6 −19 Original line number Original line Diff line number Diff line Loading @@ -678,31 +678,18 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColor return *this; return *this; } } SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorAlpha( SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBackgroundColor( const sp<SurfaceControl>& sc, float alpha) { const sp<SurfaceControl>& sc, const half3& color, float alpha, ui::Dataspace dataspace) { layer_state_t* s = getLayerState(sc); if (!s) { mStatus = BAD_INDEX; return *this; } s->what |= layer_state_t::eColorAlphaChanged; s->colorAlpha = alpha; registerSurfaceControlForCallback(sc); return *this; } SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorDataspace( const sp<SurfaceControl>& sc, ui::Dataspace dataspace) { layer_state_t* s = getLayerState(sc); layer_state_t* s = getLayerState(sc); if (!s) { if (!s) { mStatus = BAD_INDEX; mStatus = BAD_INDEX; return *this; return *this; } } s->what |= layer_state_t::eColorDataspaceChanged; s->what |= layer_state_t::eBackgroundColorChanged; s->colorDataspace = dataspace; s->color = color; s->bgColorAlpha = alpha; s->bgColorDataspace = dataspace; registerSurfaceControlForCallback(sc); registerSurfaceControlForCallback(sc); return *this; return *this; Loading
libs/gui/include/gui/LayerState.h +9 −8 Original line number Original line Diff line number Diff line Loading @@ -86,9 +86,8 @@ struct layer_state_t { eCornerRadiusChanged = 0x80000000, eCornerRadiusChanged = 0x80000000, eFrameChanged = 0x1'00000000, eFrameChanged = 0x1'00000000, eCachedBufferChanged = 0x2'00000000, eCachedBufferChanged = 0x2'00000000, eColorAlphaChanged = 0x4'00000000, eBackgroundColorChanged = 0x4'00000000, eColorDataspaceChanged = 0x8'00000000, eMetadataChanged = 0x8'00000000, eMetadataChanged = 0x10'00000000, }; }; layer_state_t() layer_state_t() Loading @@ -115,8 +114,8 @@ struct layer_state_t { surfaceDamageRegion(), surfaceDamageRegion(), api(-1), api(-1), colorTransform(mat4()), colorTransform(mat4()), colorAlpha(0), bgColorAlpha(0), colorDataspace(ui::Dataspace::UNKNOWN) { bgColorDataspace(ui::Dataspace::UNKNOWN) { matrix.dsdx = matrix.dtdy = 1.0f; matrix.dsdx = matrix.dtdy = 1.0f; matrix.dsdy = matrix.dtdx = 0.0f; matrix.dsdy = matrix.dtdx = 0.0f; hdrMetadata.validTypes = 0; hdrMetadata.validTypes = 0; Loading Loading @@ -187,10 +186,12 @@ struct layer_state_t { cached_buffer_t cachedBuffer; cached_buffer_t cachedBuffer; float colorAlpha; ui::Dataspace colorDataspace; LayerMetadata metadata; LayerMetadata metadata; // The following refer to the alpha, and dataspace, respectively of // the background color layer float bgColorAlpha; ui::Dataspace bgColorDataspace; }; }; struct ComposerState { struct ComposerState { Loading