frameworks/native
Révision | 87d725793ec559e1f1ad67108a2c4806313e8a26 (tree) |
---|---|
l'heure | 2020-05-21 11:16:53 |
Auteur | Matt Moeller <matthew.moeller@kinz...> |
Commiter | Chih-Wei Huang |
ISurfaceComposer: Workaround for screenshots on intel graphics
Prevent the GraphicBuffer destructor until after the screencap client
has had a chance to consume it.
@@ -19,6 +19,7 @@ | ||
19 | 19 | |
20 | 20 | #include <stdint.h> |
21 | 21 | #include <sys/types.h> |
22 | +#include <thread> | |
22 | 23 | |
23 | 24 | #include <binder/Parcel.h> |
24 | 25 | #include <binder/IPCThreadState.h> |
@@ -631,6 +632,20 @@ status_t BnSurfaceComposer::onTransact( | ||
631 | 632 | reply->write(*outBuffer); |
632 | 633 | reply->writeBool(capturedSecureLayers); |
633 | 634 | } |
635 | + | |
636 | + // XXX | |
637 | + // When outBuffer goes out of scope, the destructor gets called and on some | |
638 | + // graphics platforms (intel i915) this will actually free the underlying buffer | |
639 | + // containing the screen capture. The guy on the other end of this binder transaction | |
640 | + // will try to open the buffer that has been freed and fail. | |
641 | + // | |
642 | + // The super-hacky workaround here is to delay the destructor call in a thread so | |
643 | + // the binder client can obtain the buffer in question. When the thread timeout expires | |
644 | + // the destructor will get called and clean up the buffer so there is no memory leak. | |
645 | + std::thread([outBuffer]() { | |
646 | + std::this_thread::sleep_for(std::chrono::seconds(1)); | |
647 | + }).detach(); | |
648 | + | |
634 | 649 | return NO_ERROR; |
635 | 650 | } |
636 | 651 | case CAPTURE_LAYERS: { |