Introduce AutoBackendTexture into Skia-RenderEngine

Conceptually this is the same class as AutoBackendTextureRelease in
libhwui. We require this because:
* As with the equivalent class in libhwui, buffers are reused and
therefore their content is mutable, but SkImages are defined to be
immutable, so the workaround is to cache the backing texture instead.
* Color spaces associated with a buffer are not guaranteed to be
constant. The HWC is allowed to request a different color space for the
client target depending on the set of input layers. This means that
SkSurfaces need to be recreated when the color space changes.
Furthermore, since LinearEffects performs tone-mapping and wants
to sidestep Skia's built-in tone mapping process, this means that when
tone-mapping is enabled we lie about the color space of the input
buffers so that we don't do multiple tone-mapping passes. But this means
that SkImages need to be recreated for those scenarios too so that the
input content can be reinterpreted with a different color space.

Also, append additional trace points onto this CL to get a better handle
on RenderEngine perf.

Bug: 164223050
Test: On a Pixel 3, play HDR content on Youtube with PQ and HLG transfer
functions, and toggle full-screen GL composition on and off.

Change-Id: Ic53a422545b4fb563c7e75c73d978350d38181d5
diff --git a/libs/renderengine/skia/SkiaGLRenderEngine.h b/libs/renderengine/skia/SkiaGLRenderEngine.h
index 965cb41..59ab3b2 100644
--- a/libs/renderengine/skia/SkiaGLRenderEngine.h
+++ b/libs/renderengine/skia/SkiaGLRenderEngine.h
@@ -29,8 +29,11 @@
 #include <mutex>
 #include <unordered_map>
 
+#include "AutoBackendTexture.h"
 #include "EGL/egl.h"
+#include "SkImageInfo.h"
 #include "SkiaRenderEngine.h"
+#include "android-base/macros.h"
 #include "filters/BlurFilter.h"
 
 namespace android {
@@ -92,8 +95,11 @@
 
     const bool mUseColorManagement;
 
-    // Cache of GL images that we'll store per GraphicBuffer ID
-    std::unordered_map<uint64_t, sk_sp<SkImage>> mImageCache GUARDED_BY(mRenderingMutex);
+    // Cache of GL textures that we'll store per GraphicBuffer ID
+    std::unordered_map<uint64_t, std::shared_ptr<AutoBackendTexture::LocalRef>> mTextureCache
+            GUARDED_BY(mRenderingMutex);
+    std::unordered_map<uint64_t, std::shared_ptr<AutoBackendTexture::LocalRef>>
+            mProtectedTextureCache GUARDED_BY(mRenderingMutex);
     // Mutex guarding rendering operations, so that:
     // 1. GL operations aren't interleaved, and
     // 2. Internal state related to rendering that is potentially modified by
@@ -107,8 +113,6 @@
     // Same as above, but for protected content (eg. DRM)
     sk_sp<GrDirectContext> mProtectedGrContext;
 
-    std::unordered_map<uint64_t, sk_sp<SkSurface>> mSurfaceCache;
-    std::unordered_map<uint64_t, sk_sp<SkSurface>> mProtectedSurfaceCache;
     bool mInProtectedContext = false;
 };