diff options
author | Robert Phillips <robertphillips@google.com> | 2023-12-12 09:20:09 -0500 |
---|---|---|
committer | SkCQ <skcq-be@skia-corp.google.com.iam.gserviceaccount.com> | 2023-12-12 16:15:47 +0000 |
commit | 7685acfb622190506f54533b5083737cb36f86ca (patch) | |
tree | b1c2a2f56d1ba7dd2e59a98f4058ae1d6fd5f331 | |
parent | 053490edfa703f3433d97a299ee80f2acc93de71 (diff) | |
download | skia-7685acfb622190506f54533b5083737cb36f86ca.tar.gz |
Revert^2 "[graphite] Allow GetSkColorTypeFromBufferFormat to be used in Graphite"
This reverts commit 17bd70326a4956afa059e5cea99fd37b83d271f0.
Reason for revert: Revised to _not_ break the Android & G3 builds
Original change's description:
> Revert "[graphite] Allow GetSkColorTypeFromBufferFormat to be used in Graphite"
>
> This reverts commit cdc40b40cdde070414d75ac289f47c401b7f26b3.
>
> Reason for revert: Android is calling this!!!!!!
>
> Original change's description:
> > [graphite] Allow GetSkColorTypeFromBufferFormat to be used in Graphite
> >
> > Bug: b/237108194
> > Change-Id: Ie14c9a9849e4965de1d9258adfe0b746bccb8710
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/787516
> > Reviewed-by: Nicolette Prevost <nicolettep@google.com>
> > Commit-Queue: Robert Phillips <robertphillips@google.com>
> > Reviewed-by: Kevin Lubick <kjlubick@google.com>
>
> Bug: b/237108194
> Change-Id: Ib2fc311059e2d4ff6afecf717e73a345a785e1f1
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/788459
> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Auto-Submit: Robert Phillips <robertphillips@google.com>
Bug: b/237108194
Change-Id: I17858dfc6d313f379665e2a5363ed239f7bc7b19
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/788978
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Nicolette Prevost <nicolettep@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
-rw-r--r-- | BUILD.gn | 4 | ||||
-rw-r--r-- | bazel/exporter_tool/main.go | 4 | ||||
-rw-r--r-- | gn/gpu.gni | 4 | ||||
-rw-r--r-- | include/android/AHardwareBufferUtils.h | 23 | ||||
-rw-r--r-- | include/android/BUILD.bazel | 1 | ||||
-rw-r--r-- | include/android/GrAHardwareBufferUtils.h | 2 | ||||
-rw-r--r-- | src/gpu/BUILD.bazel | 1 | ||||
-rw-r--r-- | src/gpu/android/AHardwareBufferUtils.cpp | 45 | ||||
-rw-r--r-- | src/gpu/android/BUILD.bazel | 11 | ||||
-rw-r--r-- | src/gpu/ganesh/GrAHardwareBufferImageGenerator.cpp | 3 | ||||
-rw-r--r-- | src/gpu/ganesh/GrAHardwareBufferUtils.cpp | 29 | ||||
-rw-r--r-- | src/gpu/ganesh/surface/SkSurface_AndroidFactories.cpp | 82 | ||||
-rw-r--r-- | src/image/SkImage_AndroidFactories.cpp | 3 | ||||
-rw-r--r-- | tests/MultiPictureDocumentTest.cpp | 3 |
14 files changed, 147 insertions, 68 deletions
@@ -962,6 +962,10 @@ optional("gpu_shared") { public_defines += [ "SK_METAL" ] sources += skia_shared_mtl_sources } + + if (is_android) { + sources += skia_shared_android_sources + } } optional("gpu") { diff --git a/bazel/exporter_tool/main.go b/bazel/exporter_tool/main.go index 76c58fa087..a587eea164 100644 --- a/bazel/exporter_tool/main.go +++ b/bazel/exporter_tool/main.go @@ -420,6 +420,10 @@ var gniExportDescs = []exporter.GNIExportDesc{ "//src/gpu/mtl:mtl_hdrs", "//src/gpu/mtl:mtl_srcs", }}, + {Var: "skia_shared_android_sources", + Rules: []string{ + "//src/gpu/android:shared_android_srcs", + }}, }}, {GNI: "modules/svg/svg.gni", Vars: []exporter.GNIFileListExportDesc{ {Var: "skia_svg_public", diff --git a/gn/gpu.gni b/gn/gpu.gni index c7cfaa913a..61afc6d8e9 100644 --- a/gn/gpu.gni +++ b/gn/gpu.gni @@ -18,6 +18,7 @@ # //include/private/gpu/ganesh/BUILD.bazel # //include/private/gpu/vk/BUILD.bazel # //src/gpu/BUILD.bazel +# //src/gpu/android/BUILD.bazel # //src/gpu/ganesh/BUILD.bazel # //src/gpu/ganesh/d3d/BUILD.bazel # //src/gpu/ganesh/effects/BUILD.bazel @@ -1120,3 +1121,6 @@ skia_shared_mtl_sources = [ "$_src/gpu/mtl/MtlUtils.mm", "$_src/gpu/mtl/MtlUtilsPriv.h", ] + +# Generated by Bazel rule //src/gpu/android:shared_android_srcs +skia_shared_android_sources = [ "$_src/gpu/android/AHardwareBufferUtils.cpp" ] diff --git a/include/android/AHardwareBufferUtils.h b/include/android/AHardwareBufferUtils.h new file mode 100644 index 0000000000..a1f4f7e99a --- /dev/null +++ b/include/android/AHardwareBufferUtils.h @@ -0,0 +1,23 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef AHardwareBufferUtils_DEFINED +#define AHardwareBufferUtils_DEFINED + +#include "include/core/SkColorType.h" +#include "include/core/SkTypes.h" + +#if __ANDROID_API__ >= 26 + +namespace AHardwareBufferUtils { + +SkColorType GetSkColorTypeFromBufferFormat(uint32_t bufferFormat); + +} // namespace AHardwareBufferUtils + +#endif + +#endif // AHardwareBufferUtils_DEFINED diff --git a/include/android/BUILD.bazel b/include/android/BUILD.bazel index 45d87a6885..7e0e61c277 100644 --- a/include/android/BUILD.bazel +++ b/include/android/BUILD.bazel @@ -16,6 +16,7 @@ skia_filegroup( skia_filegroup( name = "private_hdrs", srcs = [ + "AHardwareBufferUtils.h", "GrAHardwareBufferUtils.h", "SkCanvasAndroid.h", "SkImageAndroid.h", diff --git a/include/android/GrAHardwareBufferUtils.h b/include/android/GrAHardwareBufferUtils.h index 474e9f4a66..92d6dd4d78 100644 --- a/include/android/GrAHardwareBufferUtils.h +++ b/include/android/GrAHardwareBufferUtils.h @@ -22,6 +22,8 @@ extern "C" { namespace GrAHardwareBufferUtils { +// TODO: remove this function once Android has been updated to call the AHardwareBufferUtils +// version SkColorType GetSkColorTypeFromBufferFormat(uint32_t bufferFormat); #if !defined(SK_DISABLE_LEGACY_ANDROID_HW_UTILS) diff --git a/src/gpu/BUILD.bazel b/src/gpu/BUILD.bazel index a06915cee2..6c1bc7244b 100644 --- a/src/gpu/BUILD.bazel +++ b/src/gpu/BUILD.bazel @@ -151,6 +151,7 @@ skia_filegroup( ] + select( { ":has_vulkan": ["//src/gpu/vk:srcs"], + "@platforms//os:android": ["//src/gpu/android:shared_android_srcs"], "//conditions:default": [], }, ), diff --git a/src/gpu/android/AHardwareBufferUtils.cpp b/src/gpu/android/AHardwareBufferUtils.cpp new file mode 100644 index 0000000000..dfe236aacf --- /dev/null +++ b/src/gpu/android/AHardwareBufferUtils.cpp @@ -0,0 +1,45 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "include/android/AHardwareBufferUtils.h" + +#if __ANDROID_API__ >= 26 + +#include <android/hardware_buffer.h> + +namespace AHardwareBufferUtils { + +SkColorType GetSkColorTypeFromBufferFormat(uint32_t bufferFormat) { + switch (bufferFormat) { + case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM: + return kRGBA_8888_SkColorType; + case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM: + return kRGB_888x_SkColorType; + case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT: + return kRGBA_F16_SkColorType; + case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM: + return kRGB_565_SkColorType; + case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM: + return kRGB_888x_SkColorType; + case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM: + return kRGBA_1010102_SkColorType; +#if __ANDROID_API__ >= 33 + case AHARDWAREBUFFER_FORMAT_R8_UNORM: + return kAlpha_8_SkColorType; +#endif + default: + // Given that we only use this texture as a source, colorType will not impact how Skia + // uses the texture. The only potential affect this is anticipated to have is that for + // some format types if we are not bound as an OES texture we may get invalid results + // for SKP capture if we read back the texture. + return kRGBA_8888_SkColorType; + } +} + +} // namespace AHardwareBufferUtils + +#endif diff --git a/src/gpu/android/BUILD.bazel b/src/gpu/android/BUILD.bazel new file mode 100644 index 0000000000..d1b7ec8b2f --- /dev/null +++ b/src/gpu/android/BUILD.bazel @@ -0,0 +1,11 @@ +load("//bazel:skia_rules.bzl", "exports_files_legacy", "skia_filegroup") + +licenses(["notice"]) + +exports_files_legacy() + +skia_filegroup( + name = "shared_android_srcs", + srcs = ["AHardwareBufferUtils.cpp"], + visibility = ["//src/gpu:__pkg__"], +) diff --git a/src/gpu/ganesh/GrAHardwareBufferImageGenerator.cpp b/src/gpu/ganesh/GrAHardwareBufferImageGenerator.cpp index 2de02ee604..98f5c4ef30 100644 --- a/src/gpu/ganesh/GrAHardwareBufferImageGenerator.cpp +++ b/src/gpu/ganesh/GrAHardwareBufferImageGenerator.cpp @@ -11,6 +11,7 @@ #include "src/gpu/ganesh/GrAHardwareBufferImageGenerator.h" +#include "include/android/AHardwareBufferUtils.h" #include "include/android/GrAHardwareBufferUtils.h" #include "include/core/SkColorSpace.h" #include "include/gpu/GrBackendSurface.h" @@ -38,7 +39,7 @@ std::unique_ptr<SkImageGenerator> GrAHardwareBufferImageGenerator::Make( AHardwareBuffer_describe(graphicBuffer, &bufferDesc); SkColorType colorType = - GrAHardwareBufferUtils::GetSkColorTypeFromBufferFormat(bufferDesc.format); + AHardwareBufferUtils::GetSkColorTypeFromBufferFormat(bufferDesc.format); SkImageInfo info = SkImageInfo::Make(bufferDesc.width, bufferDesc.height, colorType, alphaType, std::move(colorSpace)); diff --git a/src/gpu/ganesh/GrAHardwareBufferUtils.cpp b/src/gpu/ganesh/GrAHardwareBufferUtils.cpp index c7dffb750a..dc41e4688b 100644 --- a/src/gpu/ganesh/GrAHardwareBufferUtils.cpp +++ b/src/gpu/ganesh/GrAHardwareBufferUtils.cpp @@ -17,33 +17,14 @@ #include "include/gpu/GrDirectContext.h" #endif +// TODO: remove this once Android is using the AHardwareBufferUtils version of +// GetSkColorTypeFromBufferFormat +#include "include/android/AHardwareBufferUtils.h" + namespace GrAHardwareBufferUtils { SkColorType GetSkColorTypeFromBufferFormat(uint32_t bufferFormat) { - switch (bufferFormat) { - case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM: - return kRGBA_8888_SkColorType; - case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM: - return kRGB_888x_SkColorType; - case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT: - return kRGBA_F16_SkColorType; - case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM: - return kRGB_565_SkColorType; - case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM: - return kRGB_888x_SkColorType; - case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM: - return kRGBA_1010102_SkColorType; -#if __ANDROID_API__ >= 33 - case AHARDWAREBUFFER_FORMAT_R8_UNORM: - return kAlpha_8_SkColorType; -#endif - default: - // Given that we only use this texture as a source, colorType will not impact how Skia - // uses the texture. The only potential affect this is anticipated to have is that for - // some format types if we are not bound as an OES texture we may get invalid results - // for SKP capture if we read back the texture. - return kRGBA_8888_SkColorType; - } + return AHardwareBufferUtils::GetSkColorTypeFromBufferFormat(bufferFormat); } #if !defined(SK_DISABLE_LEGACY_ANDROID_HW_UTILS) diff --git a/src/gpu/ganesh/surface/SkSurface_AndroidFactories.cpp b/src/gpu/ganesh/surface/SkSurface_AndroidFactories.cpp index b2a401e8eb..5a434afea6 100644 --- a/src/gpu/ganesh/surface/SkSurface_AndroidFactories.cpp +++ b/src/gpu/ganesh/surface/SkSurface_AndroidFactories.cpp @@ -9,6 +9,8 @@ #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 +#include "include/android/AHardwareBufferUtils.h" +#include "include/android/GrAHardwareBufferUtils.h" #include "include/android/SkSurfaceAndroid.h" #include "include/core/SkCanvas.h" #include "include/core/SkColorSpace.h" @@ -35,7 +37,6 @@ #include "src/gpu/SkBackingFit.h" #include "src/gpu/SkRenderEngineAbortf.h" #include "src/gpu/ganesh/Device.h" -#include "include/android/GrAHardwareBufferUtils.h" #include "src/gpu/ganesh/GrCaps.h" #include "src/gpu/ganesh/GrContextThreadSafeProxyPriv.h" #include "src/gpu/ganesh/GrDirectContextPriv.h" @@ -75,6 +76,9 @@ sk_sp<SkSurface> WrapAndroidHardwareBuffer(GrDirectContext* dContext, } bool isTextureable = SkToBool(bufferDesc.usage & AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE); + if (!isTextureable) { + return nullptr; + } GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat( dContext, hardwareBuffer, bufferDesc.format, true); @@ -82,53 +86,49 @@ sk_sp<SkSurface> WrapAndroidHardwareBuffer(GrDirectContext* dContext, return nullptr; } - if (isTextureable) { - GrAHardwareBufferUtils::DeleteImageProc deleteImageProc = nullptr; - GrAHardwareBufferUtils::UpdateImageProc updateImageProc = nullptr; - GrAHardwareBufferUtils::TexImageCtx deleteImageCtx = nullptr; + GrAHardwareBufferUtils::DeleteImageProc deleteImageProc = nullptr; + GrAHardwareBufferUtils::UpdateImageProc updateImageProc = nullptr; + GrAHardwareBufferUtils::TexImageCtx deleteImageCtx = nullptr; - bool isProtectedContent = - SkToBool(bufferDesc.usage & AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT); + bool isProtectedContent = + SkToBool(bufferDesc.usage & AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT); - bool fromWindowLocal = false; + bool fromWindowLocal = false; #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK - fromWindowLocal = fromWindow; + fromWindowLocal = fromWindow; #endif - GrBackendTexture backendTexture = - GrAHardwareBufferUtils::MakeBackendTexture(dContext, - hardwareBuffer, - bufferDesc.width, - bufferDesc.height, - &deleteImageProc, - &updateImageProc, - &deleteImageCtx, - isProtectedContent, - backendFormat, - true, - fromWindowLocal); - if (!backendTexture.isValid()) { - return nullptr; - } - - SkColorType colorType = - GrAHardwareBufferUtils::GetSkColorTypeFromBufferFormat(bufferDesc.format); - - // Will call deleteImageProc if SkSurface creation fails. - sk_sp<SkSurface> surface = SkSurfaces::WrapBackendTexture(dContext, - backendTexture, - origin, - 0, - colorType, - std::move(colorSpace), - surfaceProps, - deleteImageProc, - deleteImageCtx); - - return surface; - } else { + GrBackendTexture backendTexture = + GrAHardwareBufferUtils::MakeBackendTexture(dContext, + hardwareBuffer, + bufferDesc.width, + bufferDesc.height, + &deleteImageProc, + &updateImageProc, + &deleteImageCtx, + isProtectedContent, + backendFormat, + true, + fromWindowLocal); + if (!backendTexture.isValid()) { return nullptr; } + + SkColorType colorType = + AHardwareBufferUtils::GetSkColorTypeFromBufferFormat(bufferDesc.format); + + // Will call deleteImageProc if SkSurface creation fails. + sk_sp<SkSurface> surface = SkSurfaces::WrapBackendTexture(dContext, + backendTexture, + origin, + 0, + colorType, + std::move(colorSpace), + surfaceProps, + deleteImageProc, + deleteImageCtx); + + return surface; } } // namespace SkSurfaces diff --git a/src/image/SkImage_AndroidFactories.cpp b/src/image/SkImage_AndroidFactories.cpp index a595c96dbe..4c8df1526f 100644 --- a/src/image/SkImage_AndroidFactories.cpp +++ b/src/image/SkImage_AndroidFactories.cpp @@ -11,6 +11,7 @@ #include "include/android/SkImageAndroid.h" +#include "include/android/AHardwareBufferUtils.h" #include "include/android/GrAHardwareBufferUtils.h" #include "include/core/SkAlphaType.h" #include "include/core/SkBitmap.h" @@ -127,7 +128,7 @@ sk_sp<SkImage> TextureFromAHardwareBufferWithData(GrDirectContext* dContext, auto releaseHelper = skgpu::RefCntedCallback::Make(deleteImageProc, deleteImageCtx); SkColorType colorType = - GrAHardwareBufferUtils::GetSkColorTypeFromBufferFormat(bufferDesc.format); + AHardwareBufferUtils::GetSkColorTypeFromBufferFormat(bufferDesc.format); GrColorType grColorType = SkColorTypeToGrColorType(colorType); diff --git a/tests/MultiPictureDocumentTest.cpp b/tests/MultiPictureDocumentTest.cpp index 6cbead0290..e4bce003fa 100644 --- a/tests/MultiPictureDocumentTest.cpp +++ b/tests/MultiPictureDocumentTest.cpp @@ -183,6 +183,7 @@ DEF_TEST(SkMultiPictureDocument_Serialize_and_deserialize, reporter) { #if defined(SK_GANESH) && defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 +#include "include/android/AHardwareBufferUtils.h" #include "include/android/GrAHardwareBufferUtils.h" #include "include/core/SkBitmap.h" #include "include/core/SkColorSpace.h" @@ -310,7 +311,7 @@ static sk_sp<SkImage> makeAHardwareBufferTestImage( backendFormat, false // isRenderable ); - SkColorType colorType = GrAHardwareBufferUtils::GetSkColorTypeFromBufferFormat(hwbDesc.format); + SkColorType colorType = AHardwareBufferUtils::GetSkColorTypeFromBufferFormat(hwbDesc.format); sk_sp<SkImage> image = SkImages::BorrowTextureFrom(context, texture, kTopLeft_GrSurfaceOrigin, |