gecko-dev/gfx/2d/BufferUnrotate.cpp
Ryan Hunt a71d0035ad Bug 1478815 part 7 - Add a buffer unrotate operation to DrawTarget. r=bas
This commit adds a buffer unrotate operation to DrawTarget. It's
initially implemented with LockBits in DrawTarget. DrawTargetDual
overrides the implementation to pass on the operation to it's
DrawTargets.

No override is given for DrawTargetCapture as we intentionally
avoid this code path when async painting as it can fail.

This is needed so that RotatedBuffer can expose a single DrawTarget,
which can be a DrawTarget (for normal alpha), DrawTargetDual (for
component alpha), or DrawTargetCapture (when async painting).

MozReview-Commit-ID: csjjZ733hl

--HG--
rename : gfx/layers/BufferUnrotate.cpp => gfx/2d/BufferUnrotate.cpp
rename : gfx/layers/BufferUnrotate.h => gfx/2d/BufferUnrotate.h
extra : rebase_source : 5d96e2a5d36a01f2f9992adb37830e56436c7c35
extra : source : 64cb50b227e0ae604653f03ce2e892493126392e
2018-08-01 12:50:32 -05:00

71 lines
2.4 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include <algorithm> // min & max
#include <cstdlib>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
namespace mozilla {
namespace gfx {
void BufferUnrotate(uint8_t* aBuffer, int aByteWidth, int aHeight,
int aByteStride, int aXBoundary, int aYBoundary)
{
if (aXBoundary != 0) {
uint8_t* line = new uint8_t[aByteWidth];
uint32_t smallStart = 0;
uint32_t smallLen = aXBoundary;
uint32_t smallDest = aByteWidth - aXBoundary;
uint32_t largeStart = aXBoundary;
uint32_t largeLen = aByteWidth - aXBoundary;
uint32_t largeDest = 0;
if (aXBoundary > aByteWidth / 2) {
smallStart = aXBoundary;
smallLen = aByteWidth - aXBoundary;
smallDest = 0;
largeStart = 0;
largeLen = aXBoundary;
largeDest = smallLen;
}
for (int y = 0; y < aHeight; y++) {
int yOffset = y * aByteStride;
memcpy(line, &aBuffer[yOffset + smallStart], smallLen);
memmove(&aBuffer[yOffset + largeDest], &aBuffer[yOffset + largeStart], largeLen);
memcpy(&aBuffer[yOffset + smallDest], line, smallLen);
}
delete[] line;
}
if (aYBoundary != 0) {
uint32_t smallestHeight = std::min(aHeight - aYBoundary, aYBoundary);
uint32_t largestHeight = std::max(aHeight - aYBoundary, aYBoundary);
uint32_t smallOffset = 0;
uint32_t largeOffset = aYBoundary * aByteStride;
uint32_t largeDestOffset = 0;
uint32_t smallDestOffset = largestHeight * aByteStride;
if (aYBoundary > aHeight / 2) {
smallOffset = aYBoundary * aByteStride;
largeOffset = 0;
largeDestOffset = smallestHeight * aByteStride;
smallDestOffset = 0;
}
uint8_t* smallestSide = new uint8_t[aByteStride * smallestHeight];
memcpy(smallestSide, &aBuffer[smallOffset], aByteStride * smallestHeight);
memmove(&aBuffer[largeDestOffset], &aBuffer[largeOffset], aByteStride * largestHeight);
memcpy(&aBuffer[smallDestOffset], smallestSide, aByteStride * smallestHeight);
delete[] smallestSide;
}
}
} // namespace gfx
} // namespace mozilla