/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Some of this code is based on Skia source code, covered by the following * license notice (see readlicense_oo for the full license): * * Copyright 2016 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * */ #include #include #include #include #include #include #include #include using namespace SkiaHelper; namespace SkiaHelper { CGImageRef createCGImage(const Image& rImage) { BitmapEx bitmapEx(rImage.GetBitmapEx()); Bitmap bitmap(bitmapEx.GetBitmap()); if (bitmap.IsEmpty() || !bitmap.ImplGetSalBitmap()) return nullptr; assert(dynamic_cast(bitmap.ImplGetSalBitmap().get()) != nullptr); SkiaSalBitmap* skiaBitmap = static_cast(bitmap.ImplGetSalBitmap().get()); SkBitmap targetBitmap; if (!targetBitmap.tryAllocPixels( SkImageInfo::Make(bitmap.GetSizePixel().getWidth(), bitmap.GetSizePixel().getHeight(), kRGBA_8888_SkColorType, kPremul_SkAlphaType))) return nullptr; SkPaint paint; paint.setBlendMode(SkBlendMode::kSrc); // set as is SkMatrix matrix; // The image is needed upside-down. matrix.preTranslate(0, targetBitmap.height()); matrix.setConcat(matrix, SkMatrix::Scale(1, -1)); if (!bitmapEx.IsAlpha()) { SkCanvas canvas(targetBitmap); canvas.concat(matrix); canvas.drawImage(skiaBitmap->GetSkImage(), 0, 0, SkSamplingOptions(), &paint); } else { AlphaMask alpha(bitmapEx.GetAlphaMask()); // tdf#156854 invert alpha mask for macOS native menu item images // At the time of this change, only the AquaSalMenu class calls this // function so it should be safe to invert the alpha mask here. alpha.Invert(); Bitmap alphaBitmap(alpha.GetBitmap()); assert(dynamic_cast(alphaBitmap.ImplGetSalBitmap().get()) != nullptr); SkiaSalBitmap* skiaAlpha = static_cast(alphaBitmap.ImplGetSalBitmap().get()); #if 0 // Drawing to a bitmap using a shader from a GPU-backed image fails silently. // https://bugs.chromium.org/p/skia/issues/detail?id=12685 paint.setShader(SkShaders::Blend(SkBlendMode::kDstOut, skiaBitmap->GetSkShader(SkSamplingOptions()), skiaAlpha->GetAlphaSkShader(SkSamplingOptions()))); #else sk_sp imB = skiaBitmap->GetSkImage()->makeNonTextureImage(); sk_sp imA = skiaAlpha->GetAlphaSkImage()->makeNonTextureImage(); paint.setShader(SkShaders::Blend(SkBlendMode::kDstOut, imB->makeShader(SkSamplingOptions()), imA->makeShader(SkSamplingOptions()))); #endif SkCanvas canvas(targetBitmap); canvas.concat(matrix); canvas.drawPaint(paint); } CGContextRef context = CGBitmapContextCreate( targetBitmap.getAddr32(0, 0), targetBitmap.width(), targetBitmap.height(), 8, targetBitmap.rowBytes(), GetSalData()->mxRGBSpace, kCGImageAlphaPremultipliedLast); if (!context) return nullptr; CGImageRef screenImage = CGBitmapContextCreateImage(context); CFRelease(context); return screenImage; } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ abora/cp-5.0 LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2024-10-08cid#1632259 COPY_INSTEAD_OF_MOVECaolán McNamara
2024-09-12use more concrete UNO type in editengNoel Grandin
2024-05-07loplugin:ostr in editengNoel Grandin
2024-04-08tdf#146619 Drop unused 'using namespace' in: editeng/Gabor Kelemen
2023-06-26new loplugin:constexprliteralNoel Grandin
2023-06-18Use getXWeak in editengMike Kaganski
2022-08-18Move tools/diagnose_ex.h to comphelper/diagnose_ex.hxxStephan Bergmann
2022-07-25use more o3tl::spanNoel Grandin
2021-12-01loplugin:stringliteraldefine in editengNoel Grandin
2021-03-25const OUString -> const OUStringLiteralMike Kaganski
2021-02-22loplugin:refcounting in editengNoel
2020-08-28Change OUStringLiteral from char[] to char16_t[]Stephan Bergmann
2020-08-13use OUStringLiteral in SfxItemPropertyMapEntryNoel Grandin
2020-06-29loplugin:constantparamNoel Grandin
2020-06-03Upcoming loplugin:elidestringvar: editengStephan Bergmann
2019-12-20tdf#42949 Fix IWYU warnings in editeng/Gabor Kelemen
2019-12-03remove some useless comment linesNoel Grandin
2019-11-22Extend loplugin:external to warn about classesStephan Bergmann
2019-08-16use more TOOLS_WARN_EXCEPTIONNoel Grandin
2019-04-23tdf#42949 Fix IWYU warnings in include/editeng/[f-x]*Gabor Kelemen
2019-03-07log nice exception messages whereever possibleNoel Grandin