ANativeWindow是個什么東西


    公司經常組織一些培訓,培訓的都是些奇技淫巧。什么設計模式啦,開發策略啦,git啦,repo啦,另外就是培訓一些開發流程的東東,例如CMMI啦。可是,卻忘記了,程序員終究要歸結到三個問題上:

    1.解決什么問題?

    2.為什么這樣解決問題?

    3.有沒有更好的解決方案?

    這些東東才是最核心的東東。但是卻是一個程序員一輩子都無法完全掌握的東西。很多人以為寫出了高難度的反射代碼就是很牛,也有人認為利用C++模板來進行編程就多牛多牛,還有人覺得會寫makefile文件,掌握了某種高難度語言很牛。但是我認為這些都不重要,重要的是要有思想。思考者比行動者在關鍵時候定大局。中國人的技術書籍缺乏的就是思想。在中國,可以肯定,沒有幾個人能寫出像thinking in java這樣的鴻篇巨著,更沒有人能夠超越 design pattern,來描述其思想。反之,像《自己動手寫操作系統》,《21天學java》,《程序員的自我修養》,《面試寶典》,《C++面試一百例》, android內核開發要點等等等等一系列的書籍在中國卻是層出不窮。為什么,因為缺乏思考,來不及思考,更或者懶得思考。然而,作為一名專業級的程序員,不思考就意味着退步,不學習就意味着淘汰。

   這幾天一直在思考ANativeWindow是個什么東西,今天終於找到了,代碼貼出來,大家參考一下。

  

