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

Commit 9dddefca authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "DL-next groundwork" am: ca53522c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12952656

Change-Id: I0cf4b0ff8eba5aec7351dc70d0ba079e12f70818
parents 23bf2b66 ca53522c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -429,6 +429,8 @@ cc_defaults {
    whole_static_libs: ["libskia"],

    srcs: [
        "canvas/CanvasOpBuffer.cpp",
        "canvas/CanvasOpRasterizer.cpp",
        "pipeline/skia/SkiaDisplayList.cpp",
        "pipeline/skia/SkiaRecordingCanvas.cpp",
        "pipeline/skia/RenderNodeDrawable.cpp",
@@ -604,6 +606,7 @@ cc_test {
        "tests/unit/ABitmapTests.cpp",
        "tests/unit/CacheManagerTests.cpp",
        "tests/unit/CanvasContextTests.cpp",
        "tests/unit/CanvasOpTests.cpp",
        "tests/unit/CommonPoolTests.cpp",
        "tests/unit/DamageAccumulatorTests.cpp",
        "tests/unit/DeferredLayerUpdaterTests.cpp",
+25 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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 "CanvasOpBuffer.h"

#include "CanvasOps.h"

namespace android::uirenderer {

template class OpBuffer<CanvasOpType, CanvasOpContainer>;

}  // namespace android::uirenderer
+60 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.
 */

#pragma once

#include <SkMatrix.h>

#include "CanvasOpTypes.h"
#include "OpBuffer.h"

namespace android::uirenderer {

template <CanvasOpType T>
struct CanvasOp;

template <CanvasOpType T>
class CanvasOpContainer {
private:
    BE_OPBUFFERS_FRIEND();

    OpBufferItemHeader<CanvasOpType> header;
    // TODO: Figure out some magic to make this not be here when it's identity (or not used)
    SkMatrix mTransform;
    CanvasOp<T> mImpl;

public:
    CanvasOpContainer(CanvasOp<T>&& impl, const SkMatrix& transform = SkMatrix::I())
            : mTransform(transform), mImpl(std::move(impl)) {}

    uint32_t size() const { return header.size; }
    CanvasOpType type() const { return header.type; }

    const SkMatrix& transform() const { return mTransform; }

    CanvasOp<T>* operator->() noexcept { return &mImpl; }
};

extern template class OpBuffer<CanvasOpType, CanvasOpContainer>;
class CanvasOpBuffer final : public OpBuffer<CanvasOpType, CanvasOpContainer> {
public:
    template <CanvasOpType T>
    void push(CanvasOp<T>&& op) {
        push_container(CanvasOpContainer<T>(std::move(op)));
    }
};

}  // namespace android::uirenderer
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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 "CanvasOpRasterizer.h"

#include <SkCanvas.h>
#include <log/log.h>

#include <vector>

#include "CanvasOpBuffer.h"
#include "CanvasOps.h"

namespace android::uirenderer {

void rasterizeCanvasBuffer(const CanvasOpBuffer& source, SkCanvas* destination) {
    // Tracks the global transform from the current display list back toward the display space
    // Push on beginning a RenderNode draw, pop on ending one
    std::vector<SkMatrix> globalMatrixStack;
    SkMatrix& currentGlobalTransform = globalMatrixStack.emplace_back(SkMatrix::I());

    source.for_each([&]<CanvasOpType T>(CanvasOpContainer<T> * op) {
        if constexpr (T == CanvasOpType::BeginZ || T == CanvasOpType::EndZ) {
            // Do beginZ or endZ
            LOG_ALWAYS_FATAL("TODO");
            return;
        } else {
            // Generic OP
            // First apply the current transformation
            destination->setMatrix(SkMatrix::Concat(currentGlobalTransform, op->transform()));
            // Now draw it
            (*op)->draw(destination);
        }
    });
}

}  // namespace android::uirenderer
+64 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.
 */

#pragma once

#include <hwui/Bitmap.h>

#include <SkBitmap.h>
#include <SkCanvas.h>

#include "CanvasOps.h"

#include <experimental/type_traits>
#include <variant>

namespace android::uirenderer {

class CanvasOpBuffer;

void rasterizeCanvasBuffer(const CanvasOpBuffer& source, SkCanvas* destination);

class ImmediateModeRasterizer {
public:
    explicit ImmediateModeRasterizer(std::unique_ptr<SkCanvas>&& canvas) {
        mCanvas = canvas.get();
        mOwnership = std::move(canvas);
    }

    explicit ImmediateModeRasterizer(std::shared_ptr<SkCanvas> canvas) {
        mCanvas = canvas.get();
        mOwnership = std::move(canvas);
    }

    explicit ImmediateModeRasterizer(Bitmap& bitmap) {
        mCanvas = &(mOwnership.emplace<SkCanvas>(bitmap.getSkBitmap()));
    }

    template <CanvasOpType T>
    void draw(const CanvasOp<T>& op) {
        if constexpr (CanvasOpTraits::can_draw<CanvasOp<T>>) {
            op.draw(mCanvas);
        }
    }

private:
    SkCanvas* mCanvas;
    // Just here to keep mCanvas alive. Thankfully we never need to actually look inside this...
    std::variant<SkCanvas, std::shared_ptr<SkCanvas>, std::unique_ptr<SkCanvas>> mOwnership;
};

}  // namespace android::uirenderer
Loading