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 : efc838a3a4b196f78eda79ff3304c15d386bdc63
This commit is contained in:
Ryan Hunt 2018-08-01 12:50:32 -05:00
parent 90b1c71102
commit 6c76c39c97
9 changed files with 53 additions and 5 deletions

View File

@ -1303,6 +1303,11 @@ public:
*/
virtual void PadEdges(const IntRegion& aRegion);
/**
* Performs an in-place buffer unrotation operation.
*/
virtual bool Unrotate(IntPoint aRotation);
/**
* Create a SourceSurface optimized for use with this DrawTarget from
* existing bitmap data in memory.

View File

@ -11,6 +11,9 @@
#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)
{
@ -63,3 +66,5 @@ void BufferUnrotate(uint8_t* aBuffer, int aByteWidth, int aHeight,
}
}
} // namespace gfx
} // namespace mozilla

View File

@ -4,12 +4,18 @@
* 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/. */
#ifndef GFX_BUFFERUNROTATE_H
#define GFX_BUFFERUNROTATE_H
#ifndef MOZILLA_GFX_BUFFER_UNROTATE_H
#define MOZILLA_GFX_BUFFER_UNROTATE_H
#include "mozilla/Types.h"
namespace mozilla {
namespace gfx {
void BufferUnrotate(uint8_t* aBuffer, int aByteWidth, int aHeight,
int aByteStride, int aXByteBoundary, int aYBoundary);
#endif // GFX_BUFFERUNROTATE_H
} // namespace gfx
} // namespace mozilla
#endif // MOZILLA_GFX_BUFFER_UNROTATE_H

View File

@ -7,10 +7,12 @@
#include "2D.h"
#include "Logging.h"
#include "PathHelpers.h"
#include "Tools.h"
#include "DrawTargetCapture.h"
#include "BufferEdgePad.h"
#include "BufferUnrotate.h"
#ifdef BUILD_ARM_NEON
#include "mozilla/arm.h"
@ -296,5 +298,26 @@ DrawTarget::PadEdges(const IntRegion& aRegion)
PadDrawTargetOutFromRegion(this, aRegion);
}
bool
DrawTarget::Unrotate(IntPoint aRotation)
{
unsigned char* data;
IntSize size;
int32_t stride;
SurfaceFormat format;
if (LockBits(&data, &size, &stride, &format)) {
uint8_t bytesPerPixel = BytesPerPixel(format);
BufferUnrotate(data,
size.width * bytesPerPixel,
size.height, stride,
aRotation.x * bytesPerPixel,
aRotation.y);
ReleaseBits(data);
return true;
}
return false;
}
} // namespace gfx
} // namespace mozilla

View File

@ -115,6 +115,12 @@ public:
const IntRect& aBounds = IntRect(),
bool aCopyBackground = false) override;
virtual bool Unrotate(IntPoint aRotation) override
{
return mA->Unrotate(aRotation) &&
mB->Unrotate(aRotation);
}
virtual already_AddRefed<SourceSurface>
CreateSourceSurfaceFromData(unsigned char *aData,
const IntSize &aSize,

View File

@ -163,6 +163,7 @@ UNIFIED_SOURCES += [
'BezierUtils.cpp',
'Blur.cpp',
'BufferEdgePad.cpp',
'BufferUnrotate.cpp',
'CaptureCommandList.cpp',
'DataSourceSurface.cpp',
'DataSurfaceHelpers.cpp',

View File

@ -51,6 +51,10 @@
#undef compress
#include "mozilla/Compression.h"
// Undo the damage done by X11
#ifdef Status
# undef Status
#endif
// Protocol buffer (generated automatically)
#include "protobuf/LayerScopePacket.pb.h"

View File

@ -9,7 +9,6 @@
#include <algorithm> // for max
#include "BasicImplData.h" // for BasicImplData
#include "BasicLayersImpl.h" // for ToData
#include "BufferUnrotate.h" // for BufferUnrotate
#include "GeckoProfiler.h" // for AUTO_PROFILER_LABEL
#include "Layers.h" // for PaintedLayer, Layer, etc
#include "gfxPlatform.h" // for gfxPlatform

View File

@ -354,7 +354,6 @@ UNIFIED_SOURCES += [
'basic/TextureHostBasic.cpp',
'BSPTree.cpp',
'BufferTexture.cpp',
'BufferUnrotate.cpp',
'CanvasRenderer.cpp',
'client/CanvasClient.cpp',
'client/ClientCanvasLayer.cpp',