Cpp代碼    收藏代碼
  1. struct ANativeWindow  
  2. {  
  3. #ifdef __cplusplus  
  4.     ANativeWindow()  
  5.         : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)  
  6.     {  
  7.         common.magic = ANDROID_NATIVE_WINDOW_MAGIC;  
  8.         common.version = sizeof(ANativeWindow);  
  9.         memset(common.reserved, 0, sizeof(common.reserved));  
  10.     }  
  11.   
  12.     /* Implement the methods that sp<ANativeWindow> expects so that it 
  13.        can be used to automatically refcount ANativeWindow's. */  
  14.     void incStrong(const void* id) const {  
  15.         common.incRef(const_cast<android_native_base_t*>(&common));  
  16.     }  
  17.     void decStrong(const void* id) const {  
  18.         common.decRef(const_cast<android_native_base_t*>(&common));  
  19.     }  
  20. #endif  
  21.   
  22.     struct android_native_base_t common;  
  23.   
  24.     /* flags describing some attributes of this surface or its updater */  
  25.     const uint32_t flags;  
  26.   
  27.     /* min swap interval supported by this updated */  
  28.     const int   minSwapInterval;  
  29.   
  30.     /* max swap interval supported by this updated */  
  31.     const int   maxSwapInterval;  
  32.   
  33.     /* horizontal and vertical resolution in DPI */  
  34.     const float xdpi;  
  35.     const float ydpi;  
  36.   
  37.     /* Some storage reserved for the OEM's driver. */  
  38.     intptr_t    oem[4];  
  39.   
  40.     /* 
  41.      * Set the swap interval for this surface. 
  42.      * 
  43.      * Returns 0 on success or -errno on error. 
  44.      */  
  45.     int     (*setSwapInterval)(struct ANativeWindow* window,  
  46.                 int interval);  
  47.   
  48.     /* 
  49.      * Hook called by EGL to acquire a buffer. After this call, the buffer 
  50.      * is not locked, so its content cannot be modified. This call may block if 
  51.      * no buffers are available. 
  52.      * 
  53.      * The window holds a reference to the buffer between dequeueBuffer and 
  54.      * either queueBuffer or cancelBuffer, so clients only need their own 
  55.      * reference if they might use the buffer after queueing or canceling it. 
  56.      * Holding a reference to a buffer after queueing or canceling it is only 
  57.      * allowed if a specific buffer count has been set. 
  58.      * 
  59.      * Returns 0 on success or -errno on error. 
  60.      */  
  61.     int     (*dequeueBuffer)(struct ANativeWindow* window,  
  62.                 struct ANativeWindowBuffer** buffer);  
  63.   
  64.     /* 
  65.      * hook called by EGL to lock a buffer. This MUST be called before modifying 
  66.      * the content of a buffer. The buffer must have been acquired with 
  67.      * dequeueBuffer first. 
  68.      * 
  69.      * Returns 0 on success or -errno on error. 
  70.      */  
  71.     int     (*lockBuffer)(struct ANativeWindow* window,  
  72.                 struct ANativeWindowBuffer* buffer);  
  73.     /* 
  74.      * Hook called by EGL when modifications to the render buffer are done. 
  75.      * This unlocks and post the buffer. 
  76.      * 
  77.      * The window holds a reference to the buffer between dequeueBuffer and 
  78.      * either queueBuffer or cancelBuffer, so clients only need their own 
  79.      * reference if they might use the buffer after queueing or canceling it. 
  80.      * Holding a reference to a buffer after queueing or canceling it is only 
  81.      * allowed if a specific buffer count has been set. 
  82.      * 
  83.      * Buffers MUST be queued in the same order than they were dequeued. 
  84.      * 
  85.      * Returns 0 on success or -errno on error. 
  86.      */  
  87.     int     (*queueBuffer)(struct ANativeWindow* window,  
  88.                 struct ANativeWindowBuffer* buffer);  
  89.   
  90.     /* 
  91.      * hook used to retrieve information about the native window. 
  92.      * 
  93.      * Returns 0 on success or -errno on error. 
  94.      */  
  95.     int     (*query)(const struct ANativeWindow* window,  
  96.                 int what, int* value);  
  97.   
  98.     /* 
  99.      * hook used to perform various operations on the surface. 
  100.      * (*perform)() is a generic mechanism to add functionality to 
  101.      * ANativeWindow while keeping backward binary compatibility. 
  102.      * 
  103.      * DO NOT CALL THIS HOOK DIRECTLY.  Instead, use the helper functions 
  104.      * defined below. 
  105.      * 
  106.      *  (*perform)() returns -ENOENT if the 'what' parameter is not supported 
  107.      *  by the surface's implementation. 
  108.      * 
  109.      * The valid operations are: 
  110.      *     NATIVE_WINDOW_SET_USAGE 
  111.      *     NATIVE_WINDOW_CONNECT               (deprecated) 
  112.      *     NATIVE_WINDOW_DISCONNECT            (deprecated) 
  113.      *     NATIVE_WINDOW_SET_CROP 
  114.      *     NATIVE_WINDOW_SET_BUFFER_COUNT 
  115.      *     NATIVE_WINDOW_SET_BUFFERS_GEOMETRY  (deprecated) 
  116.      *     NATIVE_WINDOW_SET_BUFFERS_TRANSFORM 
  117.      *     NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP 
  118.      *     NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS 
  119.      *     NATIVE_WINDOW_SET_BUFFERS_FORMAT 
  120.      *     NATIVE_WINDOW_SET_SCALING_MODE 
  121.      *     NATIVE_WINDOW_LOCK                   (private) 
  122.      *     NATIVE_WINDOW_UNLOCK_AND_POST        (private) 
  123.      *     NATIVE_WINDOW_API_CONNECT            (private) 
  124.      *     NATIVE_WINDOW_API_DISCONNECT         (private) 
  125.      * 
  126.      */  
  127.   
  128.     int     (*perform)(struct ANativeWindow* window,  
  129.                 int operation, ... );  
  130.   
  131.     /* 
  132.      * Hook used to cancel a buffer that has been dequeued. 
  133.      * No synchronization is performed between dequeue() and cancel(), so 
  134.      * either external synchronization is needed, or these functions must be 
  135.      * called from the same thread. 
  136.      * 
  137.      * The window holds a reference to the buffer between dequeueBuffer and 
  138.      * either queueBuffer or cancelBuffer, so clients only need their own 
  139.      * reference if they might use the buffer after queueing or canceling it. 
  140.      * Holding a reference to a buffer after queueing or canceling it is only 
  141.      * allowed if a specific buffer count has been set. 
  142.      */  
  143.     int     (*cancelBuffer)(struct ANativeWindow* window,  
  144.                 struct ANativeWindowBuffer* buffer);  
  145.   
  146.   
  147.     void* reserved_proc[2];  
  148. };  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM