mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 05:37:11 +00:00
c8732098b3
- Bug 1246851 (Part 1) - Add a new SurfacePipe API for writing to image surfaces in a safe and composable manner. r=njn (2e3353a6a7) - Bug 1246851 (Part 2) - Add SurfaceFilter implementations for basic surface output operations. r=njn (fa30948a3f) - Bug 1246851 (Part 3) - Add a factory for constructing SurfacePipes. r=njn (7a746d3ec8) - Bug 1191347 - Explicitly release surfaces on the main thread in TestDecodeToSurface. r=me (fa1a68dc9a) - Bug 1246851 (Part 4) - Add a test suite for SurfacePipes and SurfaceFilters. r=njn (380dc94c08) - Bug 1247152 (Part 1) - Use SurfacePipe in the GIF decoder. r=njn (8b3d76f017) - Bug 1247152 (Part 2) - Remove even more code from the GIF decoder. r=edwin (80c8cc5e1c) - side effects Bug 1247152 (Part 1) (5b6cbf0ad5) - Bug 1237232 - Properly check the result of Vector append() calls in security/. r=keeler (b06dce061f) - Bug 1235308 - Fix -Wimplicit-fallthrough warnings in security/. r=keeler (ac5c3bf540) - Bug 1235188 - Fix -Wformat warnings in security/certverifier/. r=keeler (25ee7ee77c) - Bug 1004149 - Remove some dead code. r=keeler (59fedcb6a6) - Bug 1004149 - Return mozilla::pkix::Result values in nsNSSHttpInterface functions. r=keeler (76933c7d94) - Bug 1187173 - Disable warning C4623 on security/certverifier. r=briansmith (c1353b0577) - Bug 1256484 - Disable C4456 and C4458 to unblock compilation on VS2015; r=keeler (b51ac368ba) - Bug 1251009 - Remove unused nsICertificateDialogs.notifyCACertExists() method. r=keeler, r=mfinkle (9ca9aee3d0) - Bug 1249224 - window.open() should open a new window in the same container, r=bz (c57c76ec2f) - Bug 1245451 - add default nullptr value to mChrome. r=bsmedberg (3236ea34df) - Bug 1255849. Add some documentation for AutoJSAPI instances that seem to be used just for cxpushing. r=bholley (60a81652de) - Bug 1189554 - Make Saved Passwords dialog resizable on Windows again. r=smaug (a367796251) - Bug 1252974 - Convert screen's available dimensions to CSS-pixel units in nsWindowWatcher. r=emk (5524055ab0) - Bug 1233328 - Part 1: Ignore SHA-1 pins in PublicKeyPinningService.cpp. r=keeler (e5fe732a4b) - Bug 1233328 - Part 2: Use SHA-256 StaticFingerprints directly instead창 of StaticPinset since the SHA-1 StaticFingerprints entry will always be null. r=keeler (50f88c76da) - Bug 1256089 - Fix Mutex support for tier-3 platforms; r=froydnj (76ab483843) - Bug 1257019 - Add move construction to js::Mutex<T>. r=terrence (383ad474ba) - No bug, Automated HPKP preload list update from host bld-linux64-spot-309 - a=hpkp-update (0a6d3b9c40) - No bug, Automated HPKP preload list update from host bld-linux64-spot-223 - a=hpkp-update (7b3dbac6f8) - Bug 1255655 - Const-ify kPinset_* arrays. r=cykesiopka. (ddbaad40a0) - No bug, Automated HPKP preload list update from host bld-linux64-spot-543 - a=hpkp-update (f5c37e366a) - bug 1233853 - make nsSyncJPAKE aware of NSS shutdown r=jcj (9f74b5a46f) - Bug 1215734 - Expand GeckoMediaPlugin sandbox policy for Clang 3.7 ASan. r=kang (a96e0429e5) - part Bug 1154738 - Fixed WMFUtils.cpp compilation on mingw (9ba8bd1481) - Bug 1256498. Explicitly convert to float. r=bas (ce97ef100e) - Bug 1223736 - Part 1: Set correct effective transform on mask layers. r=thinker (a87514ac4f) - Bug 1249813 - part 1 - revise nsShmImage to allow draw targets anywhere inside its bounds. r=jrmuizel (cba4cdf8c9) - Bug 1249813 - part 2 - make Cairo mark a surface as clear if clip covers entire surface. r=jrmuizel (45ccfcfc15) - Bug 1249813 - part 3 - tell the compositor if the root layer has opaque content so it can skip clears. r=mattwoodrow (2abaa0cf8b) - Bug 1255303 - Use SurfaceFormat::B8G8R8X8 as back buffer if possible r=jrmuizel (5f81a83123) - Bug 1253860 - Don't update the scrollbar unless we're actually painting. r=mstange (d3a2482408) - Bug 1253860 - Add a flag on scroll frames indicating if they have an APZ counterpart. r=mstange (2aef746ee1) - Bug 1253860 - Skip paints for main thread scrolls if we can ask APZ to handle the scrolling for us. r=mstange (4483da1f16) - Bug 1244116 - Telemetry for mixed content requests by plugins. r=smaug, p=ally (fd5f87f666) - Bug 1252829 - CSP Telemetry. r=ckerschb, p=bsmedberg (8d340fa824) - Bug 1246464: Add 'const' to some stylesheet args in nsDocument methods. r=heycam (4e744d81d2) - Bug 1255705 - Add some useful logging that can be enabled at compile time. r=botond (80f0202160) - Bug 1255856 - Don't allow paint-skipping if there are windowed plugins on the page. r=mstange,jimm (25e6d8ed22) - Bug 1256727 - Don't allow paint-skipping on pages with scroll-linked effects. r=mstange (a8bace52ff) - Bug 1247098 - Take document resolution into account when computing root composition bounds for displayport base. r=tnikkel (1b7b61c82e) - Bug 1250550 - Ensure a scroll event posted during a refresh driver tick fires during that same tick. r=mats (d5bfc24524) - Bug 1253739 - Fix incorrect namespace on forward declaration. r=botond (dfc7aac51e) - Bug 1253489 - Update SendFenceHandleIfPresent() r=nical (798c209dff) - Bug 1253860 - Stop APZC from reprocessing stale metrics on unrelated layer tree updates. r=botond (1013df0068) - Bug 1253860 - Add machinery to update APZ's scroll offset without a main-thread paint. r=botond (cb95baf9c6) - Bug 1239564 - Post translate maskSurface to renderTarget. r=roc (66c56d227d) - Bug 1223736 - Part 2: Draw masks in the correct coordinate space when doing 3d transforms in BasicCompositor. r=lsalzman (2d62616534) - Bug 1223736 - Part 3: Remove the distinction between 2d and 3d masks since it only adds complexity. r=Bas (61c2306875) - Bug 1137561 - Follow up VS2015 build error. r=masayuki (f12716a1ab) - Bug 1217275 Fix missing \n in IMMHandler::HandleDocumentFeed(), it was replaced to empty string accidentally r=m_kato (3315b1c270) - Bug 1243268 - Adjust ATOK workaround. r=masayuki (13af7184d1) - Bug 1242690 - If a drag block is interrupted by something else, have it create a new drag block when it resumes. r=rbarker (fe3dc8deac) - Bug 1242690 - Add untransforming of mouse events not in a drag block. r=rbarker (a39e715efe) - Bug 1241991 - Switch mTreeLock from a Monitor to a Mutex. r=kats (0eca284591) - Bug 1242690 - Further refine the mouse event untransformation code to only apply to events directed at a scrollbar. r=rbarker (5c92ca2807) - Bug 1251608 - Add a root-content annotation to the APZ test data structure. r=botond (a1ee8e496a) - Bug 1249748 - Ensure the mHandledByAPZ flag is set on WidgetTouchEvents that are handled by APZ. r=botond (11bdfae896) - Bug 1242690 - Don't apply the main-thread callback transform for events in a drag block. r=rbarker (3db1405b68) - Bug 1243589 - Use SingleTiledContentClient even for scrollable layers if the layer is smaller than a single tile. r=mattwoodrow (56bb664de1) - Bug 1250517 - Differentiate between no critical display port and empty critical display port in ClientTiledPaintedLayer; r=kats (1b809fac8e) - Bug 1255448 - Call ClientMultiTiledLayerBuffer::PaintThebes even when region to paint is empty. r=mattwoodrow (31ac878dc0) - Bug 1255907 - Fix unification build issues in APZ & Layers. r=kats (9829525402) - Bug 1256344 - If a long-press is interrupted by a non-touch block, don't dispatch the long-press event. r=botond (b3bdd0e58e) - Bug 1256341 - Guard against scenarios where GenerateSingleTap is called without an active touch block. r=botond (d4ec208407) - Bug 1230552 - Minor follow-up to add an assertion. rs=kats (6f9eec7bd4) - Bug 1247964 - Allow InputBlockState::SetScrolledApzc to accept new APZC when it is an ancestor of the current APZC r=kats # Please enter the commit message for your changes. Lines starting (08ce9cfa98) - Bug 1257264 - When apz.allow_immediate_handoff=false, APZ handoff should not occur when panning changes direction r=botond (6ec9ec22e6) - Bug 1250213 - Ensure the scroll offset does not go outside the page bounds when going full screen r=kats (ace8e8a80c) - Bug 1241332 - part 1, Request content repaint at end of APZ animation r=kats (74f7e249f2) - Bug 1255705 - Generalize the NotifyLayersUpdated short-circuit codepath to trigger on empty transactions as well. r=botond (0344d44844) - Bug 1250614 - Repeated zooming in bug on mobile Wikipedia site r=botond (459f02b8d3) - Bug 1251001 - Input fields at the bottom of a page do not pan into view when gaining focus. r=botond (770102bf9f) - Bug 1190093 (Comment Tweak) - Add better comments for nsIDocument::mIsShowing and mVisible. r=me DONTBUILD (e3822ef086) - Bug 1217226: P1. Use VideoInfo display size data rather than attempt to detect value in stream. r=cpearce (a4a7e9b19a) - Bug 1217226: P2. Implement WMFMediaDataDecoder::ConfigurationChanged. r=cpearce (52177525c5) - fix misspatch (61a694fe3d) - Bug 1249706: Added telemetry for the proportion of frames dropped keyed by several details. r=jya (cb459d971c) - Bug 1202296 - Recreate the MFTDecoder when we want to disable DXVA. r=cpearce (d82999e94f) - Bug 1176071 - Handle WMF MFTDecoder returning success but no output, with telemetry. r=mattwoodrow,r=vladan (da8017c92b) - align, cleanup (9a86d51dfd) - no bug - fix case of nsIDocShell.h in WindowsUIUtils.cpp (0ccabaa445) - Bug 1187724 Don't dispatch KeyboardEvents when the target of WM_APPCOMMAND is a windowed plug-in for preventing deadlock r=jimm (7b6d83559c) - Bug 1187178 - Use MOZ_WINSDK_MAXVER instead of #ifndef. r=jimm (06c949ddb9) - bits of Bug 1165515 - Part 13-2: Replace usage of PRLogModuleLevel (7beaa2dcc4) - Bug 1257791: Return correct DPI and printing scale from nsDeviceContextSpecWin when printing to PDF. r=jimm (87360301ea) - Bug 1242295 - Fix compile error in nsDeviceContextSpecWin. r=jimm (d1d4680319) - Bug 1229881 - fix off-by-one error in nsPrinterEnumeratorWin::GetPrinterNameList; r=dbaron; a=KWierso (439061ba50) - Bug 1239683 - Replace NS_UNCONSTRAINEDSIZE with NS_MAXSIZE in windows/nsWindow.cpp. r=mats (4135189bec) - Bug 1033488 - Send RTL information to child process by WM_INPUTLANGCHANGE. r=masayuki (eaf8f70d34) - Bug 1238137 - Telemetry pings for main thread touch scrolling (Windows only). r=kats (f2194a2965) - Bug 1156182 - Ensure nsWindow::Destroy() is called before destroying mPresentLock to avoid a race with the compositor thread. r=Bas (0452ffc641) - Bug 1173617. Don't cache titlebar caption sizes unless the widget has a titlebar. r=jimm (b29e190504) - Bug 580165 - Clean up dead code related to missing screen managers in widget. r=jimm (bf83f21ddc) - Bug 1256501: Fix warning C4312 with 64-bit VS2015 in widget/windows/nsWindow.cpp; r=jimm (635151964e) - Bug 1242690 - Squash together DispatchAPZAwareEvent and DispatchInputEvent. r=dvander (d7b4fea361) - Bug 1242616: Add break in nsWindow.cpp WM_GETOBJECT handling. r=tbsaunde (eb516d4119) - Bug 1239353 - Don't try to change DPI on the fly for popup windows, they remain connected to their parent's presShell and therefore need to share its resolution. r=emk (1491b84fd1) - Bug 1246389 - Resize window appropriately on WM_DPICHANGED messages for dynamic resolution changes. r=emk (f3dbfcdbb1) - Bug 1254019 - Don't attempt to resize a maximized window on DPI change; and when handling a DPI change, constrain the resized window to the screen bounds. r=emk (2047c2dcb5) - Bug 1252191 - use UniquePtr instead of ScopedFreePtr in PoisonIOInterposerMac.cpp; r=aklotz (7c26e55b76) - Bug 1233208: Disable IOInterposer on Beta and Release; r=froydnj (04a6f8b07c) - crashreporter (377572bbb1) - Bug 1055322 - The realloc for libnestegg should free with size 0. r=froydnj (ea624646ca) - Bug 1236789. Avoid creating an unnecessary thread pool thread for tail-dispatch in TaskQueue. r=bholley (e7fb9e4373) - Bug 1255655 - Const-ify named CIDs. r=froydnj. (03b414d92b) - Bug 1250396 (part 1) - Document a subtle contraint on nsIAtom. r=froydnj. (ff279149ac) - Bug 1250396 (part 2) - Remove nsStaticAtomStringType. r=froydnj. (5520507680) - Bug 1255343 - Stop returning nsresult from NS_RegisterStaticAtoms; r=ehsan (de1d387937) - Bug 1251495 - remove unnecessary Logging.h include from nsStaticAtom.h; r=erahm (5226a840fa)
571 lines
20 KiB
C++
571 lines
20 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/. */
|
|
|
|
/**
|
|
* A SurfacePipe is a pipeline that consists of a series of SurfaceFilters
|
|
* terminating in a SurfaceSink. Each SurfaceFilter transforms the image data in
|
|
* some way before the SurfaceSink ultimately writes it to the surface. This
|
|
* design allows for each transformation to be tested independently, for the
|
|
* transformations to be combined as needed to meet the needs of different
|
|
* situations, and for all image decoders to share the same code for these
|
|
* transformations.
|
|
*
|
|
* Writing to the SurfacePipe is done using lambdas that act as generator
|
|
* functions. Because the SurfacePipe machinery controls where the writes take
|
|
* place, a bug in an image decoder cannot cause a buffer overflow of the
|
|
* underlying surface. In particular, when using WritePixels() a buffer overflow
|
|
* is impossible as long as the SurfacePipe code is correct.
|
|
*/
|
|
|
|
#ifndef mozilla_image_SurfacePipe_h
|
|
#define mozilla_image_SurfacePipe_h
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "mozilla/Maybe.h"
|
|
#include "mozilla/Move.h"
|
|
#include "mozilla/UniquePtr.h"
|
|
#include "mozilla/unused.h"
|
|
#include "mozilla/Variant.h"
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
namespace mozilla {
|
|
namespace image {
|
|
|
|
class Decoder;
|
|
|
|
/**
|
|
* An invalid rect for a surface. Results are given both in the space of the
|
|
* input image (i.e., before any SurfaceFilters are applied) and in the space
|
|
* of the output surface (after all SurfaceFilters).
|
|
*/
|
|
struct SurfaceInvalidRect
|
|
{
|
|
gfx::IntRect mInputSpaceRect; /// The invalid rect in pre-SurfacePipe space.
|
|
gfx::IntRect mOutputSpaceRect; /// The invalid rect in post-SurfacePipe space.
|
|
};
|
|
|
|
/**
|
|
* An enum used to allow the lambdas passed to WritePixels() and WriteRows() to
|
|
* communicate their state to the caller.
|
|
*/
|
|
enum class WriteState : uint8_t
|
|
{
|
|
NEED_MORE_DATA, /// The lambda ran out of data.
|
|
|
|
FINISHED, /// The lambda is done writing to the surface; future writes
|
|
/// will fail.
|
|
|
|
FAILURE /// The lambda encountered an error. The caller may recover
|
|
/// if possible and continue to write. (This never indicates
|
|
/// an error in the SurfacePipe machinery itself; it's only
|
|
/// generated by the lambdas.)
|
|
};
|
|
|
|
/**
|
|
* A template alias used to make the return value of WritePixels() lambdas
|
|
* (which may return either a pixel value or a WriteState) easier to specify.
|
|
* WriteRows() doesn't need such a template alias since WriteRows() lambdas
|
|
* don't return a pixel value.
|
|
*/
|
|
template <typename PixelType>
|
|
using NextPixel = Variant<PixelType, WriteState>;
|
|
|
|
/**
|
|
* SurfaceFilter is the abstract superclass of SurfacePipe pipeline stages.
|
|
* It implements the the code that actually writes to the surface -
|
|
* WritePixels() and WriteRows() - which are non-virtual for efficiency.
|
|
*
|
|
* SurfaceFilter's API is nonpublic; only SurfacePipe and other SurfaceFilters
|
|
* should use it. Non-SurfacePipe code should use the methods on SurfacePipe.
|
|
*
|
|
* To implement a SurfaceFilter, it's necessary to subclass SurfaceFilter and
|
|
* implement, at a minimum, the pure virtual methods. It's also necessary to
|
|
* define a Config struct with a Filter typedef member that identifies the
|
|
* matching SurfaceFilter class, and a Configure() template method. See an
|
|
* existing SurfaceFilter subclass, such as RemoveFrameRectFilter, for an
|
|
* example of how the Configure() method must be implemented. It takes a list of
|
|
* Config structs, passes the tail of the list to the next filter in the chain's
|
|
* Configure() method, and then uses the head of the list to configure itself. A
|
|
* SurfaceFilter's Configure() method must also call
|
|
* SurfaceFilter::ConfigureFilter() to provide WritePixels() and WriteRows()
|
|
* with the information they need to do their jobs.
|
|
*/
|
|
class SurfaceFilter
|
|
{
|
|
public:
|
|
SurfaceFilter()
|
|
: mRowPointer(nullptr)
|
|
, mCol(0)
|
|
, mPixelSize(0)
|
|
{ }
|
|
|
|
virtual ~SurfaceFilter() { }
|
|
|
|
/**
|
|
* Reset this surface to the first row. It's legal for this filter to throw
|
|
* away any previously written data at this point, as all rows must be written
|
|
* to on every pass.
|
|
*
|
|
* @return a pointer to the buffer for the first row.
|
|
*/
|
|
uint8_t* ResetToFirstRow()
|
|
{
|
|
mCol = 0;
|
|
mRowPointer = DoResetToFirstRow();
|
|
return mRowPointer;
|
|
}
|
|
|
|
/// @return a pointer to the buffer for the current row.
|
|
uint8_t* CurrentRowPointer() const { return mRowPointer; }
|
|
|
|
/// @return true if we've finished writing to the surface.
|
|
bool IsSurfaceFinished() const { return mRowPointer == nullptr; }
|
|
|
|
/// @return the input size this filter expects.
|
|
gfx::IntSize InputSize() const { return mInputSize; }
|
|
|
|
/**
|
|
* Write pixels to the surface one at a time by repeatedly calling a lambda
|
|
* that yields pixels. WritePixels() should be preferred over WriteRows()
|
|
* whenever using it will not introduce additional copies or other performance
|
|
* penalties, because it is completely memory safe.
|
|
*
|
|
* Writing continues until every pixel in the surface has been written to
|
|
* (i.e., IsSurfaceFinished() returns true) or the lambda returns a WriteState
|
|
* which WritePixels() will return to the caller.
|
|
*
|
|
* The template parameter PixelType must be uint8_t (for paletted surfaces) or
|
|
* uint32_t (for BGRA/BGRX surfaces) and must be in agreement with the pixel
|
|
* size passed to ConfigureFilter().
|
|
*
|
|
* XXX(seth): We'll remove all support for paletted surfaces in bug 1247520,
|
|
* which means we can remove the PixelType template parameter from this
|
|
* method.
|
|
*
|
|
* @param aFunc A lambda that functions as a generator, yielding the next
|
|
* pixel in the surface each time it's called. The lambda must
|
|
* return a NextPixel<PixelType> value.
|
|
*
|
|
* @return A WriteState value indicating the lambda generator's state.
|
|
* WritePixels() itself will return WriteState::FINISHED if writing
|
|
* has finished, regardless of the lambda's internal state.
|
|
*/
|
|
template <typename PixelType, typename Func>
|
|
WriteState WritePixels(Func aFunc)
|
|
{
|
|
MOZ_ASSERT(mPixelSize == 1 || mPixelSize == 4);
|
|
MOZ_ASSERT_IF(mPixelSize == 1, sizeof(PixelType) == sizeof(uint8_t));
|
|
MOZ_ASSERT_IF(mPixelSize == 4, sizeof(PixelType) == sizeof(uint32_t));
|
|
|
|
while (!IsSurfaceFinished()) {
|
|
PixelType* rowPtr = reinterpret_cast<PixelType*>(mRowPointer);
|
|
|
|
for (; mCol < mInputSize.width; ++mCol) {
|
|
NextPixel<PixelType> result = aFunc();
|
|
if (result.template is<PixelType>()) {
|
|
rowPtr[mCol] = result.template as<PixelType>();
|
|
continue;
|
|
}
|
|
|
|
switch (result.template as<WriteState>()) {
|
|
case WriteState::NEED_MORE_DATA:
|
|
return WriteState::NEED_MORE_DATA;
|
|
|
|
case WriteState::FINISHED:
|
|
// Make sure that IsSurfaceFinished() returns true so the caller
|
|
// can't write anything else to the pipeline.
|
|
mRowPointer = nullptr;
|
|
mCol = 0;
|
|
return WriteState::FINISHED;
|
|
|
|
case WriteState::FAILURE:
|
|
// Note that we don't need to record this anywhere, because this
|
|
// indicates an error in aFunc, and there's nothing wrong with our
|
|
// machinery. The caller can recover as needed and continue writing to
|
|
// the row.
|
|
return WriteState::FAILURE;
|
|
}
|
|
}
|
|
|
|
// We've finished the row.
|
|
mRowPointer = AdvanceRow();
|
|
mCol = 0;
|
|
}
|
|
|
|
// We've finished the entire surface.
|
|
return WriteState::FINISHED;
|
|
}
|
|
|
|
/**
|
|
* Write rows to the surface one at a time by repeatedly calling a lambda
|
|
* that yields rows. Because WriteRows() is not completely memory safe,
|
|
* WritePixels() should be preferred whenever it can be used without
|
|
* introducing additional copies or other performance penalties.
|
|
*
|
|
* Writing continues until every row in the surface has been written to (i.e.,
|
|
* IsSurfaceFinished() returns true) or the lambda returns a WriteState which
|
|
* WriteRows() will return to the caller.
|
|
*
|
|
* The template parameter PixelType must be uint8_t (for paletted surfaces) or
|
|
* uint32_t (for BGRA/BGRX surfaces) and must be in agreement with the pixel
|
|
* size passed to ConfigureFilter().
|
|
*
|
|
* XXX(seth): We'll remove all support for paletted surfaces in bug 1247520,
|
|
* which means we can remove the PixelType template parameter from this
|
|
* method.
|
|
*
|
|
* @param aFunc A lambda that functions as a generator, yielding the next
|
|
* row in the surface each time it's called. The lambda must
|
|
* return a Maybe<WriteState> value; if Some(), the return value
|
|
* indicates a WriteState to return to the caller, while
|
|
* Nothing() indicates that the lambda can generate more rows.
|
|
*
|
|
* @return A WriteState value indicating the lambda generator's state.
|
|
* WriteRows() itself will return WriteState::FINISHED if writing
|
|
* has finished, regardless of the lambda's internal state.
|
|
*/
|
|
template <typename PixelType, typename Func>
|
|
WriteState WriteRows(Func aFunc)
|
|
{
|
|
MOZ_ASSERT(mPixelSize == 1 || mPixelSize == 4);
|
|
MOZ_ASSERT_IF(mPixelSize == 1, sizeof(PixelType) == sizeof(uint8_t));
|
|
MOZ_ASSERT_IF(mPixelSize == 4, sizeof(PixelType) == sizeof(uint32_t));
|
|
|
|
if (IsSurfaceFinished()) {
|
|
return WriteState::FINISHED; // Already done.
|
|
}
|
|
|
|
while (true) {
|
|
PixelType* rowPtr = reinterpret_cast<PixelType*>(mRowPointer);
|
|
|
|
Maybe<WriteState> result = aFunc(rowPtr, mInputSize.width);
|
|
if (result != Some(WriteState::FAILURE)) {
|
|
mCol = 0;
|
|
mRowPointer = AdvanceRow(); // We've finished the row.
|
|
}
|
|
|
|
if (IsSurfaceFinished()) {
|
|
break;
|
|
}
|
|
|
|
if (result == Some(WriteState::FINISHED)) {
|
|
// Make sure that IsSurfaceFinished() returns true so the caller can't
|
|
// write anything else to the pipeline.
|
|
mRowPointer = nullptr;
|
|
mCol = 0;
|
|
}
|
|
|
|
if (result) {
|
|
return *result;
|
|
}
|
|
}
|
|
|
|
// We've finished the entire surface.
|
|
return WriteState::FINISHED;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// Methods Subclasses Should Override
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// @return true if this SurfaceFilter can be used with paletted surfaces.
|
|
virtual bool IsValidPalettedPipe() const { return false; }
|
|
|
|
/**
|
|
* Called by WritePixels() and WriteRows() to advance this filter to the next
|
|
* row.
|
|
*
|
|
* @return a pointer to the buffer for the next row, or nullptr to indicate
|
|
* that we've finished the entire surface.
|
|
*/
|
|
virtual uint8_t* AdvanceRow() = 0;
|
|
|
|
/**
|
|
* @return a SurfaceInvalidRect representing the region of the surface that
|
|
* has been written to since the last time TakeInvalidRect() was
|
|
* called, or Nothing() if the region is empty (i.e. nothing has been
|
|
* written).
|
|
*/
|
|
virtual Maybe<SurfaceInvalidRect> TakeInvalidRect() = 0;
|
|
|
|
protected:
|
|
|
|
/**
|
|
* Called by ResetToFirstRow() to actually perform the reset. It's legal to
|
|
* throw away any previously written data at this point, as all rows must be
|
|
* written to on every pass.
|
|
*/
|
|
virtual uint8_t* DoResetToFirstRow() = 0;
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// Methods For Internal Use By Subclasses
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
* Called by subclasses' Configure() methods to initialize the configuration
|
|
* of this filter. After the filter is configured, calls ResetToFirstRow().
|
|
*
|
|
* @param aInputSize The input size of this filter, in pixels. The previous
|
|
* filter in the chain will expect to write into rows
|
|
* |aInputSize.width| pixels wide.
|
|
* @param aPixelSize How large, in bytes, each pixel in the surface is. This
|
|
* should be either 1 for paletted images or 4 for BGRA/BGRX
|
|
* images.
|
|
*/
|
|
void ConfigureFilter(gfx::IntSize aInputSize, uint8_t aPixelSize)
|
|
{
|
|
mInputSize = aInputSize;
|
|
mPixelSize = aPixelSize;
|
|
|
|
ResetToFirstRow();
|
|
}
|
|
|
|
private:
|
|
gfx::IntSize mInputSize; /// The size of the input this filter expects.
|
|
uint8_t* mRowPointer; /// Pointer to the current row or null if finished.
|
|
int32_t mCol; /// The current column we're writing to. (0-indexed)
|
|
uint8_t mPixelSize; /// How large each pixel in the surface is, in bytes.
|
|
};
|
|
|
|
class NullSurfaceSink;
|
|
|
|
/// A trivial configuration struct for NullSurfaceSink.
|
|
struct NullSurfaceConfig
|
|
{
|
|
using Filter = NullSurfaceSink;
|
|
};
|
|
|
|
/**
|
|
* NullSurfaceSink is a trivial SurfaceFilter implementation that behaves as if
|
|
* it were a zero-size SurfaceSink. It's used as the default filter chain for an
|
|
* uninitialized SurfacePipe.
|
|
*
|
|
* To avoid unnecessary allocations when creating SurfacePipe objects,
|
|
* NullSurfaceSink is a singleton. (This implies that the implementation must be
|
|
* stateless.)
|
|
*/
|
|
class NullSurfaceSink final : public SurfaceFilter
|
|
{
|
|
public:
|
|
/// Returns the singleton instance of NullSurfaceSink.
|
|
static NullSurfaceSink* Singleton();
|
|
|
|
virtual ~NullSurfaceSink() { }
|
|
|
|
nsresult Configure(const NullSurfaceConfig& aConfig);
|
|
|
|
Maybe<SurfaceInvalidRect> TakeInvalidRect() override { return Nothing(); }
|
|
uint8_t* AdvanceRow() override { return nullptr; }
|
|
|
|
protected:
|
|
uint8_t* DoResetToFirstRow() override { return nullptr; }
|
|
|
|
private:
|
|
static UniquePtr<NullSurfaceSink> sSingleton; /// The singleton instance.
|
|
};
|
|
|
|
|
|
/**
|
|
* SurfacePipe is the public API that decoders should use to interact with a
|
|
* SurfaceFilter pipeline.
|
|
*/
|
|
class SurfacePipe
|
|
{
|
|
public:
|
|
/// Initialize global state used by all SurfacePipes.
|
|
static void Initialize() { NullSurfaceSink::Singleton(); }
|
|
|
|
SurfacePipe()
|
|
: mHead(NullSurfaceSink::Singleton())
|
|
{ }
|
|
|
|
SurfacePipe(SurfacePipe&& aOther)
|
|
: mHead(Move(aOther.mHead))
|
|
{ }
|
|
|
|
~SurfacePipe()
|
|
{
|
|
// Ensure that we don't free the NullSurfaceSink singleton.
|
|
if (mHead.get() == NullSurfaceSink::Singleton()) {
|
|
Unused << mHead.release();
|
|
}
|
|
}
|
|
|
|
SurfacePipe& operator=(SurfacePipe&& aOther)
|
|
{
|
|
MOZ_ASSERT(this != &aOther);
|
|
|
|
// Ensure that we don't free the NullSurfaceSink singleton.
|
|
if (mHead.get() == NullSurfaceSink::Singleton()) {
|
|
Unused << mHead.release();
|
|
}
|
|
|
|
mHead = Move(aOther.mHead);
|
|
return *this;
|
|
}
|
|
|
|
/// Begins a new pass, seeking to the first row of the surface.
|
|
void ResetToFirstRow() { mHead->ResetToFirstRow(); }
|
|
|
|
/**
|
|
* Write pixels to the surface one at a time by repeatedly calling a lambda
|
|
* that yields pixels. WritePixels() should be preferred over WriteRows()
|
|
* whenever using it will not introduce additional copies or other performance
|
|
* penalties, because it is completely memory safe.
|
|
*
|
|
* @see SurfaceFilter::WritePixels() for the canonical documentation.
|
|
*/
|
|
template <typename PixelType, typename Func>
|
|
WriteState WritePixels(Func aFunc)
|
|
{
|
|
return mHead->WritePixels<PixelType>(Forward<Func>(aFunc));
|
|
}
|
|
|
|
/**
|
|
* Write rows to the surface one at a time by repeatedly calling a lambda
|
|
* that yields rows. Because WriteRows() is not completely memory safe,
|
|
* WritePixels() should be preferred whenever it can be used without
|
|
* introducing additional copies or other performance penalties.
|
|
*
|
|
* @see SurfaceFilter::WriteRows() for the canonical documentation.
|
|
*/
|
|
template <typename PixelType, typename Func>
|
|
WriteState WriteRows(Func aFunc)
|
|
{
|
|
return mHead->WriteRows<PixelType>(Forward<Func>(aFunc));
|
|
}
|
|
|
|
/// @return true if we've finished writing to the surface.
|
|
bool IsSurfaceFinished() const { return mHead->IsSurfaceFinished(); }
|
|
|
|
/// @see SurfaceFilter::TakeInvalidRect() for the canonical documentation.
|
|
Maybe<SurfaceInvalidRect> TakeInvalidRect() const
|
|
{
|
|
return mHead->TakeInvalidRect();
|
|
}
|
|
|
|
private:
|
|
friend class SurfacePipeFactory;
|
|
friend class TestSurfacePipeFactory;
|
|
|
|
explicit SurfacePipe(UniquePtr<SurfaceFilter>&& aHead)
|
|
: mHead(Move(aHead))
|
|
{ }
|
|
|
|
SurfacePipe(const SurfacePipe&) = delete;
|
|
SurfacePipe& operator=(const SurfacePipe&) = delete;
|
|
|
|
UniquePtr<SurfaceFilter> mHead; /// The first filter in the chain.
|
|
};
|
|
|
|
/**
|
|
* AbstractSurfaceSink contains shared implementation for both SurfaceSink and
|
|
* PalettedSurfaceSink.
|
|
*/
|
|
class AbstractSurfaceSink : public SurfaceFilter
|
|
{
|
|
public:
|
|
AbstractSurfaceSink()
|
|
: mImageData(nullptr)
|
|
, mImageDataLength(0)
|
|
, mRow(0)
|
|
, mFlipVertically(false)
|
|
{ }
|
|
|
|
Maybe<SurfaceInvalidRect> TakeInvalidRect() override final;
|
|
uint8_t* AdvanceRow() override final;
|
|
|
|
protected:
|
|
uint8_t* DoResetToFirstRow() override final;
|
|
virtual uint8_t* GetRowPointer() const = 0;
|
|
|
|
gfx::IntRect mInvalidRect; /// The region of the surface that has been written
|
|
/// to since the last call to TakeInvalidRect().
|
|
uint8_t* mImageData; /// A pointer to the beginning of the surface data.
|
|
uint32_t mImageDataLength; /// The length of the surface data.
|
|
uint32_t mRow; /// The row to which we're writing. (0-indexed)
|
|
bool mFlipVertically; /// If true, write the rows from top to bottom.
|
|
};
|
|
|
|
class SurfaceSink;
|
|
|
|
/// A configuration struct for SurfaceSink.
|
|
struct SurfaceConfig
|
|
{
|
|
using Filter = SurfaceSink;
|
|
Decoder* mDecoder; /// Which Decoder to use to allocate the surface.
|
|
uint32_t mFrameNum; /// Which frame of animation this surface is for.
|
|
gfx::IntSize mOutputSize; /// The size of the surface.
|
|
gfx::SurfaceFormat mFormat; /// The surface format (BGRA or BGRX).
|
|
bool mFlipVertically; /// If true, write the rows from bottom to top.
|
|
};
|
|
|
|
/**
|
|
* A sink for normal (i.e., non-paletted) surfaces. It handles the allocation of
|
|
* the surface and protects against buffer overflow. This sink should be used
|
|
* for all non-animated images and for the first frame of animated images.
|
|
*
|
|
* Sinks must always be at the end of the SurfaceFilter chain.
|
|
*/
|
|
class SurfaceSink final : public AbstractSurfaceSink
|
|
{
|
|
public:
|
|
nsresult Configure(const SurfaceConfig& aConfig);
|
|
|
|
protected:
|
|
uint8_t* GetRowPointer() const override;
|
|
};
|
|
|
|
class PalettedSurfaceSink;
|
|
|
|
struct PalettedSurfaceConfig
|
|
{
|
|
using Filter = PalettedSurfaceSink;
|
|
Decoder* mDecoder; /// Which Decoder to use to allocate the surface.
|
|
uint32_t mFrameNum; /// Which frame of animation this surface is for.
|
|
gfx::IntSize mOutputSize; /// The logical size of the surface.
|
|
gfx::IntRect mFrameRect; /// The surface subrect which contains data.
|
|
gfx::SurfaceFormat mFormat; /// The surface format (BGRA or BGRX).
|
|
uint8_t mPaletteDepth; /// The palette depth of this surface.
|
|
bool mFlipVertically; /// If true, write the rows from bottom to top.
|
|
};
|
|
|
|
/**
|
|
* A sink for paletted surfaces. It handles the allocation of the surface and
|
|
* protects against buffer overflow. This sink can be used for frames of
|
|
* animated images except the first.
|
|
*
|
|
* Sinks must always be at the end of the SurfaceFilter chain.
|
|
*
|
|
* XXX(seth): We'll remove all support for paletted surfaces in bug 1247520,
|
|
* which means we can remove PalettedSurfaceSink entirely.
|
|
*/
|
|
class PalettedSurfaceSink final : public AbstractSurfaceSink
|
|
{
|
|
public:
|
|
bool IsValidPalettedPipe() const override { return true; }
|
|
|
|
nsresult Configure(const PalettedSurfaceConfig& aConfig);
|
|
|
|
protected:
|
|
uint8_t* GetRowPointer() const override;
|
|
|
|
private:
|
|
/**
|
|
* The surface subrect which contains data. Note that the surface size we
|
|
* actually allocate is the size of the frame rect, not the logical size of
|
|
* the surface.
|
|
*/
|
|
gfx::IntRect mFrameRect;
|
|
};
|
|
|
|
} // namespace image
|
|
} // namespace mozilla
|
|
|
|
#endif // mozilla_image_SurfacePipe_h
|