Firefly开源社区

打印 上一主题 下一主题

(Android5.1.1) 如何在开机动画时显示机器序列号

741

积分

68

威望

68

贡献

技术大神

Rank: 3Rank: 3

积分
741
QQ

(Android5.1.1) 如何在开机动画时显示机器序列号

发表于 2017-3-14 10:49:09      浏览:8612 | 回复:3        打印      只看该作者   [复制链接] 楼主
之前做过的一个功能,在开机动画时显示当前主机的序列号。有其他会动态更新或者要显示当前机器特有信息在开机动画需求时,也可以借鉴此补丁进行实现。

  1. external/skia/include/core/SkBitmap.h              |    2 +-
  2. frameworks/base/cmds/bootanimation/Android.mk      |    3 +-
  3. .../base/cmds/bootanimation/BootAnimation.cpp      |  164 +++++++++++++++++++-
  4. frameworks/base/cmds/bootanimation/BootAnimation.h |    7 +
  5. 4 files changed, 171 insertions(+), 5 deletions(-)

  6. diff --git a/external/skia/include/core/SkBitmap.h b/external/skia/include/core/SkBitmap.h
  7. index d3c33a8..a4a60c6 100644
  8. --- a/external/skia/include/core/SkBitmap.h
  9. +++ b/external/skia/include/core/SkBitmap.h
  10. @@ -13,7 +13,7 @@
  11. #include "SkImageInfo.h"
  12. #include "SkPoint.h"
  13. #include "SkRefCnt.h"
  14. -
  15. +#define SK_SUPPORT_LEGACY_SETCONFIG
  16. struct SkMask;
  17. struct SkIRect;
  18. struct SkRect;
  19. diff --git a/frameworks/base/cmds/bootanimation/Android.mk b/frameworks/base/cmds/bootanimation/Android.mk
  20. index 4a1a713..590a293 100644
  21. --- a/frameworks/base/cmds/bootanimation/Android.mk
  22. +++ b/frameworks/base/cmds/bootanimation/Android.mk
  23. @@ -8,7 +8,8 @@ LOCAL_SRC_FILES:= \

  24. LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES

  25. -LOCAL_C_INCLUDES += external/tinyalsa/include
  26. +LOCAL_C_INCLUDES += external/tinyalsa/include \
  27. +                        external/skia/include  

  28. LOCAL_SHARED_LIBRARIES := \
  29.         libcutils \
  30. diff --git a/frameworks/base/cmds/bootanimation/BootAnimation.cpp b/frameworks/base/cmds/bootanimation/BootAnimation.cpp
  31. index 0d6c78d..bb6a9c7 100644
  32. --- a/frameworks/base/cmds/bootanimation/BootAnimation.cpp
  33. +++ b/frameworks/base/cmds/bootanimation/BootAnimation.cpp
  34. @@ -79,6 +79,19 @@ namespace android {

  35. static const int ANIM_ENTRY_NAME_MAX = 256;

  36. +static const int SN_TEXT_SIZE = 30;
  37. +static const SkColor SN_TEXT_COLOR= 0xFFFFFFFF;
  38. +
  39. +#define EXPECT_NO_GL_ERROR(stmt)  \
  40. +  do {  \
  41. +    stmt;  \
  42. +    const EGLint error_code = eglGetError();  \
  43. +    if (EGL_SUCCESS != error_code){  \
  44. +        LOGD("GLTest: GL error code %d at %s:%d", error_code, __FILE__, __LINE__); \
  45. +        __android_log_assert("GLTest", "GLtest", "GlTest"); \
  46. +    }\
  47. +  } while(0)
  48. +
  49. // ---------------------------------------------------------------------------

  50. BootAnimation::BootAnimation(bool shutdown) : Thread(false), mZip(NULL)
  51. @@ -214,12 +227,12 @@ status_t BootAnimation::initTexture(const Animation::Frame& frame)
  52. {
  53.      //StopWatch watch("blah");

  54. -    SkBitmap bitmap;
  55. +    SkBitmap bm;
  56.      SkMemoryStream  stream(frame.map->getDataPtr(), frame.map->getDataLength());
  57.      SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
  58.      if (codec) {
  59.          codec->setDitherImage(false);
  60. -        codec->decode(&stream, &bitmap,
  61. +        codec->decode(&stream, &bm,
  62.                  #ifdef USE_565
  63.                  kRGB_565_SkColorType,
  64.                  #else
  65. @@ -236,6 +249,24 @@ status_t BootAnimation::initTexture(const Animation::Frame& frame)

  66.      // ensure we can call getPixels(). No need to call unlock, since the
  67.      // bitmap will go out of scope when we return from this method.
  68. +    SkBitmap bitmap;
  69. +    bitmap.setConfig(SkBitmap::kARGB_8888_Config, bm.width(), bm.height());
  70. +    bitmap.allocPixels();
  71. +    SkGraphics::Init();
  72. +    SkCanvas canvas(bitmap);
  73. +    SkPaint textAttribs;
  74. +
  75. +    canvas.drawBitmap(bm, 0, 0,
  76. +               &textAttribs);
  77. +
  78. +    textAttribs.setColor(SN_TEXT_COLOR);
  79. +    textAttribs.setTextSize(SkIntToScalar(SN_TEXT_SIZE));
  80. +    char serialno[PROPERTY_VALUE_MAX];
  81. +    property_get("ro.serialno", serialno, "") ;
  82. +    canvas.drawText(serialno, strlen(serialno), SN_TEXT_SIZE/2, bm.height()-SN_TEXT_SIZE/2,
  83. +                textAttribs);
  84. +
  85. +
  86.      bitmap.lockPixels();

  87.      const int w = bitmap.width();
  88. @@ -497,6 +528,8 @@ bool BootAnimation::android()
  89. {
  90.      initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png"); // texture_object_mask
  91.      initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png");
  92. +    initSerialnoTexture(&serialnoTexture);
  93. +
  94.      mBMPWidth = mTexWidth = mBMPHeight = mTexHeight = 1;
  95.      getTexCoordinate();

  96. @@ -636,6 +669,11 @@ bool BootAnimation::android()
  97.                         GL_UNSIGNED_SHORT,   // type
  98.                         indices);            // indices

  99. +        glDisable(GL_SCISSOR_TEST);  
  100. +        glEnable (GL_BLEND);
  101. +        EXPECT_NO_GL_ERROR(glBindTexture(GL_TEXTURE_2D, serialnoTexture.name));
  102. +        EXPECT_NO_GL_ERROR(glDrawTexiOES(0, 0, 0, serialnoTexture.w, serialnoTexture.h));
  103. +
  104.          /*-----------------------------------*/

  105.          EGLBoolean res = eglSwapBuffers(mDisplay, mSurface);
  106. @@ -652,6 +690,7 @@ bool BootAnimation::android()

  107.      glDeleteTextures(1, &mAndroid[0].name);
  108.      glDeleteTextures(1, &mAndroid[1].name);
  109. +    glDeleteTextures(1, &serialnoTexture.name);
  110.      return false;
  111. }

  112. @@ -962,7 +1001,7 @@ bool BootAnimation::movie()
  113.                      } while (err<0 && errno == EINTR);
  114.                  }

  115. -                checkExit();
  116. +               checkExit();
  117.              }

  118.              usleep(part.pause * ns2us(frameDuration));
  119. @@ -983,7 +1022,126 @@ bool BootAnimation::movie()

  120.      return false;
  121. }
  122. +status_t BootAnimation::initSerialnoTexture(Texture* texture)
  123. +{
  124. +        glShadeModel (GL_FLAT);
  125. +    glDisable (GL_DITHER);
  126. +    glDisable (GL_SCISSOR_TEST);
  127. +    glClearColor(0, 1, 0, 1);
  128. +    glClear(GL_COLOR_BUFFER_BIT);
  129. +     SkGraphics::Init();
  130. +    SkBitmap bitmap;

  131. +     LOGD("initSerialnoTexture mWidth:%d,mHeight:%d",mWidth,mHeight);
  132. +    bitmap.setConfig(SkBitmap::kARGB_8888_Config, mWidth, mHeight);
  133. +    bitmap.allocPixels();
  134. +
  135. +    if(!initTexture(&(*texture), bitmap))
  136. +    {
  137. +        LOGD("GLTest: Unable to create a texture that is backed by SkBitmap");
  138. +        return false;
  139. +    }
  140. +
  141. +    SkCanvas canvas(bitmap);
  142. +    SkPaint textAttribs;
  143. +
  144. +    textAttribs.setColor(SN_TEXT_COLOR);
  145. +    textAttribs.setTextSize(SkIntToScalar(SN_TEXT_SIZE));
  146. +    char serialno[PROPERTY_VALUE_MAX];
  147. +    property_get("ro.serialno", serialno, "") ;
  148. +    canvas.drawText(serialno, strlen(serialno), SN_TEXT_SIZE/2, mHeight-SN_TEXT_SIZE/2,
  149. +                textAttribs);
  150. +
  151. +    return initTexture(&(*texture), bitmap);// Upload bitmap into canvas
  152. +   
  153. +}
  154. +
  155. +status_t BootAnimation::initTexture(Texture* texture, const SkBitmap &bitmap)
  156. +{
  157. +    bool result = true;
  158. +    SkAutoLockPixels alp(bitmap);
  159. +
  160. +    const int w = bitmap.width();
  161. +    const int h = bitmap.height();
  162. +    const void* p = bitmap.getPixels();
  163. +    int tw = 1 << (31 - __builtin_clz(w));
  164. +    int th = 1 << (31 - __builtin_clz(h));
  165. +    if (tw < w)
  166. +        tw <<= 1;
  167. +    if (th < h)
  168. +        th <<= 1;
  169. +
  170. +    if (NULL == texture)
  171. +      {LOGD("GNULL == texture");
  172. +        return false;
  173. +      }   
  174. +      LOGD("texture->name %d",texture->name);
  175. +    if (texture->name != 0)
  176. +    {
  177. +        glBindTexture(GL_TEXTURE_2D, texture->name);
  178. +        switch (bitmap.getConfig())
  179. +        {
  180. +        case SkBitmap::kA8_Config:
  181. +            glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_ALPHA, GL_UNSIGNED_BYTE, p);
  182. +            break;
  183. +        case SkBitmap::kARGB_4444_Config:
  184. +            glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, p);
  185. +            break;
  186. +        case SkBitmap::kARGB_8888_Config:
  187. +            glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p);
  188. +            break;
  189. +        case SkBitmap::kRGB_565_Config:
  190. +            glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p);
  191. +            break;
  192. +        default:
  193. +            break;
  194. +        }
  195. +    }
  196. +     LOGD("texture->w:%d,texture->h:%d",texture->w,texture->h);
  197. +    GLint crop[4] = { 0, h, w, -h };
  198. +    texture->w = w;
  199. +    texture->h = h;
  200. +
  201. +    glEnable (GL_TEXTURE_2D);
  202. +    glGenTextures(1, &(texture->name));
  203. +    glBindTexture(GL_TEXTURE_2D, texture->name);
  204. +
  205. +    switch (bitmap.getConfig())
  206. +    {
  207. +    case SkBitmap::kA8_Config:
  208. +        glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, p);
  209. +        break;
  210. +    case SkBitmap::kARGB_4444_Config:
  211. +        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, p);
  212. +        break;
  213. +    case SkBitmap::kARGB_8888_Config:
  214. +        if (tw != w || th != h)
  215. +        {
  216. +            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA,
  217. +                    GL_UNSIGNED_BYTE, 0);
  218. +            glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA,
  219. +                    GL_UNSIGNED_BYTE, p);
  220. +        }
  221. +        else
  222. +        {
  223. +            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, p);
  224. +        }
  225. +        break;
  226. +    case SkBitmap::kRGB_565_Config:
  227. +        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p);
  228. +        break;
  229. +    default:
  230. +        break;
  231. +    }
  232. +
  233. +    glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
  234. +    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  235. +    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  236. +    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  237. +    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  238. +    LOGD("result :%d",result);
  239. +    return result;
  240. +}
  241. /* ############################################################################################# */

  242. int64_t BootAnimation::getFileSize(int fd)
  243. diff --git a/frameworks/base/cmds/bootanimation/BootAnimation.h b/frameworks/base/cmds/bootanimation/BootAnimation.h
  244. index 5663dba..1a78d69 100644
  245. --- a/frameworks/base/cmds/bootanimation/BootAnimation.h
  246. +++ b/frameworks/base/cmds/bootanimation/BootAnimation.h
  247. @@ -26,6 +26,10 @@
  248. #include <EGL/egl.h>
  249. #include <GLES/gl.h>

  250. +#include "SkCanvas.h"
  251. +#include "SkGraphics.h"
  252. + #include "SkBitmap.h"
  253. +
  254. class SkBitmap;

  255. namespace android {
  256. @@ -84,6 +88,8 @@ private:

  257.      status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
  258.      status_t initTexture(const Animation::Frame& frame);
  259. +     status_t initTexture(Texture* texture, const SkBitmap &bitmap);
  260. +     status_t initSerialnoTexture(Texture* texture);
  261.      bool android();
  262.      bool readFile(const char* name, String8& outString);
  263.      bool movie();
  264. @@ -114,6 +120,7 @@ private:
  265.      int         mTexHeight;
  266.      int         mBMPWidth;
  267.      int         mBMPHeight;
  268. +    Texture     serialnoTexture;

  269.      template<class T>
  270.      void exchangeParameters(T* x, T* y) {
  271. --
  272. 1.7.9.5
复制代码



回复

使用道具 举报

620

积分

0

威望

0

贡献

技术大神

Rank: 3Rank: 3

积分
620
发表于 2017-3-14 11:33:51        只看该作者  沙发
标记一下,有空试下。全屏开机动画上显示会不会不好看?有没有拍个图看看效果。
回复

使用道具 举报

529

积分

0

威望

0

贡献

技术大神

Rank: 3Rank: 3

积分
529
发表于 2017-3-22 10:43:24        只看该作者  板凳
有意思, 待会儿试试
回复

使用道具 举报

312

积分

0

威望

0

贡献

技术达人

Rank: 2

积分
312
发表于 2017-3-23 19:05:11        只看该作者  地板
有点意思! 我明天试试
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

友情链接 : 爱板网 电子发烧友论坛 云汉电子社区 粤ICP备14022046号-2
快速回复 返回顶部 返回列表