のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

opengl cache

    268 void Caches::flush(FlushMode mode) {
    269     FLUSH_LOGD("Flushing caches (mode %d)", mode);
    270 
    271     switch (mode) {
    272         case kFlushMode_Full:
    273             textureCache.clear();
    274             patchCache.clear();
    275             dropShadowCache.clear();
    276             gradientCache.clear();
    277             fontRenderer->clear();
    278             dither.clear();
    279             // fall through
    280         case kFlushMode_Moderate:
    281             fontRenderer->flush();
    282             textureCache.flush();
    283             pathCache.clear();
    284             roundRectShapeCache.clear();
    285             circleShapeCache.clear();
    286             ovalShapeCache.clear();
    287             rectShapeCache.clear();
    288             arcShapeCache.clear();
    289             // fall through
    290         case kFlushMode_Layers:
    291             layerCache.clear();
    292             break;
    293     }
    294 
    295     clearGarbage();
    296 }

FlushModeを使用しているところは、どこかな?

    304     /**
    305      * Must match Caches::FlushMode values
    308      */
    309     public static final int FLUSH_CACHES_LAYERS = 0;
    316     public static final int FLUSH_CACHES_MODERATE = 1;
    323     public static final int FLUSH_CACHES_FULL = 2;
    324 
    325     /**
    326      * Flush caches to reclaim as much memory as possible. The amount of memory
    327      * to reclaim is indicate by the level parameter.
    334      * @hide
    335      */
    336     public static void flushCaches(int level) {
    337         nFlushCaches(level);
    338     }
    339 
    340     private static native void nFlushCaches(int level);

Native(C++)での宣言

     94 static void android_view_GLES20Canvas_flushCaches(JNIEnv* env, jobject clazz,
     95         Caches::FlushMode mode) {
     96     if (Caches::hasInstance()) {
     97         Caches::getInstance().flush(mode);
     98     }
     99 }
    100 
    101 static void android_view_GLES20Canvas_initCaches(JNIEnv* env, jobject clazz) {
    102     if (Caches::hasInstance()) {
    103         Caches::getInstance().init();
    104     }
    105 }
    106 
    107 static void android_view_GLES20Canvas_terminateCaches(JNIEnv* env, jobject clazz) {
    108     if (Caches::hasInstance()) {
    109         Caches::getInstance().terminate();
    110     }
    111 }

    908     { "nFlushCaches",       "(I)V",            (void*) android_view_GLES20Canvas_flushCaches },
    909     { "nInitCaches",        "()V",             (void*) android_view_GLES20Canvas_initCaches },
    910     { "nTerminateCaches",   "()V",             (void*) android_view_GLES20Canvas_terminateCaches },


FLUSH_CACHES_FULLを使用しているところ

   1617         static void startTrimMemory(int level) {
   1618             if (sEgl == null || sEglConfig == null) return;
   1619 
   1620             Gl20RendererEglContext managedContext =
   1621                     (Gl20RendererEglContext) sEglContextStorage.get();
   1622             // We do not have OpenGL objects
   1623             if (managedContext == null) {
   1624                 return;
   1625             } else {
   1626                 usePbufferSurface(managedContext.getContext());
   1627             }
   1628 
   1629             if (level >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE) { <== 80
   1630                 GLES20Canvas.flushCaches(GLES20Canvas.FLUSH_CACHES_FULL);
   1631             } else if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) { <==20
   1632                 GLES20Canvas.flushCaches(GLES20Canvas.FLUSH_CACHES_MODERATE);
   1633             }
   1634         }
     23 public interface ComponentCallbacks2 extends ComponentCallbacks {
     30     static final int TRIM_MEMORY_COMPLETE         = 80;
     37     static final int TRIM_MEMORY_MODERATE         = 60;
     44     static final int TRIM_MEMORY_BACKGROUND       = 40;
     52     static final int TRIM_MEMORY_UI_HIDDEN        = 20;
     64     static final int TRIM_MEMORY_RUNNING_CRITICAL = 15;
     72     static final int TRIM_MEMORY_RUNNING_LOW      = 10;
     81     static final int TRIM_MEMORY_RUNNING_MODERATE =  5;
    103     void onTrimMemory(int level);
    104 }


startTrimMemoryを使っているところ。その1(handleTrimMemory)

   4099     final void handleTrimMemory(int level) {
   4100         if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level);
   4101 
   4102         final WindowManagerGlobal windowManager = WindowManagerGlobal.getInstance();
   4103         windowManager.startTrimMemory(level); <===
   4104 
   4105         ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null);
   4106 
   4107         final int N = callbacks.size();
   4108         for (int i = 0; i < N; i++) {
   4109             callbacks.get(i).onTrimMemory(level);
   4110         }
   4111 
   4112         windowManager.endTrimMemory();
   4113     }
   1225         public void handleMessage(Message msg) {
   1226             if (DEBUG_MESSAGES) Slog.v(TAG, ">>> handling: " + codeToString(msg.what));
   1227             switch (msg.what) {
   1424                 case TRIM_MEMORY:
   1425                     Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory");
   1426                     handleTrimMemory(msg.arg1); <==メッセージの値による
   1427                     Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
   1428                     break;
   1432             }
   1433             if (DEBUG_MESSAGES) Slog.v(TAG, "<<< done: " + codeToString(msg.what));
   1434         }


startTrimMemoryを使っているところ。その2(trimMemory)

    552     static void trimMemory(int level) {
    553         startTrimMemory(level);
    554         endTrimMemory();
    555     }
    648     void destroyHardwareLayers() {
    649         if (mThread != Thread.currentThread()) {
    650             if (mAttachInfo.mHardwareRenderer != null &&
    651                     mAttachInfo.mHardwareRenderer.isEnabled()) {
    652                 HardwareRenderer.trimMemory(ComponentCallbacks2.TRIM_MEMORY_MODERATE); <===60固定
    653             }
    654         } else {
    655             if (mAttachInfo.mHardwareRenderer != null &&
    656                     mAttachInfo.mHardwareRenderer.isEnabled()) {
    657                 mAttachInfo.mHardwareRenderer.destroyLayers(mView);
    658             }
    659         }
    660     }