搞定了android4.0.3的触摸屏的适配后(其实只要驱动没有什么问题,加个配置文件就很容易搞定了),新的任务就下来了,就是要寻找android4.0.3中的鼠标是如何绘画的,哪里createSurface,哪里分配空间的。因为如果是软鼠标的话,在播放视频或者玩大型游戏的时候是很卡的,而走overlay,硬鼠标的话,就显得很灵敏了。艰巨的任务啊,看了我好久还是没有找到鼠标是在哪里绘制的。因为android2.3是在WindowManagerService里面new了一个surface,接着画了几条线而得到的,而android4.0.3中,找了n久还是没有发现,可恶的android4.0.3,网上资料也没有介绍。
        期间也添加了android中的power、volumeup、volumedown三个按键,虽然基本功能实现了,但是还是没有搞明白那个长按电源键出来关机和重启等选项是怎么实现的。无聊之余,把KEY的DOWN和UP顺序对调了下,居然有点效果,在此非常疑惑。就是我本来实现的时候,input子系统上报是

[html] view plaincopy
  1. input_report_key(&button_dev, KEY_POWER, 1);
[html] view plaincopy
  1. input_report_key(&button_dev, KEY_POWER, 0);

这样可以实现电源键的锁屏功能。但当我交换了上报的顺寻后也就是

