公司经常组织一些培训,培训的都是些奇技淫巧。什么设计模式啦,开发策略啦,git啦,repo啦,另外就是培训一些开发流程的东东,例如CMMI啦。可是,却忘记了,程序员终究要归结到三个问题上:
1.解决什么问题?
2.为什么这样解决问题?
3.有没有更好的解决方案?
这些东东才是最核心的东东。但是却是一个程序员一辈子都无法完全掌握的东西。很多人以为写出了高难度的反射代码就是很牛,也有人认为利用C++模板来进行编程就多牛多牛,还有人觉得会写makefile文件,掌握了某种高难度语言很牛。但是我认为这些都不重要,重要的是要有思想。思考者比行动者在关键时候定大局。中国人的技术书籍缺乏的就是思想。在中国,可以肯定,没有几个人能写出像thinking in java这样的鸿篇巨著,更没有人能够超越 design pattern,来描述其思想。反之,像《自己动手写操作系统》,《21天学java》,《程序员的自我修养》,《面试宝典》,《C++面试一百例》, android内核开发要点等等等等一系列的书籍在中国却是层出不穷。为什么,因为缺乏思考,来不及思考,更或者懒得思考。然而,作为一名专业级的程序员,不思考就意味着退步,不学习就意味着淘汰。
这几天一直在思考ANativeWindow是个什么东西,今天终于找到了,代码贴出来,大家参考一下。
struct ANativeWindow { #ifdef __cplusplus ANativeWindow() : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0) { common.magic = ANDROID_NATIVE_WINDOW_MAGIC; common.version = sizeof(ANativeWindow); memset(common.reserved, 0, sizeof(common.reserved)); } /* Implement the methods that sp<ANativeWindow> expects so that it can be used to automatically refcount ANativeWindow's. */ void incStrong(const void* id) const { common.incRef(const_cast<android_native_base_t*>(&common)); } void decStrong(const void* id) const { common.decRef(const_cast<android_native_base_t*>(&common)); } #endif struct android_native_base_t common; /* flags describing some attributes of this surface or its updater */ const uint32_t flags; /* min swap interval supported by this updated */ const int minSwapInterval; /* max swap interval supported by this updated */ const int maxSwapInterval; /* horizontal and vertical resolution in DPI */ const float xdpi; const float ydpi; /* Some storage reserved for the OEM's driver. */ intptr_t oem[4]; /* * Set the swap interval for this surface. * * Returns 0 on success or -errno on error. */ int (*setSwapInterval)(struct ANativeWindow* window, int interval); /* * Hook called by EGL to acquire a buffer. After this call, the buffer * is not locked, so its content cannot be modified. This call may block if * no buffers are available. * * The window holds a reference to the buffer between dequeueBuffer and * either queueBuffer or cancelBuffer, so clients only need their own * reference if they might use the buffer after queueing or canceling it. * Holding a reference to a buffer after queueing or canceling it is only * allowed if a specific buffer count has been set. * * Returns 0 on success or -errno on error. */ int (*dequeueBuffer)(struct ANativeWindow* window, struct ANativeWindowBuffer** buffer); /* * hook called by EGL to lock a buffer. This MUST be called before modifying * the content of a buffer. The buffer must have been acquired with * dequeueBuffer first. * * Returns 0 on success or -errno on error. */ int (*lockBuffer)(struct ANativeWindow* window, struct ANativeWindowBuffer* buffer); /* * Hook called by EGL when modifications to the render buffer are done. * This unlocks and post the buffer. * * The window holds a reference to the buffer between dequeueBuffer and * either queueBuffer or cancelBuffer, so clients only need their own * reference if they might use the buffer after queueing or canceling it. * Holding a reference to a buffer after queueing or canceling it is only * allowed if a specific buffer count has been set. * * Buffers MUST be queued in the same order than they were dequeued. * * Returns 0 on success or -errno on error. */ int (*queueBuffer)(struct ANativeWindow* window, struct ANativeWindowBuffer* buffer); /* * hook used to retrieve information about the native window. * * Returns 0 on success or -errno on error. */ int (*query)(const struct ANativeWindow* window, int what, int* value); /* * hook used to perform various operations on the surface. * (*perform)() is a generic mechanism to add functionality to * ANativeWindow while keeping backward binary compatibility. * * DO NOT CALL THIS HOOK DIRECTLY. Instead, use the helper functions * defined below. * * (*perform)() returns -ENOENT if the 'what' parameter is not supported * by the surface's implementation. * * The valid operations are: * NATIVE_WINDOW_SET_USAGE * NATIVE_WINDOW_CONNECT (deprecated) * NATIVE_WINDOW_DISCONNECT (deprecated) * NATIVE_WINDOW_SET_CROP * NATIVE_WINDOW_SET_BUFFER_COUNT * NATIVE_WINDOW_SET_BUFFERS_GEOMETRY (deprecated) * NATIVE_WINDOW_SET_BUFFERS_TRANSFORM * NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP * NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS * NATIVE_WINDOW_SET_BUFFERS_FORMAT * NATIVE_WINDOW_SET_SCALING_MODE * NATIVE_WINDOW_LOCK (private) * NATIVE_WINDOW_UNLOCK_AND_POST (private) * NATIVE_WINDOW_API_CONNECT (private) * NATIVE_WINDOW_API_DISCONNECT (private) * */ int (*perform)(struct ANativeWindow* window, int operation, ... ); /* * Hook used to cancel a buffer that has been dequeued. * No synchronization is performed between dequeue() and cancel(), so * either external synchronization is needed, or these functions must be * called from the same thread. * * The window holds a reference to the buffer between dequeueBuffer and * either queueBuffer or cancelBuffer, so clients only need their own * reference if they might use the buffer after queueing or canceling it. * Holding a reference to a buffer after queueing or canceling it is only * allowed if a specific buffer count has been set. */ int (*cancelBuffer)(struct ANativeWindow* window, struct ANativeWindowBuffer* buffer); void* reserved_proc[2]; };