Coverage Report

Created: 2024-09-14 07:19

/src/skia/src/gpu/ganesh/image/SkImage_LazyTexture.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2023 Google LLC
3
 *
4
 * Use of this source code is governed by a BSD-style license that can be
5
 * found in the LICENSE file.
6
 */
7
8
#include "src/gpu/ganesh/image/SkImage_LazyTexture.h"
9
10
#include "include/core/SkColorSpace.h"
11
#include "include/core/SkImage.h"
12
#include "include/core/SkImageGenerator.h"
13
#include "include/core/SkImageInfo.h"
14
#include "include/core/SkPixmap.h"
15
#include "include/gpu/GpuTypes.h"
16
#include "include/gpu/ganesh/GrDirectContext.h"
17
#include "include/gpu/ganesh/SkImageGanesh.h"
18
#include "include/private/gpu/ganesh/GrTextureGenerator.h" // IWYU pragma: keep
19
#include "src/gpu/ganesh/GrColorInfo.h"
20
#include "src/gpu/ganesh/GrDirectContextPriv.h"
21
#include "src/gpu/ganesh/GrSurfaceProxyView.h"
22
#include "src/gpu/ganesh/SkGr.h"
23
#include "src/gpu/ganesh/SurfaceContext.h"
24
#include "src/gpu/ganesh/image/GrImageUtils.h"
25
26
#include <cstddef>
27
#include <memory>
28
#include <utility>
29
30
enum class GrColorType;
31
32
sk_sp<SkImage> SkImage_LazyTexture::onMakeSubset(GrDirectContext* direct,
33
0
                                                 const SkIRect& subset) const {
34
0
    auto pixels = direct ? SkImages::TextureFromImage(direct, this) :
35
0
                           this->makeRasterImage(nullptr);
36
0
    return pixels ? pixels->makeSubset(direct, subset) : nullptr;
37
0
}
38
39
0
bool SkImage_LazyTexture::readPixelsProxy(GrDirectContext* ctx, const SkPixmap& pixmap) const {
40
0
    if (!ctx) {
41
0
        return false;
42
0
    }
43
0
    GrSurfaceProxyView view = skgpu::ganesh::LockTextureProxyView(
44
0
            ctx, this, GrImageTexGenPolicy::kDraw, skgpu::Mipmapped::kNo);
45
46
0
    if (!view) {
47
0
        return false;
48
0
    }
49
50
0
    GrColorType ct = skgpu::ganesh::ColorTypeOfLockTextureProxy(ctx->priv().caps(),
51
0
                                                                this->colorType());
52
0
    GrColorInfo colorInfo(ct, this->alphaType(), this->refColorSpace());
53
0
    auto sContext = ctx->priv().makeSC(std::move(view), colorInfo);
54
0
    if (!sContext) {
55
0
        return false;
56
0
    }
57
0
    size_t rowBytes = this->imageInfo().minRowBytes();
58
0
    return sContext->readPixels(ctx, {this->imageInfo(), pixmap.writable_addr(), rowBytes}, {0, 0});
59
0
}
60
61
namespace SkImages {
62
0
sk_sp<SkImage> DeferredFromTextureGenerator(std::unique_ptr<GrTextureGenerator> generator) {
63
0
    SkImage_Lazy::Validator validator(
64
0
            SharedGenerator::Make(std::move(generator)), nullptr, nullptr);
65
66
0
    return validator ? sk_make_sp<SkImage_LazyTexture>(&validator) : nullptr;
67
0
}
68
}