Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 70d15b1b authored by Ana Krulec's avatar Ana Krulec
Browse files

Adding Skia Recorder to Render Engine

To start recording run:
adb shell setprop debug.renderengine.capture_skia_ms 1000

File will be stored in the /data directory on the device:
adb shell ls -al /data/user/
adb pull /data/user/re_skiacapture_<timestamp>.mskp

The recording will stop after MS specified. To reset the
recording, set the capture_skia_ms flag to a new time.
When recording is finished, the capture_skia_ms flag will
be set to 0 to avoid circular recording.

Bug: 173805658
Test: Turn on the flag. Turn off the flag. Pull the file from
      the device. Open it in Skia Debugger.
Change-Id: Iea478245c267fb4b26f980417d96acd7273bfb55
parent 749ada98
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -81,6 +81,9 @@ filegroup {
        "skia/AutoBackendTexture.cpp",
        "skia/SkiaRenderEngine.cpp",
        "skia/SkiaGLRenderEngine.cpp",
        "skia/debug/CaptureTimer.cpp",
        "skia/debug/CommonPool.cpp",
        "skia/debug/SkiaCapture.cpp",
        "skia/filters/BlurFilter.cpp",
        "skia/filters/LinearEffect.cpp",
    ],
@@ -94,6 +97,7 @@ cc_library_static {
    cflags: [
        "-fvisibility=hidden",
        "-Werror=format",
        "-Wno-unused-parameter",
    ],
    srcs: [
        ":librenderengine_sources",
+8 −1
Original line number Diff line number Diff line
@@ -31,10 +31,17 @@
#include <ui/Transform.h>

/**
 * Allows to set RenderEngine backend to GLES (default) or Vulkan (NOT yet supported).
 * Allows to set RenderEngine backend to GLES (default) or SkiaGL (NOT yet supported).
 */
#define PROPERTY_DEBUG_RENDERENGINE_BACKEND "debug.renderengine.backend"

/**
 * Turns on recording of skia commands in SkiaGL version of the RE. This property
 * defines number of milliseconds for the recording to take place. A non zero value
 * turns on the recording.
 */
#define PROPERTY_DEBUG_RENDERENGINE_CAPTURE_SKIA_MS "debug.renderengine.capture_skia_ms"

struct ANativeWindowBuffer;

namespace android {
+9 −14
Original line number Diff line number Diff line
@@ -15,19 +15,19 @@
 */

//#define LOG_NDEBUG 0
#undef LOG_TAG
#define LOG_TAG "RenderEngine"
#define ATRACE_TAG ATRACE_TAG_GRAPHICS

#include <cstdint>
#include <memory>

#include "SkImageInfo.h"
#include "log/log_main.h"
#include "system/graphics-base-v1.0.h"
#undef LOG_TAG
#define LOG_TAG "RenderEngine"
#define ATRACE_TAG ATRACE_TAG_GRAPHICS

#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2.h>
#include <sync/sync.h>
#include <ui/BlurRegion.h>
#include <ui/GraphicBuffer.h>
@@ -35,6 +35,8 @@
#include "../gl/GLExtensions.h"
#include "SkiaGLRenderEngine.h"
#include "filters/BlurFilter.h"
#include "filters/LinearEffect.h"
#include "skia/debug/SkiaCapture.h"

#include <GrContextOptions.h>
#include <SkCanvas.h>
@@ -46,17 +48,9 @@
#include <SkShadowUtils.h>
#include <SkSurface.h>
#include <gl/GrGLInterface.h>
#include <sync/sync.h>
#include <ui/GraphicBuffer.h>
#include <utils/Trace.h>

#include <cmath>

#include "../gl/GLExtensions.h"
#include "SkiaGLRenderEngine.h"
#include "filters/BlurFilter.h"
#include "filters/LinearEffect.h"

bool checkGlError(const char* op, int lineNumber);

namespace android {
@@ -482,7 +476,7 @@ status_t SkiaGLRenderEngine::drawLayers(const DisplaySettings& display,
                                                                        : ui::Dataspace::SRGB,
                                                                mGrContext.get());

    auto canvas = surface->getCanvas();
    SkCanvas* canvas = mCapture.tryCapture(surface.get());
    // Clear the entire canvas with a transparent black to prevent ghost images.
    canvas->clear(SK_ColorTRANSPARENT);
    canvas->save();
@@ -663,11 +657,12 @@ status_t SkiaGLRenderEngine::drawLayers(const DisplaySettings& display,

        canvas->restore();
    }
    canvas->restore();
    mCapture.endCapture();
    {
        ATRACE_NAME("flush surface");
        surface->flush();
    }
    canvas->restore();

    if (drawFence != nullptr) {
        *drawFence = flush();
+3 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include "SkiaRenderEngine.h"
#include "android-base/macros.h"
#include "filters/BlurFilter.h"
#include "skia/debug/SkiaCapture.h"
#include "skia/filters/LinearEffect.h"

namespace android {
@@ -116,6 +117,8 @@ private:
    sk_sp<GrDirectContext> mProtectedGrContext;

    bool mInProtectedContext = false;
    // Object to capture commands send to Skia.
    SkiaCapture mCapture;
};

} // namespace skia
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * 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.
 */

#include "CaptureTimer.h"

#undef LOG_TAG
#define LOG_TAG "RenderEngine"
#define ATRACE_TAG ATRACE_TAG_GRAPHICS

#include "CommonPool.h"

#include <thread>

namespace android {
namespace renderengine {
namespace skia {

void CaptureTimer::setTimeout(TimeoutCallback function, std::chrono::milliseconds delay) {
    this->clear = false;
    CommonPool::post([=]() {
        if (this->clear) return;
        std::this_thread::sleep_for(delay);
        if (this->clear) return;
        function();
    });
}

void CaptureTimer::stop() {
    this->clear = true;
}

} // namespace skia
} // namespace renderengine
} // namespace android
 No newline at end of file
Loading