Bug 1758688 [wpt PR 33067] - [FedCM] Make revoke a non-static method, a=testonly
[gecko.git] / gfx / thebes / gfxAlphaRecovery.cpp
blob98a78ed3cb16ee302eb5502e58c6f7dfec2a8132
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "gfxAlphaRecovery.h"
8 #include "gfxImageSurface.h"
10 #define MOZILLA_SSE_INCLUDE_HEADER_FOR_SSE2
11 #include "mozilla/SSE.h"
13 /* static */
14 bool gfxAlphaRecovery::RecoverAlpha(gfxImageSurface* blackSurf,
15 const gfxImageSurface* whiteSurf) {
16 mozilla::gfx::IntSize size = blackSurf->GetSize();
18 if (size != whiteSurf->GetSize() ||
19 (blackSurf->Format() != mozilla::gfx::SurfaceFormat::A8R8G8B8_UINT32 &&
20 blackSurf->Format() != mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32) ||
21 (whiteSurf->Format() != mozilla::gfx::SurfaceFormat::A8R8G8B8_UINT32 &&
22 whiteSurf->Format() != mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32))
23 return false;
25 #ifdef MOZILLA_MAY_SUPPORT_SSE2
26 if (mozilla::supports_sse2() && RecoverAlphaSSE2(blackSurf, whiteSurf)) {
27 return true;
29 #endif
31 blackSurf->Flush();
32 whiteSurf->Flush();
34 unsigned char* blackData = blackSurf->Data();
35 unsigned char* whiteData = whiteSurf->Data();
37 for (int32_t i = 0; i < size.height; ++i) {
38 uint32_t* blackPixel = reinterpret_cast<uint32_t*>(blackData);
39 const uint32_t* whitePixel = reinterpret_cast<uint32_t*>(whiteData);
40 for (int32_t j = 0; j < size.width; ++j) {
41 uint32_t recovered = RecoverPixel(blackPixel[j], whitePixel[j]);
42 blackPixel[j] = recovered;
44 blackData += blackSurf->Stride();
45 whiteData += whiteSurf->Stride();
48 blackSurf->MarkDirty();
50 return true;