Guest User

Untitled

a guest
Nov 26th, 2017
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.00 KB | None | 0 0
  1. From e5b0c51fb87e3cf0b47ebf80d51382f756d462dc Mon Sep 17 00:00:00 2001
  2. From: Ricardo Cerqueira <cyanogenmod@cerqueira.org>
  3. Date: Tue, 6 Aug 2013 16:11:06 +0100
  4. Subject: [PATCH 1/8] libgui: Bring back support for mHeap-based screenshots
  5.  
  6. Older graphics libraries throw a hissy fit when trying to lock
  7. buffers for Surface-based screenshots, on at least Tegra2/3 and
  8. Exynos4 hardware.
  9.  
  10. This patch depends on the BOARD_USE_MHEAP_SCREENSHOT board flag
  11. and requires the ro.bq.gpu_to_cpu_unsupported property set to 1
  12. in order to work.
  13.  
  14. [pawitp: port to Lollipop]
  15.  
  16. Change-Id: I7db955e2cdd120018e349c14290e975788e70ed3
  17. ---
  18. include/gui/ISurfaceComposer.h | 15 +++
  19. include/gui/SurfaceComposerClient.h | 6 +
  20. libs/gui/Android.mk | 4 +
  21. libs/gui/ISurfaceComposer.cpp | 53 ++++++++
  22. libs/gui/SurfaceComposerClient.cpp | 27 ++++
  23. services/surfaceflinger/Android.mk | 4 +
  24. services/surfaceflinger/SurfaceFlinger.h | 16 +++
  25. services/surfaceflinger/SurfaceFlinger_hwc1.cpp | 161 +++++++++++++++++++++++-
  26. 8 files changed, 282 insertions(+), 4 deletions(-)
  27.  
  28. diff --git a/include/gui/ISurfaceComposer.h b/include/gui/ISurfaceComposer.h
  29. index 90c4dc3..725575a 100644
  30. --- a/include/gui/ISurfaceComposer.h
  31. +++ b/include/gui/ISurfaceComposer.h
  32. @@ -157,6 +157,18 @@ public:
  33. Rotation rotation = eRotateNone,
  34. bool isCpuConsumer = false) = 0;
  35.  
  36. +#ifdef USE_MHEAP_SCREENSHOT
  37. + /* Capture the specified screen. requires READ_FRAME_BUFFER permission
  38. + * This function will fail if there is a secure window on screen.
  39. + */
  40. + virtual status_t captureScreen(const sp<IBinder>& display, sp<IMemoryHeap>* heap,
  41. + uint32_t* width, uint32_t* height,
  42. + Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  43. + uint32_t minLayerZ, uint32_t maxLayerZ,
  44. + bool useIdentityTransform,
  45. + Rotation rotation = eRotateNone) = 0;
  46. +#endif
  47. +
  48. /* Clears the frame statistics for animations.
  49. *
  50. * Requires the ACCESS_SURFACE_FLINGER permission.
  51. @@ -193,6 +205,9 @@ public:
  52. GET_BUILT_IN_DISPLAY,
  53. SET_TRANSACTION_STATE,
  54. AUTHENTICATE_SURFACE,
  55. +#ifdef USE_MHEAP_SCREENSHOT
  56. + CAPTURE_SCREEN_DEPRECATED,
  57. +#endif
  58. GET_DISPLAY_CONFIGS,
  59. GET_ACTIVE_CONFIG,
  60. SET_ACTIVE_CONFIG,
  61. diff --git a/include/gui/SurfaceComposerClient.h b/include/gui/SurfaceComposerClient.h
  62. index bcf4880..2f4922c 100644
  63. --- a/include/gui/SurfaceComposerClient.h
  64. +++ b/include/gui/SurfaceComposerClient.h
  65. @@ -41,6 +41,9 @@ namespace android {
  66. class DisplayInfo;
  67. class Composer;
  68. class HdrCapabilities;
  69. +#ifdef USE_MHEAP_SCREENSHOT
  70. +class IMemoryHeap;
  71. +#endif
  72. class ISurfaceComposerClient;
  73. class IGraphicBufferProducer;
  74. class Region;
  75. @@ -218,6 +221,9 @@ public:
  76. bool useIdentityTransform);
  77.  
  78. private:
  79. +#ifdef USE_MHEAP_SCREENSHOT
  80. + sp<IMemoryHeap> mHeap;
  81. +#endif
  82. mutable sp<CpuConsumer> mCpuConsumer;
  83. mutable sp<IGraphicBufferProducer> mProducer;
  84. CpuConsumer::LockedBuffer mBuffer;
  85. diff --git a/libs/gui/Android.mk b/libs/gui/Android.mk
  86. index 0889aaf..d1b415e 100644
  87. --- a/libs/gui/Android.mk
  88. +++ b/libs/gui/Android.mk
  89. @@ -87,6 +87,10 @@ LOCAL_SHARED_LIBRARIES := \
  90. liblog
  91.  
  92.  
  93. +ifeq ($(BOARD_USE_MHEAP_SCREENSHOT),true)
  94. + LOCAL_CFLAGS += -DUSE_MHEAP_SCREENSHOT
  95. +endif
  96. +
  97. LOCAL_MODULE := libgui
  98.  
  99. ifeq ($(TARGET_BOARD_PLATFORM), tegra)
  100. diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp
  101. index 2e101b3..5c5caa5 100644
  102. --- a/libs/gui/ISurfaceComposer.cpp
  103. +++ b/libs/gui/ISurfaceComposer.cpp
  104. @@ -101,6 +101,33 @@ public:
  105. remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
  106. }
  107.  
  108. +#ifdef USE_MHEAP_SCREENSHOT
  109. + virtual status_t captureScreen(
  110. + const sp<IBinder>& display, sp<IMemoryHeap>* heap,
  111. + uint32_t* width, uint32_t* height,
  112. + Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  113. + uint32_t minLayerZ, uint32_t maxLayerZ,
  114. + bool useIdentityTransform,
  115. + ISurfaceComposer::Rotation rotation)
  116. + {
  117. + Parcel data, reply;
  118. + data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
  119. + data.writeStrongBinder(display);
  120. + data.write(sourceCrop);
  121. + data.writeUint32(reqWidth);
  122. + data.writeUint32(reqHeight);
  123. + data.writeUint32(minLayerZ);
  124. + data.writeUint32(maxLayerZ);
  125. + data.writeInt32(static_cast<int32_t>(useIdentityTransform));
  126. + data.writeInt32(static_cast<int32_t>(rotation));
  127. + remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN_DEPRECATED, data, &reply);
  128. + *heap = interface_cast<IMemoryHeap>(reply.readStrongBinder());
  129. + *width = reply.readUint32();
  130. + *height = reply.readUint32();
  131. + return reply.readInt32();
  132. + }
  133. +#endif
  134. +
  135. virtual status_t captureScreen(const sp<IBinder>& display,
  136. const sp<IGraphicBufferProducer>& producer,
  137. Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  138. @@ -451,6 +478,32 @@ status_t BnSurfaceComposer::onTransact(
  139. bootFinished();
  140. return NO_ERROR;
  141. }
  142. +#ifdef USE_MHEAP_SCREENSHOT
  143. + case CAPTURE_SCREEN_DEPRECATED: {
  144. + CHECK_INTERFACE(ISurfaceComposer, data, reply);
  145. + sp<IBinder> display = data.readStrongBinder();
  146. + Rect sourceCrop(Rect::EMPTY_RECT);
  147. + data.read(sourceCrop);
  148. + uint32_t reqWidth = data.readUint32();
  149. + uint32_t reqHeight = data.readUint32();
  150. + uint32_t minLayerZ = data.readUint32();
  151. + uint32_t maxLayerZ = data.readUint32();
  152. + bool useIdentityTransform = static_cast<bool>(data.readInt32());
  153. + uint32_t rotation = data.readUint32();
  154. + sp<IMemoryHeap> heap;
  155. + uint32_t w, h;
  156. +
  157. + status_t res = captureScreen(display, &heap, &w, &h,
  158. + sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
  159. + useIdentityTransform,
  160. + static_cast<ISurfaceComposer::Rotation>(rotation));
  161. + reply->writeStrongBinder(IInterface::asBinder(heap));
  162. + reply->writeUint32(w);
  163. + reply->writeUint32(h);
  164. + reply->writeInt32(res);
  165. + return NO_ERROR;
  166. + }
  167. +#endif
  168. case CAPTURE_SCREEN: {
  169. CHECK_INTERFACE(ISurfaceComposer, data, reply);
  170. sp<IBinder> display = data.readStrongBinder();
  171. diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
  172. index a4bf2de..f5218f5 100644
  173. --- a/libs/gui/SurfaceComposerClient.cpp
  174. +++ b/libs/gui/SurfaceComposerClient.cpp
  175. @@ -922,6 +922,14 @@ status_t ScreenshotClient::capture(
  176. uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) {
  177. sp<ISurfaceComposer> s(ComposerService::getComposerService());
  178. if (s == NULL) return NO_INIT;
  179. +#ifdef USE_MHEAP_SCREENSHOT
  180. + int format = 0;
  181. + producer->query(NATIVE_WINDOW_FORMAT,&format);
  182. + if (format == PIXEL_FORMAT_RGBA_8888) {
  183. + /* For some reason, this format fails badly */
  184. + return BAD_VALUE;
  185. + }
  186. +#endif
  187. return s->captureScreen(display, producer, sourceCrop,
  188. reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
  189. ISurfaceComposer::eRotateNone, SS_CPU_CONSUMER);
  190. @@ -952,6 +960,20 @@ status_t ScreenshotClient::update(const sp<IBinder>& display,
  191. bool useIdentityTransform, uint32_t rotation) {
  192. sp<ISurfaceComposer> s(ComposerService::getComposerService());
  193. if (s == NULL) return NO_INIT;
  194. +#ifdef USE_MHEAP_SCREENSHOT
  195. + int ret = -1;
  196. + mHeap = 0;
  197. + ret = s->captureScreen(display, &mHeap, &mBuffer.width, &mBuffer.height, sourceCrop,
  198. + reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
  199. + static_cast<ISurfaceComposer::Rotation>(rotation));
  200. +
  201. + if (ret == NO_ERROR) {
  202. + mBuffer.format = PIXEL_FORMAT_RGBA_8888;
  203. + mBuffer.stride = mBuffer.width;
  204. + mBuffer.data = static_cast<uint8_t*>(mHeap->getBase());
  205. + }
  206. + return ret;
  207. +#else
  208. sp<CpuConsumer> cpuConsumer = getCpuConsumer();
  209.  
  210. if (mHaveBuffer) {
  211. @@ -971,6 +993,7 @@ status_t ScreenshotClient::update(const sp<IBinder>& display,
  212. }
  213. }
  214. return err;
  215. +#endif
  216. }
  217.  
  218. status_t ScreenshotClient::update(const sp<IBinder>& display,
  219. @@ -995,12 +1018,16 @@ status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
  220. }
  221.  
  222. void ScreenshotClient::release() {
  223. +#ifdef USE_MHEAP_SCREENSHOT
  224. + mHeap = 0;
  225. +#else
  226. if (mHaveBuffer) {
  227. mCpuConsumer->unlockBuffer(mBuffer);
  228. memset(&mBuffer, 0, sizeof(mBuffer));
  229. mHaveBuffer = false;
  230. }
  231. mCpuConsumer.clear();
  232. +#endif
  233. }
  234.  
  235. void const* ScreenshotClient::getPixels() const {
  236. diff --git a/services/surfaceflinger/Android.mk b/services/surfaceflinger/Android.mk
  237. index 18cc946..2df45c3 100644
  238. --- a/services/surfaceflinger/Android.mk
  239. +++ b/services/surfaceflinger/Android.mk
  240. @@ -90,6 +90,10 @@ ifeq ($(TARGET_HAS_HH_VSYNC_ISSUE),true)
  241. LOCAL_CFLAGS += -DHH_VSYNC_ISSUE
  242. endif
  243.  
  244. +ifeq ($(BOARD_USE_MHEAP_SCREENSHOT),true)
  245. + LOCAL_CFLAGS += -DUSE_MHEAP_SCREENSHOT
  246. +endif
  247. +
  248. # The following two BoardConfig variables define (respectively):
  249. #
  250. # - The phase offset between hardware vsync and when apps are woken up by the
  251. diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
  252. index 900383d..01475e1 100644
  253. --- a/services/surfaceflinger/SurfaceFlinger.h
  254. +++ b/services/surfaceflinger/SurfaceFlinger.h
  255. @@ -229,6 +229,13 @@ private:
  256. uint32_t minLayerZ, uint32_t maxLayerZ,
  257. bool useIdentityTransform, ISurfaceComposer::Rotation rotation,
  258. bool isCpuConsumer);
  259. +#ifdef USE_MHEAP_SCREENSHOT
  260. + virtual status_t captureScreen(const sp<IBinder>& display, sp<IMemoryHeap>* heap,
  261. + uint32_t* width, uint32_t* height,
  262. + Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  263. + uint32_t minLayerZ, uint32_t maxLayerZ,
  264. + bool useIdentityTransform, ISurfaceComposer::Rotation rotation);
  265. +#endif
  266. virtual status_t getDisplayStats(const sp<IBinder>& display,
  267. DisplayStatInfo* stats);
  268. virtual status_t getDisplayConfigs(const sp<IBinder>& display,
  269. @@ -407,6 +414,15 @@ private:
  270. bool useIdentityTransform, Transform::orientation_flags rotation,
  271. bool isLocalScreenshot, bool useReadPixels);
  272.  
  273. +#ifdef USE_MHEAP_SCREENSHOT
  274. + status_t captureScreenImplCpuConsumerLocked(
  275. + const sp<const DisplayDevice>& hw,
  276. + sp<IMemoryHeap>* heap, uint32_t* width, uint32_t* height,
  277. + Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  278. + uint32_t minLayerZ, uint32_t maxLayerZ,
  279. + bool useIdentityTransform, Transform::orientation_flags rotation);
  280. +#endif
  281. +
  282. /* ------------------------------------------------------------------------
  283. * EGL
  284. */
  285. diff --git a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
  286. index e0b2d55..9deb50b 100644
  287. --- a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
  288. +++ b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
  289. @@ -29,6 +29,9 @@
  290. #include <stdatomic.h>
  291.  
  292. #include <EGL/egl.h>
  293. +#ifdef USE_MHEAP_SCREENSHOT
  294. +#include <GLES/gl.h>
  295. +#endif
  296.  
  297. #include <cutils/iosched_policy.h>
  298. #include <cutils/log.h>
  299. @@ -3236,12 +3239,18 @@ status_t SurfaceFlinger::onTransact(
  300. break;
  301. }
  302. case CAPTURE_SCREEN:
  303. +#ifdef USE_MHEAP_SCREENSHOT
  304. + case CAPTURE_SCREEN_DEPRECATED:
  305. +#endif
  306. {
  307. // codes that require permission check
  308. IPCThreadState* ipc = IPCThreadState::self();
  309. const int pid = ipc->getCallingPid();
  310. const int uid = ipc->getCallingUid();
  311. if ((uid != AID_GRAPHICS) &&
  312. +#ifdef USE_MHEAP_SCREENSHOT
  313. + (uid != AID_SYSTEM) &&
  314. +#endif
  315. !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) {
  316. ALOGE("Permission Denial: "
  317. "can't read framebuffer pid=%d, uid=%d", pid, uid);
  318. @@ -3610,10 +3619,19 @@ status_t SurfaceFlinger::captureScreen(const sp<IBinder>& display,
  319. Mutex::Autolock _l(flinger->mStateLock);
  320. sp<const DisplayDevice> hw(flinger->getDisplayDevice(display));
  321. bool useReadPixels = this->useReadPixels && !flinger->mGpuToCpuSupported;
  322. - result = flinger->captureScreenImplLocked(hw, producer,
  323. - sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
  324. - useIdentityTransform, rotation, isLocalScreenshot,
  325. - useReadPixels);
  326. +#ifdef USE_MHEAP_SCREENSHOT
  327. + if (!useReadPixels) {
  328. +#endif
  329. + result = flinger->captureScreenImplLocked(hw, producer,
  330. + sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
  331. + useIdentityTransform, rotation, isLocalScreenshot,
  332. + useReadPixels);
  333. +#ifdef USE_MHEAP_SCREENSHOT
  334. + } else {
  335. + // Should never get here
  336. + return BAD_VALUE;
  337. + }
  338. +#endif
  339. static_cast<GraphicProducerWrapper*>(IInterface::asBinder(producer).get())->exit(result);
  340. return true;
  341. }
  342. @@ -3955,6 +3973,139 @@ void SurfaceFlinger::drawWormHoleIfRequired(HWComposer::LayerListIterator& /*cur
  343. drawWormhole(hw, region);
  344. }
  345.  
  346. +#ifdef USE_MHEAP_SCREENSHOT
  347. +status_t SurfaceFlinger::captureScreenImplCpuConsumerLocked(
  348. + const sp<const DisplayDevice>& hw,
  349. + sp<IMemoryHeap>* heap, uint32_t* w, uint32_t* h,
  350. + Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  351. + uint32_t minLayerZ, uint32_t maxLayerZ,
  352. + bool useIdentityTransform, Transform::orientation_flags rotation)
  353. +{
  354. + ATRACE_CALL();
  355. +
  356. + // get screen geometry
  357. + uint32_t hw_w = hw->getWidth();
  358. + uint32_t hw_h = hw->getHeight();
  359. +
  360. + if ((reqWidth > hw_w) || (reqHeight > hw_h)) {
  361. + ALOGE("size mismatch (%d, %d) > (%d, %d)",
  362. + reqWidth, reqHeight, hw_w, hw_h);
  363. + return BAD_VALUE;
  364. + }
  365. +
  366. + reqWidth = (!reqWidth) ? hw_w : reqWidth;
  367. + reqHeight = (!reqHeight) ? hw_h : reqHeight;
  368. +
  369. + status_t result = NO_ERROR;
  370. +
  371. + renderScreenImplLocked(
  372. + hw, sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ, true,
  373. + useIdentityTransform, rotation);
  374. +
  375. + size_t size = reqWidth * reqHeight * 4;
  376. + // allocate shared memory large enough to hold the
  377. + // screen capture
  378. + sp<MemoryHeapBase> base(
  379. + new MemoryHeapBase(size, 0, "screen-capture") );
  380. + void *vaddr = base->getBase();
  381. + glReadPixels(0, 0, reqWidth, reqHeight,
  382. + GL_RGBA, GL_UNSIGNED_BYTE, vaddr);
  383. + if (glGetError() == GL_NO_ERROR) {
  384. + *heap = base;
  385. + *w = reqWidth;
  386. + *h = reqHeight;
  387. + result = NO_ERROR;
  388. + } else {
  389. + result = INVALID_OPERATION;
  390. + }
  391. +
  392. + return result;
  393. +}
  394. +
  395. +status_t SurfaceFlinger::captureScreen(const sp<IBinder>& display,
  396. + sp<IMemoryHeap>* heap, uint32_t* outWidth, uint32_t* outHeight,
  397. + Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  398. + uint32_t minLayerZ, uint32_t maxLayerZ,
  399. + bool useIdentityTransform, ISurfaceComposer::Rotation rotation)
  400. +{
  401. + if (CC_UNLIKELY(display == 0))
  402. + return BAD_VALUE;
  403. +
  404. + // Convert to surfaceflinger's internal rotation type.
  405. + Transform::orientation_flags rotationFlags;
  406. + switch (rotation) {
  407. + case ISurfaceComposer::eRotateNone:
  408. + rotationFlags = Transform::ROT_0;
  409. + break;
  410. + case ISurfaceComposer::eRotate90:
  411. + rotationFlags = Transform::ROT_90;
  412. + break;
  413. + case ISurfaceComposer::eRotate180:
  414. + rotationFlags = Transform::ROT_180;
  415. + break;
  416. + case ISurfaceComposer::eRotate270:
  417. + rotationFlags = Transform::ROT_270;
  418. + break;
  419. + default:
  420. + rotationFlags = Transform::ROT_0;
  421. + ALOGE("Invalid rotation passed to captureScreen(): %d\n", rotation);
  422. + break;
  423. + }
  424. +
  425. + class MessageCaptureScreen : public MessageBase {
  426. + SurfaceFlinger* flinger;
  427. + sp<IBinder> display;
  428. + sp<IMemoryHeap>* heap;
  429. + uint32_t* outWidth;
  430. + uint32_t* outHeight;
  431. + Rect sourceCrop;
  432. + uint32_t reqWidth, reqHeight;
  433. + uint32_t minLayerZ,maxLayerZ;
  434. + bool useIdentityTransform;
  435. + Transform::orientation_flags rotation;
  436. + status_t result;
  437. + public:
  438. + MessageCaptureScreen(SurfaceFlinger* flinger,
  439. + const sp<IBinder>& display, sp<IMemoryHeap>* heap,
  440. + uint32_t* outWidth, uint32_t* outHeight,
  441. + Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  442. + uint32_t minLayerZ, uint32_t maxLayerZ,
  443. + bool useIdentityTransform, Transform::orientation_flags rotation)
  444. + : flinger(flinger), display(display), heap(heap),
  445. + outWidth(outWidth), outHeight(outHeight),
  446. + sourceCrop(sourceCrop), reqWidth(reqWidth), reqHeight(reqHeight),
  447. + minLayerZ(minLayerZ), maxLayerZ(maxLayerZ),
  448. + useIdentityTransform(useIdentityTransform),
  449. + rotation(rotation),
  450. + result(PERMISSION_DENIED)
  451. + {
  452. + }
  453. + status_t getResult() const {
  454. + return result;
  455. + }
  456. + virtual bool handler() {
  457. + Mutex::Autolock _l(flinger->mStateLock);
  458. + sp<const DisplayDevice> hw(flinger->getDisplayDevice(display));
  459. + result = flinger->captureScreenImplCpuConsumerLocked(hw, heap,
  460. + outWidth, outHeight,
  461. + sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
  462. + useIdentityTransform, rotation);
  463. + return true;
  464. + }
  465. + };
  466. +
  467. + sp<MessageBase> msg = new MessageCaptureScreen(this, display, heap,
  468. + outWidth, outHeight,
  469. + sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
  470. + useIdentityTransform, rotationFlags);
  471. + status_t res = postMessageSync(msg);
  472. + if (res == NO_ERROR) {
  473. + res = static_cast<MessageCaptureScreen*>(msg.get())->getResult();
  474. + }
  475. + return res;
  476. +}
  477. +#endif
  478. +
  479. // ---------------------------------------------------------------------------
  480.  
  481. SurfaceFlinger::LayerVector::LayerVector() {
  482. @@ -4012,6 +4163,7 @@ SurfaceFlinger::DisplayDeviceState::DisplayDeviceState(
  483. }; // namespace android
  484.  
  485.  
  486. +#ifndef USE_MHEAP_SCREENSHOT
  487. #if defined(__gl_h_)
  488. #error "don't include gl/gl.h in this file"
  489. #endif
  490. @@ -4019,3 +4171,4 @@ SurfaceFlinger::DisplayDeviceState::DisplayDeviceState(
  491. #if defined(__gl2_h_)
  492. #error "don't include gl2/gl2.h in this file"
  493. #endif
  494. +#endif
  495. --
  496. 2.7.4
  497.  
  498.  
  499. From cc6ff705bdeb06e3949673ff3f1c756b6ea02a8f Mon Sep 17 00:00:00 2001
  500. From: corphish <d97.avinaba@gmail.com>
  501. Date: Fri, 16 Sep 2016 22:21:08 +0530
  502. Subject: [PATCH 2/8] surfaceflinger: Use different function names for legacy
  503. captureScreen method
  504.  
  505. With newer API, captureScreen parameters got changed,
  506. overriding it may actually conflict somewhere else in the source. Solution:
  507. Use a different name for our functions.
  508.  
  509. Signed-off-by: corphish <d97.avinaba@gmail.com>
  510. ---
  511. include/gui/ISurfaceComposer.h | 2 +-
  512. libs/gui/ISurfaceComposer.cpp | 4 ++--
  513. libs/gui/SurfaceComposerClient.cpp | 2 +-
  514. services/surfaceflinger/SurfaceFlinger.h | 2 +-
  515. services/surfaceflinger/SurfaceFlinger_hwc1.cpp | 2 +-
  516. 5 files changed, 6 insertions(+), 6 deletions(-)
  517.  
  518. diff --git a/include/gui/ISurfaceComposer.h b/include/gui/ISurfaceComposer.h
  519. index 725575a..9b32836 100644
  520. --- a/include/gui/ISurfaceComposer.h
  521. +++ b/include/gui/ISurfaceComposer.h
  522. @@ -161,7 +161,7 @@ public:
  523. /* Capture the specified screen. requires READ_FRAME_BUFFER permission
  524. * This function will fail if there is a secure window on screen.
  525. */
  526. - virtual status_t captureScreen(const sp<IBinder>& display, sp<IMemoryHeap>* heap,
  527. + virtual status_t captureScreenLegacy(const sp<IBinder>& display, sp<IMemoryHeap>* heap,
  528. uint32_t* width, uint32_t* height,
  529. Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  530. uint32_t minLayerZ, uint32_t maxLayerZ,
  531. diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp
  532. index 5c5caa5..062573b 100644
  533. --- a/libs/gui/ISurfaceComposer.cpp
  534. +++ b/libs/gui/ISurfaceComposer.cpp
  535. @@ -102,7 +102,7 @@ public:
  536. }
  537.  
  538. #ifdef USE_MHEAP_SCREENSHOT
  539. - virtual status_t captureScreen(
  540. + virtual status_t captureScreenLegacy(
  541. const sp<IBinder>& display, sp<IMemoryHeap>* heap,
  542. uint32_t* width, uint32_t* height,
  543. Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  544. @@ -493,7 +493,7 @@ status_t BnSurfaceComposer::onTransact(
  545. sp<IMemoryHeap> heap;
  546. uint32_t w, h;
  547.  
  548. - status_t res = captureScreen(display, &heap, &w, &h,
  549. + status_t res = captureScreenLegacy(display, &heap, &w, &h,
  550. sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
  551. useIdentityTransform,
  552. static_cast<ISurfaceComposer::Rotation>(rotation));
  553. diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
  554. index f5218f5..9fa675c 100644
  555. --- a/libs/gui/SurfaceComposerClient.cpp
  556. +++ b/libs/gui/SurfaceComposerClient.cpp
  557. @@ -963,7 +963,7 @@ status_t ScreenshotClient::update(const sp<IBinder>& display,
  558. #ifdef USE_MHEAP_SCREENSHOT
  559. int ret = -1;
  560. mHeap = 0;
  561. - ret = s->captureScreen(display, &mHeap, &mBuffer.width, &mBuffer.height, sourceCrop,
  562. + ret = s->captureScreenLegacy(display, &mHeap, &mBuffer.width, &mBuffer.height, sourceCrop,
  563. reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
  564. static_cast<ISurfaceComposer::Rotation>(rotation));
  565.  
  566. diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
  567. index 01475e1..059e429 100644
  568. --- a/services/surfaceflinger/SurfaceFlinger.h
  569. +++ b/services/surfaceflinger/SurfaceFlinger.h
  570. @@ -230,7 +230,7 @@ private:
  571. bool useIdentityTransform, ISurfaceComposer::Rotation rotation,
  572. bool isCpuConsumer);
  573. #ifdef USE_MHEAP_SCREENSHOT
  574. - virtual status_t captureScreen(const sp<IBinder>& display, sp<IMemoryHeap>* heap,
  575. + virtual status_t captureScreenLegacy(const sp<IBinder>& display, sp<IMemoryHeap>* heap,
  576. uint32_t* width, uint32_t* height,
  577. Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  578. uint32_t minLayerZ, uint32_t maxLayerZ,
  579. diff --git a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
  580. index 9deb50b..7ea7f28 100644
  581. --- a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
  582. +++ b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
  583. @@ -4022,7 +4022,7 @@ status_t SurfaceFlinger::captureScreenImplCpuConsumerLocked(
  584. return result;
  585. }
  586.  
  587. -status_t SurfaceFlinger::captureScreen(const sp<IBinder>& display,
  588. +status_t SurfaceFlinger::captureScreenLegacy(const sp<IBinder>& display,
  589. sp<IMemoryHeap>* heap, uint32_t* outWidth, uint32_t* outHeight,
  590. Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
  591. uint32_t minLayerZ, uint32_t maxLayerZ,
  592. --
  593. 2.7.4
  594.  
  595.  
  596. From b5af229001bdcc23f71b3dde300497b3632505c9 Mon Sep 17 00:00:00 2001
  597. From: ghsr <ghsr92@yandex.ru>
  598. Date: Sat, 18 Nov 2017 12:56:13 +0600
  599. Subject: [PATCH 3/8] BufferQueueProducer: CAPRI_HWC: disable
  600. connect/disconnect methods
  601.  
  602. ---
  603. libs/gui/BufferQueueProducer.cpp | 14 ++++++++++++++
  604. 1 file changed, 14 insertions(+)
  605.  
  606. diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp
  607. index ff85eb5..32852f2 100644
  608. --- a/libs/gui/BufferQueueProducer.cpp
  609. +++ b/libs/gui/BufferQueueProducer.cpp
  610. @@ -66,10 +66,12 @@ status_t BufferQueueProducer::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
  611. return NO_INIT;
  612. }
  613.  
  614. +#ifndef CAPRI_HWC
  615. if (mCore->mConnectedApi == BufferQueueCore::NO_CONNECTED_API) {
  616. BQ_LOGE("requestBuffer: BufferQueue has no connected producer");
  617. return NO_INIT;
  618. }
  619. +#endif
  620.  
  621. if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) {
  622. BQ_LOGE("requestBuffer: slot index %d out of range [0, %d)",
  623. @@ -354,10 +356,12 @@ status_t BufferQueueProducer::dequeueBuffer(int *outSlot,
  624. return NO_INIT;
  625. }
  626.  
  627. +#ifndef CAPRI_HWC
  628. if (mCore->mConnectedApi == BufferQueueCore::NO_CONNECTED_API) {
  629. BQ_LOGE("dequeueBuffer: BufferQueue has no connected producer");
  630. return NO_INIT;
  631. }
  632. +#endif
  633. } // Autolock scope
  634.  
  635. BQ_LOGV("dequeueBuffer: w=%u h=%u format=%#x, usage=%#x", width, height,
  636. @@ -569,10 +573,12 @@ status_t BufferQueueProducer::detachBuffer(int slot) {
  637. return NO_INIT;
  638. }
  639.  
  640. +#ifndef CAPRI_HWC
  641. if (mCore->mConnectedApi == BufferQueueCore::NO_CONNECTED_API) {
  642. BQ_LOGE("detachBuffer: BufferQueue has no connected producer");
  643. return NO_INIT;
  644. }
  645. +#endif
  646.  
  647. if (mCore->mSharedBufferMode || mCore->mSharedBufferSlot == slot) {
  648. BQ_LOGE("detachBuffer: cannot detach a buffer in shared buffer mode");
  649. @@ -628,10 +634,12 @@ status_t BufferQueueProducer::detachNextBuffer(sp<GraphicBuffer>* outBuffer,
  650. return NO_INIT;
  651. }
  652.  
  653. +#ifndef CAPRI_HWC
  654. if (mCore->mConnectedApi == BufferQueueCore::NO_CONNECTED_API) {
  655. BQ_LOGE("detachNextBuffer: BufferQueue has no connected producer");
  656. return NO_INIT;
  657. }
  658. +#endif
  659.  
  660. if (mCore->mSharedBufferMode) {
  661. BQ_LOGE("detachNextBuffer: cannot detach a buffer in shared buffer "
  662. @@ -678,10 +686,12 @@ status_t BufferQueueProducer::attachBuffer(int* outSlot,
  663. return NO_INIT;
  664. }
  665.  
  666. +#ifndef CAPRI_HWC
  667. if (mCore->mConnectedApi == BufferQueueCore::NO_CONNECTED_API) {
  668. BQ_LOGE("attachBuffer: BufferQueue has no connected producer");
  669. return NO_INIT;
  670. }
  671. +#endif
  672.  
  673. if (mCore->mSharedBufferMode) {
  674. BQ_LOGE("attachBuffer: cannot attach a buffer in shared buffer mode");
  675. @@ -772,10 +782,12 @@ status_t BufferQueueProducer::queueBuffer(int slot,
  676. return NO_INIT;
  677. }
  678.  
  679. +#ifndef CAPRI_HWC
  680. if (mCore->mConnectedApi == BufferQueueCore::NO_CONNECTED_API) {
  681. BQ_LOGE("queueBuffer: BufferQueue has no connected producer");
  682. return NO_INIT;
  683. }
  684. +#endif
  685.  
  686. if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) {
  687. BQ_LOGE("queueBuffer: slot index %d out of range [0, %d)",
  688. @@ -969,10 +981,12 @@ status_t BufferQueueProducer::cancelBuffer(int slot, const sp<Fence>& fence) {
  689. return NO_INIT;
  690. }
  691.  
  692. +#ifndef CAPRI_HWC
  693. if (mCore->mConnectedApi == BufferQueueCore::NO_CONNECTED_API) {
  694. BQ_LOGE("cancelBuffer: BufferQueue has no connected producer");
  695. return NO_INIT;
  696. }
  697. +#endif
  698.  
  699. if (mCore->mSharedBufferMode) {
  700. BQ_LOGE("cancelBuffer: cannot cancel a buffer in shared buffer mode");
  701. --
  702. 2.7.4
  703.  
  704.  
  705. From 70db9faf672259d4a0eb76e59da057b5aa46c68a Mon Sep 17 00:00:00 2001
  706. From: Pawit Pornkitprasan <p.pawit@gmail.com>
  707. Date: Thu, 14 Nov 2013 15:19:46 +0700
  708. Subject: [PATCH 4/8] binder: add compat symbol
  709.  
  710. Required for older Samsung libtvout
  711.  
  712. Change-Id: Ib18d2513570382432d49f302ab041230650372f2
  713. ---
  714. libs/binder/IPCThreadState.cpp | 4 ++++
  715. 1 file changed, 4 insertions(+)
  716.  
  717. diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp
  718. index 3efebf7..505570a 100644
  719. --- a/libs/binder/IPCThreadState.cpp
  720. +++ b/libs/binder/IPCThreadState.cpp
  721. @@ -353,6 +353,10 @@ status_t IPCThreadState::clearLastError()
  722. return err;
  723. }
  724.  
  725. +extern "C" int _ZN7android14IPCThreadState13getCallingPidEv(IPCThreadState *state) {
  726. + return state->getCallingPid();
  727. +}
  728. +
  729. pid_t IPCThreadState::getCallingPid() const
  730. {
  731. return mCallingPid;
  732. --
  733. 2.7.4
  734.  
  735.  
  736. From 16e54c7c9db33748c6205c893267e134c1fa8d1d Mon Sep 17 00:00:00 2001
  737. From: Pawit Pornkitprasan <p.pawit@gmail.com>
  738. Date: Tue, 10 Dec 2013 19:38:17 +0700
  739. Subject: [PATCH 5/8] binder: add compat symbols
  740.  
  741. Required for libtvservice_binder.so on I9082
  742.  
  743. Change-Id: I059e92f19e4c5a911d38faa9c4df549c75c90761
  744. ---
  745. libs/binder/Parcel.cpp | 12 ++++++++++++
  746. 1 file changed, 12 insertions(+)
  747.  
  748. diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
  749. index 52caa24..5de642f 100644
  750. --- a/libs/binder/Parcel.cpp
  751. +++ b/libs/binder/Parcel.cpp
  752. @@ -1267,6 +1267,12 @@ status_t Parcel::writeDupImmutableBlobFileDescriptor(int fd)
  753. return writeDupFileDescriptor(fd);
  754. }
  755.  
  756. +extern "C" status_t _ZN7android6Parcel5writeERKNS0_26FlattenableHelperInterfaceE(void *parcel, void *val);
  757. +
  758. +extern "C" status_t _ZN7android6Parcel5writeERKNS_11FlattenableE(void *parcel, void *val) {
  759. + return _ZN7android6Parcel5writeERKNS0_26FlattenableHelperInterfaceE(parcel, val);
  760. +}
  761. +
  762. status_t Parcel::write(const FlattenableHelperInterface& val)
  763. {
  764. status_t err;
  765. @@ -2056,6 +2062,12 @@ status_t Parcel::readBlob(size_t len, ReadableBlob* outBlob) const
  766. return NO_ERROR;
  767. }
  768.  
  769. +extern "C" status_t _ZNK7android6Parcel4readERNS0_26FlattenableHelperInterfaceE(void *parcel, void *val);
  770. +
  771. +extern "C" status_t _ZNK7android6Parcel4readERNS_11FlattenableE(void *parcel, void *val) {
  772. + return _ZNK7android6Parcel4readERNS0_26FlattenableHelperInterfaceE(parcel, val);
  773. +}
  774. +
  775. status_t Parcel::read(FlattenableHelperInterface& val) const
  776. {
  777. // size
  778. --
  779. 2.7.4
  780.  
  781.  
  782. From 8939ff3547d059ddaf183b362de785fd2cea1815 Mon Sep 17 00:00:00 2001
  783. From: Pawit Pornkitprasan <p.pawit@gmail.com>
  784. Date: Mon, 16 Dec 2013 15:45:42 +0700
  785. Subject: [PATCH 6/8] sf: CAPRI_HWC: fix rotation artifact
  786.  
  787. ---
  788. services/surfaceflinger/SurfaceFlinger_hwc1.cpp | 5 +++++
  789. 1 file changed, 5 insertions(+)
  790.  
  791. diff --git a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
  792. index 7ea7f28..c97bbdf 100644
  793. --- a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
  794. +++ b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
  795. @@ -3747,6 +3747,11 @@ status_t SurfaceFlinger::captureScreenImplLocked(
  796. {
  797. ATRACE_CALL();
  798.  
  799. +// Rotation artifact problems when useReadPixels is false
  800. +#ifdef CAPRI_HWC
  801. + useReadPixels = true;
  802. +#endif
  803. +
  804. // get screen geometry
  805. uint32_t hw_w = hw->getWidth();
  806. uint32_t hw_h = hw->getHeight();
  807. --
  808. 2.7.4
  809.  
  810.  
  811. From 7b631e848be1b3f1c37af6898a63e394d5efa80b Mon Sep 17 00:00:00 2001
  812. From: Pawit Pornkitprasan <p.pawit@gmail.com>
  813. Date: Mon, 15 Dec 2014 23:12:44 +0700
  814. Subject: [PATCH 7/8] SurfaceComposerClient: don't block RGBA_8888 for
  815. screenshot on CAPRI_HWC
  816.  
  817. Works here and required for ColorFade animation
  818.  
  819. Change-Id: Ie7d549bb63e11380d7efcab27b7e4d9f3eb2a1fe
  820. ---
  821. libs/gui/SurfaceComposerClient.cpp | 2 +-
  822. 1 file changed, 1 insertion(+), 1 deletion(-)
  823.  
  824. diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
  825. index 9fa675c..e8b5aef 100644
  826. --- a/libs/gui/SurfaceComposerClient.cpp
  827. +++ b/libs/gui/SurfaceComposerClient.cpp
  828. @@ -922,7 +922,7 @@ status_t ScreenshotClient::capture(
  829. uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) {
  830. sp<ISurfaceComposer> s(ComposerService::getComposerService());
  831. if (s == NULL) return NO_INIT;
  832. -#ifdef USE_MHEAP_SCREENSHOT
  833. +#if defined(USE_MHEAP_SCREENSHOT) && !defined(CAPRI_HWC)
  834. int format = 0;
  835. producer->query(NATIVE_WINDOW_FORMAT,&format);
  836. if (format == PIXEL_FORMAT_RGBA_8888) {
  837. --
  838. 2.7.4
  839.  
  840.  
  841. From afba76166beac37b9ad222c2c62d2a65890140e6 Mon Sep 17 00:00:00 2001
  842. From: Pawit Pornkitprasan <p.pawit@gmail.com>
  843. Date: Sun, 11 Oct 2015 15:28:51 +0700
  844. Subject: [PATCH 8/8] binder: add compat symbol for RIL
  845.  
  846. ---
  847. libs/binder/Parcel.cpp | 6 ++++++
  848. 1 file changed, 6 insertions(+)
  849.  
  850. diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
  851. index 5de642f..eb9c566 100644
  852. --- a/libs/binder/Parcel.cpp
  853. +++ b/libs/binder/Parcel.cpp
  854. @@ -1082,6 +1082,12 @@ status_t Parcel::writeString16(const String16& str)
  855. return writeString16(str.string(), str.size());
  856. }
  857.  
  858. +extern "C" status_t _ZN7android6Parcel13writeString16EPKDsj(void *parcel, const char16_t* str, size_t len);
  859. +
  860. +extern "C" status_t _ZN7android6Parcel13writeString16EPKtj(void *parcel, const char16_t* str, size_t len) {
  861. + return _ZN7android6Parcel13writeString16EPKDsj(parcel, str, len);
  862. +}
  863. +
  864. status_t Parcel::writeString16(const char16_t* str, size_t len)
  865. {
  866. if (str == NULL) return writeInt32(-1);
  867. --
  868. 2.7.4
Add Comment
Please, Sign In to add comment