Enable WebKit/Chromium style logging for Skia.
authortomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 30 Jun 2011 19:37:01 +0000 (19:37 +0000)
committertomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 30 Jun 2011 19:37:01 +0000 (19:37 +0000)
New macros called in Ganesh functions; by default are compiled away,
in example code resolve to printout, and are compatible with WebKit/Chromium
event logging and GPU profiler.

git-svn-id: http://skia.googlecode.com/svn/trunk@1770 2bbb7eff-a529-9590-31e7-b0007b416f81

gpu/src/GrContext.cpp
gpu/src/GrGLProgram.cpp
gpu/src/GrPathRenderer.cpp
gyp/core.gyp
include/config/SkUserConfig.h
include/config/SkUserTrace.h [new file with mode: 0644]
src/utils/SkDebugTrace.h [new file with mode: 0644]

index a2b2a1649763d6c806e7e0ab356fd08d90227e54..d97974a190df80cf8af0e62156ed9bc8cbb2dd00 100644 (file)
     limitations under the License.
  */
 
+#include "GrBufferAllocPool.h"
+#include "GrClipIterator.h"
 #include "GrContext.h"
 #include "GrGpu.h"
-#include "GrTextureCache.h"
-#include "GrTextStrike.h"
-#include "GrMemory.h"
-#include "GrClipIterator.h"
 #include "GrIndexBuffer.h"
 #include "GrInOrderDrawBuffer.h"
-#include "GrBufferAllocPool.h"
+#include "GrMemory.h"
 #include "GrPathRenderer.h"
 #include "GrPathUtils.h"
+#include "GrTextureCache.h"
+#include "GrTextStrike.h"
+#include SK_USER_TRACE_INCLUDE_FILE
 
 // Using MSAA seems to be slower for some yet unknown reason.
 #define PREFER_MSAA_OFFSCREEN_AA 0