[html] view plaincopy
[html] view plaincopy
  1. input_report_key(&button_dev, KEY_POWER, 0);
  2. <pre class="html" name="code">input_report_key(&button_dev, KEY_POWER, 1);</pre><br>
  3. <pre></pre>
  4. <p>居然是那个长按键的功能,不知道哪位高手可以指导一下,这个还是得等找到了鼠标绘制的地方后再深入下去吧。        一直以为surface的创建是在WindowManagerService中实现的,没想到,这个android4.0.3居然把surface创建,鼠标绘制放在了input下了,这个可恶的SpriteController.cpp,目录/frameworks/base/services/input/SpriteController.cpp。找得心灰意冷啊。居然中文解释说是精灵,怪不得这么难找呢。网上找了下,说java中好像是有一个Sprite的东东,说是什么绘图时候用的,这不正好是鼠标吗,小小的精灵,难怪鼠标也是天蓝色透明的了,看来写这个代码的高手还真的别有一番寓意啊,在此膜拜下。
  5. 由于本人还是菜鸟,学电子的孩子,C++和Java接触好少,看不大懂,只能简单的了解下。先看看Sprite类的定义。注释的已经很清楚了,六级都没过的我也能看懂,相信难不倒你了。</p>
  6. <pre class="html" name="code">class Sprite : public RefBase {
  7. protected:
  8. Sprite() { }
  9. virtual ~Sprite() { }
  10. public:
  11. enum {
  12. // The base layer for pointer sprites.
  13. BASE_LAYER_POINTER = 0, // reserve space for 1 pointer
  14. // The base layer for spot sprites.
  15. BASE_LAYER_SPOT = 1, // reserve space for MAX_POINTER_ID spots
  16. };
  17. /* Sets the bitmap that is drawn by the sprite.
  18. * The sprite retains a copy of the bitmap for subsequent rendering. */
  19. virtual void setIcon(const SpriteIcon& icon) = 0;
  20. inline void clearIcon() {
  21. setIcon(SpriteIcon());
  22. }
  23. /* Sets whether the sprite is visible. */
  24. virtual void setVisible(bool visible) = 0;
  25. /* Sets the sprite position on screen, relative to the sprite's hot spot. */
  26. virtual void setPosition(float x, float y) = 0;
  27. /* Sets the layer of the sprite, relative to the system sprite overlay layer.
  28. * Layer 0 is the overlay layer, > 0 appear above this layer. */
  29. virtual void setLayer(int32_t layer) = 0;
  30. /* Sets the sprite alpha blend ratio between 0.0 and 1.0. */
  31. virtual void setAlpha(float alpha) = 0;
  32. /* Sets the sprite transformation matrix. */
  33. virtual void setTransformationMatrix(const SpriteTransformationMatrix& matrix) = 0;
  34. };
  35. </pre>
  36. <p><br>
  37. 一开始的搜寻路线是找到鼠标那个png图片是哪里调用的,鼠标早就不叫mouse了,cursor或者pointer早就替换了mouse了。鼠标的图标是在EventHub发现了鼠标这个驱动</p>
  38. <p>(android4.0.3中应该是cursor这个驱动)后再由frameworks/base/core/java/android/view/PointerIcon.java中的getSystemIcon()导入,然后再由SpriteController::SpriteImpl::setIcon()(c++的类的继承,虚函数,各种纠结,只能稍微理解)设置为Sprite这个精灵的资源。每次鼠标移动后,InputReader线程总会获取这个坐标值,然后InputDispatch会分发给WindowManagerService,而ViewRootImpl会读取等等,这个网上讲得已经很详细了。<br>
  39. 对于鼠标,应该也是pointer,input目录下面还有一个PointerController,看着这个名字,就知道了,这个肯定是控制鼠标啊, 触摸屏啊什么的。具体看注释吧,写得够直</p>
  40. <p>白的。</p>
  41. <pre class="html" name="code">/**
  42. * Interface for tracking a mouse / touch pad pointer and touch pad spots.
  43. *
  44. * The spots are sprites on screen that visually represent the positions of
  45. * fingers
  46. *
  47. * The pointer controller is responsible for providing synchronization and for tracking
  48. * display orientation changes if needed.
  49. */
  50. class PointerControllerInterface : public virtual RefBase {
  51. protected:
  52. PointerControllerInterface() { }
  53. virtual ~PointerControllerInterface() { }
  54. public:
  55. /* Gets the bounds of the region that the pointer can traverse.
  56. * Returns true if the bounds are available. */
  57. virtual bool getBounds(float* outMinX, float* outMinY,
  58. float* outMaxX, float* outMaxY) const = 0;
  59. /* Move the pointer. */
  60. virtual void move(float deltaX, float deltaY) = 0;
  61. /* Sets a mask that indicates which buttons are pressed. */
  62. virtual void setButtonState(int32_t buttonState) = 0;
  63. /* Gets a mask that indicates which buttons are pressed. */
  64. virtual int32_t getButtonState() const = 0;
  65. /* Sets the absolute location of the pointer. */
  66. virtual void setPosition(float x, float y) = 0;
  67. /* Gets the absolute location of the pointer. */
  68. virtual void getPosition(float* outX, float* outY) const = 0;
  69. enum Transition {
  70. // Fade/unfade immediately.
  71. TRANSITION_IMMEDIATE,
  72. // Fade/unfade gradually.
  73. TRANSITION_GRADUAL,
  74. };
  75. /* Fades the pointer out now. */
  76. virtual void fade(Transition transition) = 0;
  77. /* Makes the pointer visible if it has faded out.
  78. * The pointer never unfades itself automatically.  This method must be called
  79. * by the client whenever the pointer is moved or a button is pressed and it
  80. * wants to ensure that the pointer becomes visible again. */
  81. virtual void unfade(Transition transition) = 0;
  82. enum Presentation {
  83. // Show the mouse pointer.
  84. PRESENTATION_POINTER,
  85. // Show spots and a spot anchor in place of the mouse pointer.
  86. PRESENTATION_SPOT,
  87. };
  88. /* Sets the mode of the pointer controller. */
  89. virtual void setPresentation(Presentation presentation) = 0;
  90. /* Sets the spots for the current gesture.
  91. * The spots are not subject to the inactivity timeout like the pointer
  92. * itself it since they are expected to remain visible for so long as
  93. * the fingers are on the touch pad.
  94. *
  95. * The values of the AMOTION_EVENT_AXIS_PRESSURE axis is significant.
  96. * For spotCoords, pressure != 0 indicates that the spot's location is being
  97. * pressed (not hovering).
  98. */
  99. virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
  100. BitSet32 spotIdBits) = 0;
  101. /* Removes all spots. */
  102. virtual void clearSpots() = 0;
  103. };
  104. /*
  105. * Pointer resources.
  106. */
  107. struct PointerResources {
  108. SpriteIcon spotHover;
  109. SpriteIcon spotTouch;
  110. SpriteIcon spotAnchor;
  111. };
  112. </pre>
  113. <p><br>
  114. 而PointerController是继承PointerControllerInterface的。突然看到这下面那两行英文,这么熟悉,这么刺眼,顿时觉得,晴空霹雳啊,明明写得这么清楚了,画pointer精灵到surface,这,,让我情何以堪,找了这么久,苍天呢,都怪C++不够好有木有,英语不够牛有不有。其实android中很多函数的功能都在他的类的定义中有说明的,何不仔细研究.h呢?而把大把大把的时间浪费在.cpp中了,经验啊,经验不足啊。</p>
  115. <pre class="html" name="code">/*
  116. * Tracks pointer movements and draws the pointer sprite to a surface.
  117. *
  118. * Handles pointer acceleration and animation.
  119. */
  120. class PointerController : public PointerControllerInterface, public MessageHandler
  121. 好了,发泄好了,而在Sprite中,最重要的就是SpriteController::doUpdateSprites()这个函数了,这里就是鼠标绘制和移动后更新的全过程了。
  122. void SpriteController::doUpdateSprites() {
  123. // Collect information about sprite updates.
  124. // Each sprite update record includes a reference to its associated sprite so we can
  125. // be certain the sprites will not be deleted while this function runs.  Sprites
  126. // may invalidate themselves again during this time but we will handle those changes
  127. // in the next iteration.
  128. Vector<SpriteUpdate> updates;
  129. size_t numSprites;
  130. { // acquire lock
  131. AutoMutex _l(mLock);
  132. numSprites = mLocked.invalidatedSprites.size();
  133. for (size_t i = 0; i < numSprites; i++) {
  134. const sp<SpriteImpl>& sprite = mLocked.invalidatedSprites.itemAt(i);
  135. updates.push(SpriteUpdate(sprite, sprite->getStateLocked()));
  136. sprite->resetDirtyLocked();
  137. }
  138. mLocked.invalidatedSprites.clear();
  139. } // release lock
  140. // Create missing surfaces.
  141. bool surfaceChanged = false;
  142. for (size_t i = 0; i < numSprites; i++) {
  143. SpriteUpdate& update = updates.editItemAt(i);
  144. if (update.state.surfaceControl == NULL && update.state.wantSurfaceVisible()) {
  145. update.state.surfaceWidth = update.state.icon.bitmap.width();
  146. update.state.surfaceHeight = update.state.icon.bitmap.height();
  147. update.state.surfaceDrawn = false;
  148. update.state.surfaceVisible = false;
  149. update.state.surfaceControl = obtainSurface(
  150. update.state.surfaceWidth, update.state.surfaceHeight);
  151. if (update.state.surfaceControl != NULL) {
  152. update.surfaceChanged = surfaceChanged = true;
  153. }
  154. }
  155. }
  156. // Resize sprites if needed, inside a global transaction.
  157. bool haveGlobalTransaction = false;
  158. for (size_t i = 0; i < numSprites; i++) {
  159. SpriteUpdate& update = updates.editItemAt(i);
  160. if (update.state.surfaceControl != NULL && update.state.wantSurfaceVisible()) {
  161. int32_t desiredWidth = update.state.icon.bitmap.width();
  162. int32_t desiredHeight = update.state.icon.bitmap.height();
  163. if (update.state.surfaceWidth < desiredWidth
  164. || update.state.surfaceHeight < desiredHeight) {
  165. if (!haveGlobalTransaction) {
  166. SurfaceComposerClient::openGlobalTransaction();
  167. haveGlobalTransaction = true;
  168. }
  169. status_t status = update.state.surfaceControl->setSize(desiredWidth, desiredHeight);
  170. if (status) {
  171. LOGE("Error %d resizing sprite surface from %dx%d to %dx%d",
  172. status, update.state.surfaceWidth, update.state.surfaceHeight,
  173. desiredWidth, desiredHeight);
  174. } else {
  175. update.state.surfaceWidth = desiredWidth;
  176. update.state.surfaceHeight = desiredHeight;
  177. update.state.surfaceDrawn = false;
  178. update.surfaceChanged = surfaceChanged = true;
  179. if (update.state.surfaceVisible) {
  180. status = update.state.surfaceControl->hide();
  181. if (status) {
  182. LOGE("Error %d hiding sprite surface after resize.", status);
  183. } else {
  184. update.state.surfaceVisible = false;
  185. }
  186. }
  187. }
  188. }
  189. }
  190. }
  191. if (haveGlobalTransaction) {
  192. SurfaceComposerClient::closeGlobalTransaction();
  193. }
  194. // Redraw sprites if needed.
  195. for (size_t i = 0; i < numSprites; i++) {
  196. SpriteUpdate& update = updates.editItemAt(i);
  197. if ((update.state.dirty & DIRTY_BITMAP) && update.state.surfaceDrawn) {
  198. update.state.surfaceDrawn = false;
  199. update.surfaceChanged = surfaceChanged = true;
  200. }
  201. if (update.state.surfaceControl != NULL && !update.state.surfaceDrawn
  202. && update.state.wantSurfaceVisible()) {
  203. sp<Surface> surface = update.state.surfaceControl->getSurface();
  204. Surface::SurfaceInfo surfaceInfo;
  205. status_t status = surface->lock(&surfaceInfo);
  206. if (status) {
  207. LOGE("Error %d locking sprite surface before drawing.", status);
  208. } else {
  209. SkBitmap surfaceBitmap;
  210. ssize_t bpr = surfaceInfo.s * bytesPerPixel(surfaceInfo.format);
  211. surfaceBitmap.setConfig(SkBitmap::kARGB_8888_Config,
  212. surfaceInfo.w, surfaceInfo.h, bpr);
  213. surfaceBitmap.setPixels(surfaceInfo.bits);
  214. SkCanvas surfaceCanvas;
  215. surfaceCanvas.setBitmapDevice(surfaceBitmap);
  216. SkPaint paint;
  217. paint.setXfermodeMode(SkXfermode::kSrc_Mode);
  218. surfaceCanvas.drawBitmap(update.state.icon.bitmap, 0, 0, &paint);
  219. if (surfaceInfo.w > uint32_t(update.state.icon.bitmap.width())) {
  220. paint.setColor(0); // transparent fill color
  221. surfaceCanvas.drawRectCoords(update.state.icon.bitmap.width(), 0,
  222. surfaceInfo.w, update.state.icon.bitmap.height(), paint);
  223. }
  224. if (surfaceInfo.h > uint32_t(update.state.icon.bitmap.height())) {
  225. paint.setColor(0); // transparent fill color
  226. surfaceCanvas.drawRectCoords(0, update.state.icon.bitmap.height(),
  227. surfaceInfo.w, surfaceInfo.h, paint);
  228. }
  229. status = surface->unlockAndPost();
  230. if (status) {
  231. LOGE("Error %d unlocking and posting sprite surface after drawing.", status);
  232. } else {
  233. update.state.surfaceDrawn = true;
  234. update.surfaceChanged = surfaceChanged = true;
  235. }
  236. }
  237. }
  238. }
  239. // Set sprite surface properties and make them visible.
  240. bool haveTransaction = false;
  241. for (size_t i = 0; i < numSprites; i++) {
  242. SpriteUpdate& update = updates.editItemAt(i);
  243. bool wantSurfaceVisibleAndDrawn = update.state.wantSurfaceVisible()
  244. && update.state.surfaceDrawn;
  245. bool becomingVisible = wantSurfaceVisibleAndDrawn && !update.state.surfaceVisible;
  246. bool becomingHidden = !wantSurfaceVisibleAndDrawn && update.state.surfaceVisible;
  247. if (update.state.surfaceControl != NULL && (becomingVisible || becomingHidden
  248. || (wantSurfaceVisibleAndDrawn && (update.state.dirty & (DIRTY_ALPHA
  249. | DIRTY_POSITION | DIRTY_TRANSFORMATION_MATRIX | DIRTY_LAYER
  250. | DIRTY_VISIBILITY | DIRTY_HOTSPOT))))) {
  251. status_t status;
  252. if (!haveTransaction) {
  253. SurfaceComposerClient::openGlobalTransaction();
  254. haveTransaction = true;
  255. }
  256. if (wantSurfaceVisibleAndDrawn
  257. && (becomingVisible || (update.state.dirty & DIRTY_ALPHA))) {
  258. status = update.state.surfaceControl->setAlpha(update.state.alpha);
  259. if (status) {
  260. LOGE("Error %d setting sprite surface alpha.", status);
  261. }
  262. }
  263. if (wantSurfaceVisibleAndDrawn
  264. && (becomingVisible || (update.state.dirty & (DIRTY_POSITION
  265. | DIRTY_HOTSPOT)))) {
  266. status = update.state.surfaceControl->setPosition(
  267. update.state.positionX - update.state.icon.hotSpotX,
  268. update.state.positionY - update.state.icon.hotSpotY);
  269. if (status) {
  270. LOGE("Error %d setting sprite surface position.", status);
  271. }
  272. }
  273. if (wantSurfaceVisibleAndDrawn
  274. && (becomingVisible
  275. || (update.state.dirty & DIRTY_TRANSFORMATION_MATRIX))) {
  276. status = update.state.surfaceControl->setMatrix(
  277. update.state.transformationMatrix.dsdx,
  278. update.state.transformationMatrix.dtdx,
  279. update.state.transformationMatrix.dsdy,
  280. update.state.transformationMatrix.dtdy);
  281. if (status) {
  282. LOGE("Error %d setting sprite surface transformation matrix.", status);
  283. }
  284. }
  285. int32_t surfaceLayer = mOverlayLayer + update.state.layer;
  286. if (wantSurfaceVisibleAndDrawn
  287. && (becomingVisible || (update.state.dirty & DIRTY_LAYER))) {
  288. status = update.state.surfaceControl->setLayer(surfaceLayer);
  289. if (status) {
  290. LOGE("Error %d setting sprite surface layer.", status);
  291. }
  292. }
  293. if (becomingVisible) {
  294. status = update.state.surfaceControl->show(surfaceLayer);
  295. if (status) {
  296. LOGE("Error %d showing sprite surface.", status);
  297. } else {
  298. update.state.surfaceVisible = true;
  299. update.surfaceChanged = surfaceChanged = true;
  300. }
  301. } else if (becomingHidden) {
  302. status = update.state.surfaceControl->hide();
  303. if (status) {
  304. LOGE("Error %d hiding sprite surface.", status);
  305. } else {
  306. update.state.surfaceVisible = false;
  307. update.surfaceChanged = surfaceChanged = true;
  308. }
  309. }
  310. }
  311. }
  312. if (haveTransaction) {
  313. SurfaceComposerClient::closeGlobalTransaction();
  314. }
  315. // If any surfaces were changed, write back the new surface properties to the sprites.
  316. if (surfaceChanged) { // acquire lock
  317. AutoMutex _l(mLock);
  318. for (size_t i = 0; i < numSprites; i++) {
  319. const SpriteUpdate& update = updates.itemAt(i);
  320. if (update.surfaceChanged) {
  321. update.sprite->setSurfaceLocked(update.state.surfaceControl,
  322. update.state.surfaceWidth, update.state.surfaceHeight,
  323. update.state.surfaceDrawn, update.state.surfaceVisible);
  324. }
  325. }
  326. } // release lock
  327. // Clear the sprite update vector outside the lock.  It is very important that
  328. // we do not clear sprite references inside the lock since we could be releasing
  329. // the last remaining reference to the sprite here which would result in the
  330. // sprite being deleted and the lock being reacquired by the sprite destructor
  331. // while already held.
  332. updates.clear();
  333. }
  334. </pre>
  335. <p><br>
  336. 看到 update.state.surfaceControl = obtainSurface(update.state.surfaceWidth, update.state.surfaceHeight); 其实就是创建了一个surface,在一开始进入的主界面</p>
  337. <p>的时候,鼠标是没有的,当移动了下鼠标或者点击了下鼠标后就执行这个创建了这个surface,有logcat后的信息为证(只可惜公司nta内的东西拿不出来)。</p>
  338. <pre class="html" name="code">sp<SurfaceControl> SpriteController::obtainSurface(int32_t width, int32_t height) {
  339. ensureSurfaceComposerClient();
  340. sp<SurfaceControl> surfaceControl = mSurfaceComposerClient->createSurface(
  341. String8("Sprite"), 0, width, height, PIXEL_FORMAT_RGBA_8888);
  342. if (surfaceControl == NULL || !surfaceControl->isValid()
  343. || !surfaceControl->getSurface()->isValid()) {
  344. LOGE("Error creating sprite surface.");
  345. return NULL;
  346. }
  347. return surfaceControl;
  348. }
  349. </pre>
  350. <p><br>
  351. 而创建完后,必须得分配空间啊,surface的信息也得录入啊。具体就在下面了</p>
  352. <p> </p>
  353. <pre class="html" name="code">sp<Surface> surface = update.state.surfaceControl->getSurface();
  354. Surface::SurfaceInfo surfaceInfo;
  355. status_t status = surface->lock(&surfaceInfo);
  356. </pre>
  357. <p><br>
  358. 看到lock()了吗?就是这,继续跟进代码<br>
  359. </p>
  360. <pre class="html" name="code">status_t Surface::lock(SurfaceInfo* other, Region* inOutDirtyRegion) {
  361. ANativeWindow_Buffer outBuffer;
  362. ARect temp;
  363. ARect* inOutDirtyBounds = NULL;
  364. if (inOutDirtyRegion) {
  365. temp = inOutDirtyRegion->getBounds();
  366. inOutDirtyBounds = &temp;
  367. }
  368. status_t err = SurfaceTextureClient::lock(&outBuffer, inOutDirtyBounds);
  369. if (err == NO_ERROR) {
  370. other->w = uint32_t(outBuffer.width);
  371. other->h = uint32_t(outBuffer.height);
  372. other->s = uint32_t(outBuffer.stride);
  373. other->usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
  374. other->format = uint32_t(outBuffer.format);
  375. other->bits = outBuffer.bits;
  376. }
  377. if (inOutDirtyRegion) {
  378. inOutDirtyRegion->set( static_cast<Rect const&>(temp) );
  379. }
  380. return err;
  381. }
  382. </pre>
  383. <p><br>
  384. 也行你会说,怎么这个lock有两个参数的,明显不对吗,好吧,看来我的C++还是有点基础的,后悔以前搞ACM的时候只是一个main函数到底,没有好好用C++来实现,要不然现在也肯定是个大牛了。看看这个 status_t    lock(SurfaceInfo* info, Region* dirty = NULL);明白了吧?使用了默认的参数,刚开始还以为这个lock是假的。哈哈接着,看到了SurfaceTextureClient::lock(&outBuffer, inOutDirtyBounds);了吧,好明显的说,接着看看这个函数到底干了什么了</p>
  385. <pre class="html" name="code">status_t SurfaceTextureClient::lock(
  386. ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds)
  387. {
  388. if (mLockedBuffer != 0) {
  389. LOGE("Surface::lock failed, already locked");
  390. return INVALID_OPERATION;
  391. }
  392. if (!mConnectedToCpu) {
  393. int err = SurfaceTextureClient::connect(NATIVE_WINDOW_API_CPU);
  394. if (err) {
  395. return err;
  396. }
  397. // we're intending to do software rendering from this point
  398. setUsage(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
  399. }
  400. ANativeWindowBuffer* out;
  401. status_t err = dequeueBuffer(&out);
  402. LOGE_IF(err, "dequeueBuffer failed (%s)", strerror(-err));
  403. if (err == NO_ERROR) {
  404. sp<GraphicBuffer> backBuffer(GraphicBuffer::getSelf(out));
  405. err = lockBuffer(backBuffer.get());
  406. LOGE_IF(err, "lockBuffer (handle=%p) failed (%s)",
  407. backBuffer->handle, strerror(-err));
  408. if (err == NO_ERROR) {
  409. const Rect bounds(backBuffer->width, backBuffer->height);
  410. Region newDirtyRegion;
  411. if (inOutDirtyBounds) {
  412. newDirtyRegion.set(static_cast<Rect const&>(*inOutDirtyBounds));
  413. newDirtyRegion.andSelf(bounds);
  414. } else {
  415. newDirtyRegion.set(bounds);
  416. }
  417. // figure out if we can copy the frontbuffer back
  418. const sp<GraphicBuffer>& frontBuffer(mPostedBuffer);
  419. const bool canCopyBack = (frontBuffer != 0 &&
  420. backBuffer->width  == frontBuffer->width &&
  421. backBuffer->height == frontBuffer->height &&
  422. backBuffer->format == frontBuffer->format);
  423. if (canCopyBack) {
  424. // copy the area that is invalid and not repainted this round
  425. const Region copyback(mOldDirtyRegion.subtract(newDirtyRegion));
  426. if (!copyback.isEmpty())
  427. copyBlt(backBuffer, frontBuffer, copyback);
  428. } else {
  429. // if we can't copy-back anything, modify the user's dirty
  430. // region to make sure they redraw the whole buffer
  431. newDirtyRegion.set(bounds);
  432. }
  433. // keep track of the are of the buffer that is "clean"
  434. // (ie: that will be redrawn)
  435. mOldDirtyRegion = newDirtyRegion;
  436. if (inOutDirtyBounds) {
  437. *inOutDirtyBounds = newDirtyRegion.getBounds();
  438. }
  439. void* vaddr;
  440. status_t res = backBuffer->lock(
  441. GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
  442. newDirtyRegion.bounds(), &vaddr);
  443. LOGW_IF(res, "failed locking buffer (handle = %p)",
  444. backBuffer->handle);
  445. mLockedBuffer = backBuffer;
  446. outBuffer->width  = backBuffer->width;
  447. outBuffer->height = backBuffer->height;
  448. outBuffer->stride = backBuffer->stride;
  449. outBuffer->format = backBuffer->format;
  450. outBuffer->bits   = vaddr;
  451. }
  452. }
  453. return err;
  454. }
  455. </pre>
  456. <p><br>
  457. 好了,找到了 ANativeWindowBuffer* out;   status_t err = dequeueBuffer(&out);差不多告一段落了,代码看着头晕,还是分析不大来额。菜鸟有待提高,打好基础,慢慢</p>
  458. <p>地分析。</p>
  459. <pre class="html" name="code">int SurfaceTextureClient::dequeueBuffer(android_native_buffer_t** buffer) {
  460. LOGV("SurfaceTextureClient::dequeueBuffer");
  461. Mutex::Autolock lock(mMutex);
  462. int buf = -1;
  463. status_t result = mSurfaceTexture->dequeueBuffer(&buf, mReqWidth, mReqHeight,
  464. mReqFormat, mReqUsage);
  465. if (result < 0) {
  466. LOGV("dequeueBuffer: ISurfaceTexture::dequeueBuffer(%d, %d, %d, %d)"
  467. "failed: %d", mReqWidth, mReqHeight, mReqFormat, mReqUsage,
  468. result);
  469. return result;
  470. }
  471. sp<GraphicBuffer>& gbuf(mSlots[buf]);
  472. if (result & ISurfaceTexture::RELEASE_ALL_BUFFERS) {
  473. freeAllBuffers();
  474. }
  475. if ((result & ISurfaceTexture::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) {
  476. result = mSurfaceTexture->requestBuffer(buf, &gbuf);
  477. if (result != NO_ERROR) {
  478. LOGE("dequeueBuffer: ISurfaceTexture::requestBuffer failed: %d",
  479. result);
  480. return result;
  481. }
  482. }
  483. *buffer = gbuf.get();
  484. return OK;
  485. }
  486. </pre>
  487. <p><br>
  488. 由于对surface很多的概念还不是很清楚,分析代码也有点难度。只能拿出来,慢慢啃了。快要下班了,就这么着吧。android的图形显示系统好复杂好复杂啊,看得我头都大</p>
  489. <p>了。不过结合板子和代码慢慢调试倒是可以理解得很好。不错。还有就是代码中的英文得好好啃,看来单词还得好好记啊。<br>
  490. </p>
  491. <pre></pre>
  492. <pre></pre>

android4.0.3源码之鼠标光标绘制简略版相关推荐

  1. Ubuntu12.04编译Android4.0.1源码全过程-----附wubi安装ubuntu编译android源码硬盘空间不够的问题解决

    Ubuntu12.04编译Android4.0.1源码全过程-----附wubi安装ubuntu编译android源码硬盘空间不够的问题解决 参考文章: (1)Ubuntu12.04编译Android ...

  2. android4.0.3源码之硬件gps简单移植

    [转]我和菜鸟一起学android4.0.3源码之硬件gps简单移植 2013-7-5阅读94 评论0 关于android定位方式 android 定位一般有四种方法,这四种方式分别是GPS定位.WI ...

  3. Ubuntu12.04下Android4.0.4源码的下载及其编译过程

    Ubuntu12.04下Android4.0.4源码的下载及其编译过程 http://www.jizhuomi.com/android/environment/427.html

  4. 带视频教程|2.0升级版源码价值18500元的商业版游戏陪玩语音聊天系统源码

    陪玩2.0升级版源码 价值18500元的最新商业版游戏陪玩语音聊天系统源码此次更新在原有版本上传再次升级,修复部分逻辑以及bug,带详细安装教程,小白都可以从0安装起来修复bug:店员拒单后,退款会退 ...

  5. Ubuntu11.10下载android4.0.1源码

    好记不如料笔头,学习新奇的东东就是要多记一下,今天用虚拟机安装了一个Ubunut11.10的系统. 目的就是为了深入android底层方向研究,顺便做一下笔记 目前使用的是XP系统内安装VM8+Ubu ...

  6. Ubuntu12.04下在Android4.0.4源码下载及其编译过程(转载)

    一.下载源码 1.下载工具repo:https://android.googlesource.com/tools/repo/ 在本地目录建个bin的文件夹,进入bin文件夹:通过git下载: [cpp ...

  7. [2013.7.5新鲜出炉] Ubuntu12.04下载Android4.0.1源码全过程----------------折腾两天,终于下好,附若干问题解决

    杂家算后知后觉了,学校里一直在做应用层开发,考虑到日后就业问题,这次决定研究源码和驱动,并进行编译.没想到就下载源码这一步折腾了我整整两天,期间遇到很多问题,哎,记录于此,希望日后再下源码的人不要再走 ...

  8. 2013 7 5新鲜出炉 Ubuntu12 04下载Android4 0 1源码全过程---------------

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 杂家算后 ...

  9. Ubuntu下android-4.0.3_r1源码下载,阅读工具安装配置,源码编译详解

    备注: android源码动辄6.7G,新版本的则10G左右,所以要有足够大的硬盘空间. android应用开发环境搭建:http://www.cnblogs.com/pharen/archive/2 ...

最新文章

  1. win7变成xp风格了怎么改回_揭秘:干掉了win7!为何win10屡被吐槽它却“永世留芳”?...
  2. ICRA 2020 | 实时语义立体匹配
  3. 殇-至吾爱 ---经典
  4. cuda nvcc版本不一致_入坑第一步:Win10安装cuda+cuDNN+TensorFlow-GPU走过的那些路
  5. OpenGL GLSL Shader Subroutines函数的实例
  6. docker run命令_CVE-2019-14271:Docker cp命令漏洞分析
  7. CSDN2019博客之星评选——期待各位大佬的投票!
  8. 为什么不能把CSS放到html中,为什么我的CSS代码不能在我的HTML文件中工作?
  9. jenkins X 和k8s CI/CD
  10. 网络存储SAN网络存储术语解释
  11. 头条 msra几道面试题
  12. CMKY与RGB的转换
  13. 虚幻4皮肤材质_虚幻4果真被玩坏了?浅谈光影与材质带来的极致体验
  14. Aho-Corasick Automaton · AC自动机
  15. 计算机操作系统 第三章:处理机调度与死锁(2)
  16. 不是抽象的, 并且未覆盖Handler中的抽象方法
  17. win10桌面记事本便签有哪款
  18. 基于内存取证进行stuxnet 病毒分析(上)
  19. js编程常见错误:Uncaught TypeError: XXX is not a function解决
  20. Cisco Smart Install远程命令执行漏洞

热门文章

  1. 盘点:崛起中的九大HTML5开发工具
  2. vb6中word编程总结
  3. RAC分解步骤之一,在oracle linux 4u4上安装oracle 10.2.0.1.0操作日志
  4. Oracle show 命令学习
  5. MFC CString转换为字符数组
  6. VC++更改鼠标指针为系统预定义形状和自定义形状
  7. Understand分析Kinect SDK 1.7自带例子(C++)图集一
  8. Linux 应用编程
  9. 图解Windows下开发Objective-C程序之二 - Objective-C入门例子
  10. 开箱即用的VScode C++环境