Bug 1373177 - part2 : add log. draft
authorAlastor Wu <alwu@mozilla.com>
Fri, 30 Jun 2017 11:12:52 -0700
changeset 602753 7b8c05c390d9c7119519ec9dd019c89b0ea7844d
parent 602752 cb481aa4b73d119eea6ee80a93c289fa57a0a709
child 602754 5a8470e06dfd8b21fc0ac31425f5293042dcb4a6
push id66535
push useralwu@mozilla.com
push dateFri, 30 Jun 2017 18:13:19 +0000
bugs1373177
milestone56.0a1
Bug 1373177 - part2 : add log. Add lazy log for debugging. MozReview-Commit-ID: 4VYjLDobFeW
gfx/layers/opengl/TexturePoolOGL.cpp
--- a/gfx/layers/opengl/TexturePoolOGL.cpp
+++ b/gfx/layers/opengl/TexturePoolOGL.cpp
@@ -1,29 +1,33 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "TexturePoolOGL.h"
 #include <stdlib.h>                     // for malloc
 #include "GLContext.h"                  // for GLContext
+#include "mozilla/Logging.h"
 #include "mozilla/Monitor.h"            // for Monitor, MonitorAutoLock
 #include "mozilla/mozalloc.h"           // for operator delete, etc
 #include "mozilla/layers/CompositorThread.h"
 #include "nsDebug.h"                    // for NS_ASSERTION, NS_ERROR, etc
 #include "nsDeque.h"                    // for nsDeque
 #include "nsThreadUtils.h"
 
 #ifdef MOZ_WIDGET_ANDROID
 #include "GeneratedJNINatives.h"
 #endif
 
 static const unsigned int TEXTURE_POOL_SIZE = 10;
 static const unsigned int TEXTURE_REFILL_THRESHOLD = TEXTURE_POOL_SIZE / 2;
 
+static mozilla::LazyLogModule gTexturePoolLog("TexturePoolOGL");
+#define LOG(arg, ...) MOZ_LOG(gTexturePoolLog, mozilla::LogLevel::Debug, ("TexturePoolOGL::%s: " arg, __func__, ##__VA_ARGS__))
+
 namespace mozilla {
 namespace gl {
 
 static GLContext* sActiveContext = nullptr;
 
 static Monitor* sMonitor = nullptr;
 static nsDeque* sTextures = nullptr;
 
@@ -41,16 +45,17 @@ public:
 };
 
 #endif // MOZ_WIDGET_ANDROID
 
 void TexturePoolOGL::MaybeFillTextures()
 {
   if (sTextures->GetSize() < TEXTURE_REFILL_THRESHOLD &&
       !sHasPendingFillTask) {
+    LOG("need to refill the texture pool.");
     sHasPendingFillTask = true;
     MessageLoop* loop = mozilla::layers::CompositorThreadHolder::Loop();
     MOZ_ASSERT(loop);
     loop->PostTask(
       NS_NewRunnableFunction(
         "TexturePoolOGL::MaybeFillTextures",
         [] () {
           TexturePoolOGL::Fill(sActiveContext);
@@ -90,16 +95,17 @@ GLuint TexturePoolOGL::AcquireTexture()
     }
 
     texture = *popped;
     delete popped;
 
     NS_ASSERTION(texture, "Failed to retrieve texture from pool");
 
     MaybeFillTextures();
+    LOG("remaining textures num = %zu", sTextures->GetSize());
   }
 
   return texture;
 }
 
 static void Clear()
 {
   const bool isCurrent = sActiveContext && sActiveContext->MakeCurrent();
@@ -135,16 +141,17 @@ void TexturePoolOGL::Fill(GLContext* aCo
 
   GLuint* texture = nullptr;
   while (sTextures->GetSize() < TEXTURE_POOL_SIZE) {
     texture = (GLuint*)malloc(sizeof(GLuint));
     sActiveContext->fGenTextures(1, texture);
     sTextures->Push((void*) texture);
   }
 
+  LOG("fill texture pool to %d", TEXTURE_POOL_SIZE);
   sMonitor->NotifyAll();
 }
 
 GLContext* TexturePoolOGL::GetGLContext()
 {
   return sActiveContext;
 }