@@ -203,6 +204,7 @@ GrTextureEntry* GrContext::createAndLockTexture(GrTextureKey* key,
                                                 const GrSamplerState& sampler,
                                                 const GrTextureDesc& desc,
                                                 void* srcData, size_t rowBytes) {
+    SK_TRACE_EVENT0("GrContext::createAndLockTexture");
     GrAssert(key->width() == desc.fWidth);
     GrAssert(key->height() == desc.fHeight);
 
@@ -712,7 +714,7 @@ void GrContext::doOffscreenAAPass2(GrDrawTarget* target,
                                  const GrIRect& boundRect,
                                  int tileX, int tileY,
                                  OffscreenRecord* record) {
-
+    SK_TRACE_EVENT0("GrContext::doOffscreenAAPass2");
     GrAssert(NULL != record->fEntry0);
     
     GrIRect tileRect;
@@ -928,7 +930,6 @@ GrIndexBuffer* GrContext::aaStrokeRectIndexBuffer() {
 void GrContext::fillAARect(GrDrawTarget* target,
                            const GrPaint& paint,
                            const GrRect& devRect) {
-
     GrVertexLayout layout = PaintStageVertexLayoutBits(paint, NULL) |
                             GrDrawTarget::kColor_VertexLayoutBit;
 
@@ -1084,7 +1085,7 @@ void GrContext::drawRect(const GrPaint& paint,
                          const GrRect& rect,
                          GrScalar width,
                          const GrMatrix* matrix) {
-
+    SK_TRACE_EVENT0("GrContext::drawRect");
 
     GrDrawTarget* target = this->prepareToDraw(paint, kUnbuffered_DrawCategory);
     int stageMask = paint.getActiveStageMask();
@@ -1190,6 +1191,7 @@ void GrContext::drawRectToRect(const GrPaint& paint,
                                const GrRect& srcRect,
                                const GrMatrix* dstMatrix,
                                const GrMatrix* srcMatrix) {
+    SK_TRACE_EVENT0("GrContext::drawRectToRect");
 
     // srcRect refers to paint's first texture
     if (NULL == paint.getTexture(0)) {
@@ -1258,6 +1260,7 @@ void GrContext::drawVertices(const GrPaint& paint,
                              const GrColor colors[],
                              const uint16_t indices[],
                              int indexCount) {
+    SK_TRACE_EVENT0("GrContext::drawVertices");
 
     GrDrawTarget::AutoReleaseGeometry geo;
 
@@ -1426,6 +1429,7 @@ void GrContext::flushDrawBuffer() {
 bool GrContext::readTexturePixels(GrTexture* texture,
                                   int left, int top, int width, int height,
                                   GrPixelConfig config, void* buffer) {
+    SK_TRACE_EVENT0("GrContext::readTexturePixels");
 
     // TODO: code read pixels for textures that aren't rendertargets
 
@@ -1443,6 +1447,7 @@ bool GrContext::readTexturePixels(GrTexture* texture,
 bool GrContext::readRenderTargetPixels(GrRenderTarget* target,
                                       int left, int top, int width, int height,
                                       GrPixelConfig config, void* buffer) {
+    SK_TRACE_EVENT0("GrContext::readRenderTargetPixels");
     uint32_t flushFlags = 0;
     if (NULL == target) { 
         flushFlags |= GrContext::kForceCurrentRenderTarget_FlushBit;
@@ -1457,6 +1462,7 @@ bool GrContext::readRenderTargetPixels(GrRenderTarget* target,
 void GrContext::writePixels(int left, int top, int width, int height,
                             GrPixelConfig config, const void* buffer,
                             size_t stride) {
+    SK_TRACE_EVENT0("GrContext::writePixels");
 
     // TODO: when underlying api has a direct way to do this we should use it
     // (e.g. glDrawPixels on desktop GL).
index b0d41aa9bd2b840264540bb9a1d0ad0854b8d5f5..319995c0bfefe47bb0af4219d6a5e17101631e6e 100644 (file)
@@ -21,6 +21,7 @@
 #include "GrMemory.h"
 
 #include "SkXfermode.h"
+#include SK_USER_TRACE_INCLUDE_FILE
 
 namespace {
 
@@ -758,6 +759,9 @@ GrGLuint GrGLProgram::CompileShader(GrGLenum type,
                                       int stringCnt,
                                       const char** strings,
                                       int* stringLengths) {
+    SK_TRACE_EVENT1("GrGLProgram::CompileShader",
+                    "stringCount", SkStringPrintf("%i", stringCnt).c_str());
+
     GrGLuint shader = GR_GL(CreateShader(type));
     if (0 == shader) {
         return 0;
index 1795bd4daecba9078fb2455baeb66b808ed40bb7..b565838e1594777a38ce06b8efd065ee8fcb75ef 100644 (file)
@@ -6,6 +6,9 @@
 #include "GrMemory.h"
 #include "GrTexture.h"
 
+#include "SkString.h"
+#include SK_USER_TRACE_INCLUDE_FILE
+
 GrPathRenderer::GrPathRenderer()
     : fCurveTolerance (GR_Scalar1) {
 
@@ -191,6 +194,8 @@ void GrDefaultPathRenderer::onDrawPath(GrDrawTarget* target,
                                        GrPathFill fill,
                                        const GrPoint* translate,
                                        bool stencilOnly) {
+    SK_TRACE_EVENT1("GrDefaultPathRenderer::onDrawPath",
+                    "points", SkStringPrintf("%i", path.countPoints()).c_str());
 
     GrDrawTarget::AutoStateRestore asr(target);
     bool colorWritesWereDisabled = target->isColorWriteDisabled();
@@ -334,7 +339,10 @@ void GrDefaultPathRenderer::onDrawPath(GrDrawTarget* target,
 
     SkPath::Iter iter(path, false);
 
+    {
+    SK_TRACE_EVENT0("GrDefaultPathRenderer::onDrawPath::assembleVerts");
     for (;;) {
+
         GrPathCmd cmd = (GrPathCmd)iter.next(pts);
         switch (cmd) {
             case kMove_PathCmd:
@@ -371,6 +379,7 @@ void GrDefaultPathRenderer::onDrawPath(GrDrawTarget* target,
         }
         first = false;
     }
+    }
 FINISHED:
     GrAssert(subpath == subpathCnt);
     GrAssert((vert - base) <= maxPts);
@@ -406,6 +415,9 @@ FINISHED:
                                   bounds.fBottom);
     }
 
+    {
+    SK_TRACE_EVENT1("GrDefaultPathRenderer::onDrawPath::renderPasses",
+                    "verts", SkStringPrintf("%i", vert - base).c_str());
     for (int p = 0; p < passCount; ++p) {
         target->setDrawFace(drawFace[p]);
         if (NULL != passes[p]) {
@@ -432,6 +444,7 @@ FINISHED:
             }
         }
     }
+    }
 }
 
 void GrDefaultPathRenderer::drawPath(GrDrawTarget* target,
index ee64446a2ce4c7fc5ba9183c1f65c1f95209170d..aa4877e9bec846302fa7e7795aa0e127d02f5a08 100644 (file)
         '../src/core/SkTypefaceCache.cpp',
         '../src/core/SkTypefaceCache.h',
         '../src/core/SkUnPreMultiply.cpp',
+        '../src/core/SkUserTrace.h',
         '../src/core/SkUtils.cpp',
         '../src/core/SkWriter32.cpp',
         '../src/core/SkXfermode.cpp',
         '../include/core/SkThread.h',
         '../include/core/SkThread_platform.h',
         '../include/core/SkTime.h',
+        '../include/core/SkTrace.h',
         '../include/core/SkTypeface.h',
         '../include/core/SkTypes.h',
         '../include/core/SkUnPreMultiply.h',
index 0e82133a9331b09a353ce8da1d344d00d6e629b1..6ee514646b2997cbe6306367b93cd920c53e8aa3 100644 (file)
 //#define SK_SUPPORT_UNITTEST
 #endif
 
+/* If your system embeds skia and has complex event logging, redefine this
+   symbol to point to a file that maps the following macros to your system's
+   equivalents:
+       SK_TRACE_EVENT0(event)
+       SK_TRACE_EVENT1(event, name1, value1)
+       SK_TRACE_EVENT2(event, name1, value1, name2, value2)
+   include/config/SkUserTrace.h has a no-op implementation, while
+   src/utils/SkDebugTrace.h has a trivial implementation that writes to
+   the debug output stream.
+*/
+#define SK_USER_TRACE_INCLUDE_FILE "../../include/config/SkUserTrace.h"
+
 /*  Change the ordering to work in X windows.
  */
 #ifdef SK_SAMPLES_FOR_X
diff --git a/include/config/SkUserTrace.h b/include/config/SkUserTrace.h
new file mode 100644 (file)
index 0000000..c5d168a
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+    Copyright 2010 Google Inc.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+ */
+#ifndef SkUserTrace_DEFINED
+#define SkUserTrace_DEFINED
+
+/* If your system embeds skia and has complex event logging, define these
+   to map to your system's equivalents. A trivial example is given in
+   src/utils/SkDebugTrace.h.
+
+   All arguments are const char*. Skia typically passes the name of
+   the object and function (and sometimes region of interest within
+   the function) separated by double colons for 'event'.
+
+   SK_TRACE_EVENT1 and SK_TRACE_EVENT2 take one or two arbitrary
+   name-value pairs that you also want to log. SkStringPrintf() is useful
+   for formatting these values.
+
+   For example:
+    SK_TRACE_EVENT0("GrContext::createAndLockTexture");
+    SK_TRACE_EVENT1("GrDefaultPathRenderer::onDrawPath::renderPasses",
+                    "verts", SkStringPrintf("%i", vert - base).c_str());
+*/
+#define SK_TRACE_EVENT0(event)
+#define SK_TRACE_EVENT1(event, name1, value1)
+#define SK_TRACE_EVENT2(event, name1, value1, name2, value2)
+
+#endif
+
+
diff --git a/src/utils/SkDebugTrace.h b/src/utils/SkDebugTrace.h
new file mode 100644 (file)
index 0000000..1f0c190
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+    Copyright 2011 Google Inc.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+ */
+#ifndef SkUserTrace_DEFINED
+#define SkUserTrace_DEFINED
+
+/* Sample implementation of SkUserTrace that routes all of the
+   trace macros to debug output stream.
+   To use this, redefine SK_USER_TRACE_INCLUDE_FILE in
+   include/config/SkUserConfig.h to point to this file
+*/
+#define SK_TRACE_EVENT0(event) \
+  SkDebugf("Trace: %s\n", event)
+#define SK_TRACE_EVENT1(event, name1, value1) \
+  SkDebugf("Trace: %s (%s=%s)\n", event, name1, value1)
+#define SK_TRACE_EVENT2(event, name1, value1, name2, value2) \
+  SkDebugf("Trace: %s (%s=%s, %s=%s)\n", event, name1, value1, name2, value2)
+
+#endif
+
+