зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 0ded74baeaf2 (bug 1340627) for blocking m-i to m-c merge
--HG-- rename : gfx/skia/skia/src/core/SkBlitRow.h => gfx/skia/skia/include/core/SkBlitRow.h rename : gfx/skia/skia/src/effects/SkGaussianEdgeShader.h => gfx/skia/skia/include/effects/SkGaussianEdgeShader.h rename : gfx/skia/skia/src/xml/SkXMLParser.h => gfx/skia/skia/include/xml/SkXMLParser.h rename : gfx/skia/skia/include/private/SkMessageBus.h => gfx/skia/skia/src/core/SkMessageBus.h rename : gfx/skia/skia/src/gpu/ops/GrAAConvexPathRenderer.h => gfx/skia/skia/src/gpu/batches/GrAAConvexPathRenderer.h rename : gfx/skia/skia/src/gpu/ops/GrAAConvexTessellator.h => gfx/skia/skia/src/gpu/batches/GrAAConvexTessellator.h rename : gfx/skia/skia/src/gpu/ops/GrAAHairLinePathRenderer.h => gfx/skia/skia/src/gpu/batches/GrAAHairLinePathRenderer.h rename : gfx/skia/skia/src/gpu/ops/GrAALinearizingConvexPathRenderer.h => gfx/skia/skia/src/gpu/batches/GrAALinearizingConvexPathRenderer.h rename : gfx/skia/skia/src/gpu/ops/GrPathStencilSettings.h => gfx/skia/skia/src/gpu/batches/GrPathStencilSettings.h rename : gfx/skia/skia/src/gpu/ops/GrStencilAndCoverPathRenderer.h => gfx/skia/skia/src/gpu/batches/GrStencilAndCoverPathRenderer.h rename : gfx/skia/skia/include/private/GrGLSL_impl.h => gfx/skia/skia/src/gpu/glsl/GrGLSL_impl.h
This commit is contained in:
Родитель
d6dc2abb78
Коммит
2e978e4438
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include "SkBitmap.h"
|
||||
#include "SkBRDAllocator.h"
|
||||
#include "SkEncodedImageFormat.h"
|
||||
#include "SkEncodedFormat.h"
|
||||
#include "SkStream.h"
|
||||
|
||||
/*
|
||||
|
@ -55,21 +55,18 @@ public:
|
|||
* if this color type is unsupported.
|
||||
* @param requireUnpremul If the image is not opaque, we will use this to determine the
|
||||
* alpha type to use.
|
||||
* @param prefColorSpace If non-null and supported, this is the color space that we will
|
||||
* decode into. Otherwise, we will choose a default.
|
||||
*
|
||||
*/
|
||||
virtual bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
|
||||
const SkIRect& desiredSubset, int sampleSize,
|
||||
SkColorType colorType, bool requireUnpremul,
|
||||
sk_sp<SkColorSpace> prefColorSpace = nullptr) = 0;
|
||||
SkColorType colorType, bool requireUnpremul) = 0;
|
||||
/*
|
||||
* @param Requested destination color type
|
||||
* @return true if we support the requested color type and false otherwise
|
||||
*/
|
||||
virtual bool conversionSupported(SkColorType colorType) = 0;
|
||||
|
||||
virtual SkEncodedImageFormat getEncodedFormat() = 0;
|
||||
virtual SkEncodedFormat getEncodedFormat() = 0;
|
||||
|
||||
int width() const { return fWidth; }
|
||||
int height() const { return fHeight; }
|
||||
|
|
|
@ -0,0 +1,501 @@
|
|||
|
||||
/*
|
||||
* Copyright 2006 The Android Open Source Project
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SkAnimator_DEFINED
|
||||
#define SkAnimator_DEFINED
|
||||
|
||||
#include "SkScalar.h"
|
||||
#include "SkKey.h"
|
||||
#include "SkEventSink.h"
|
||||
|
||||
class SkAnimateMaker;
|
||||
class SkCanvas;
|
||||
class SkDisplayable;
|
||||
class SkEvent;
|
||||
class SkExtras;
|
||||
struct SkMemberInfo;
|
||||
class SkPaint;
|
||||
struct SkRect;
|
||||
class SkStream;
|
||||
class SkTypedArray;
|
||||
class SkXMLParserError;
|
||||
class SkDOM;
|
||||
struct SkDOMNode;
|
||||
|
||||
/** SkElementType is the type of element: a rectangle, a color, an animator, and so on.
|
||||
This enum is incomplete and will be fleshed out in a future release */
|
||||
enum SkElementType {
|
||||
kElementDummyType
|
||||
};
|
||||
/** SkFieldType is the type of field: a scalar, a string, an integer, a boolean, and so on.
|
||||
This enum is incomplete and will be fleshed out in a future release */
|
||||
enum SkFieldType {
|
||||
kFieldDummyType
|
||||
};
|
||||
|
||||
/** \class SkAnimator
|
||||
|
||||
The SkAnimator class decodes an XML stream into a display list. The
|
||||
display list can be drawn statically as a picture, or can drawn
|
||||
different elements at different times to form a moving animation.
|
||||
|
||||
SkAnimator does not read the system time on its own; it relies on the
|
||||
caller to pass the current time. The caller can pause, speed up, or
|
||||
reverse the animation by varying the time passed in.
|
||||
|
||||
The XML describing the display list must conform to the schema
|
||||
described by SkAnimateSchema.xsd.
|
||||
|
||||
The XML must contain an <event> element to draw. Usually, it contains
|
||||
an <event kind="onload" /> block to add some drawing elements to the
|
||||
display list when the document is first decoded.
|
||||
|
||||
Here's an "Hello World" XML sample:
|
||||
|
||||
<screenplay>
|
||||
<event kind="onload" >
|
||||
<text text="Hello World" y="20" />
|
||||
</event>
|
||||
</screenplay>
|
||||
|
||||
To read and draw this sample:
|
||||
|
||||
// choose one of these two
|
||||
SkAnimator animator; // declare an animator instance on the stack
|
||||
// SkAnimator* animator = new SkAnimator() // or one could instantiate the class
|
||||
|
||||
// choose one of these three
|
||||
animator.decodeMemory(buffer, size); // to read from RAM
|
||||
animator.decodeStream(stream); // to read from a user-defined stream (e.g., a zip file)
|
||||
animator.decodeURI(filename); // to read from a web location, or from a local text file
|
||||
|
||||
// to draw to the current window:
|
||||
SkCanvas canvas(getBitmap()); // create a canvas
|
||||
animator.draw(canvas, &paint, 0); // draw the scene
|
||||
*/
|
||||
class SkAnimator : public SkEventSink {
|
||||
public:
|
||||
SkAnimator();
|
||||
virtual ~SkAnimator();
|
||||
|
||||
/** Add a drawable extension to the graphics engine. Experimental.
|
||||
@param extras A derived class that implements methods that identify and instantiate the class
|
||||
*/
|
||||
void addExtras(SkExtras* extras);
|
||||
|
||||
/** Read in XML from a stream, and append it to the current
|
||||
animator. Returns false if an error was encountered.
|
||||
Error diagnostics are stored in fErrorCode and fLineNumber.
|
||||
@param stream The stream to append.
|
||||
@return true if the XML was parsed successfully.
|
||||
*/
|
||||
bool appendStream(SkStream* stream);
|
||||
|
||||
/** Read in XML from memory. Returns true if the file can be
|
||||
read without error. Returns false if an error was encountered.
|
||||
Error diagnostics are stored in fErrorCode and fLineNumber.
|
||||
@param buffer The XML text as UTF-8 characters.
|
||||
@param size The XML text length in bytes.
|
||||
@return true if the XML was parsed successfully.
|
||||
*/
|
||||
bool decodeMemory(const void* buffer, size_t size);
|
||||
|
||||
/** Read in XML from a stream. Returns true if the file can be
|
||||
read without error. Returns false if an error was encountered.
|
||||
Error diagnostics are stored in fErrorCode and fLineNumber.
|
||||
@param stream The stream containg the XML text as UTF-8 characters.
|
||||
@return true if the XML was parsed successfully.
|
||||
*/
|
||||
virtual bool decodeStream(SkStream* stream);
|
||||
|
||||
/** Parse the DOM tree starting at the specified node. Returns true if it can be
|
||||
parsed without error. Returns false if an error was encountered.
|
||||
Error diagnostics are stored in fErrorCode and fLineNumber.
|
||||
@return true if the DOM was parsed successfully.
|
||||
*/
|
||||
virtual bool decodeDOM(const SkDOM&, const SkDOMNode*);
|
||||
|
||||
/** Read in XML from a URI. Returns true if the file can be
|
||||
read without error. Returns false if an error was encountered.
|
||||
Error diagnostics are stored in fErrorCode and fLineNumber.
|
||||
@param uri The complete url path to be read (either ftp, http or https).
|
||||
@return true if the XML was parsed successfully.
|
||||
*/
|
||||
bool decodeURI(const char uri[]);
|
||||
|
||||
/** Pass a char event, usually a keyboard symbol, to the animator.
|
||||
This triggers events of the form <event kind="keyChar" key="... />
|
||||
@param ch The character to match against <event> element "key"
|
||||
attributes.
|
||||
@return true if the event was dispatched successfully.
|
||||
*/
|
||||
bool doCharEvent(SkUnichar ch);
|
||||
|
||||
/** Experimental:
|
||||
Pass a mouse click event along with the mouse coordinates to
|
||||
the animator. This triggers events of the form <event kind="mouseDown" ... />
|
||||
and other mouse events.
|
||||
@param state The mouse state, described by SkView::Click::State : values are
|
||||
down == 0, moved == 1, up == 2
|
||||
@param x The x-position of the mouse
|
||||
@param y The y-position of the mouse
|
||||
@return true if the event was dispatched successfully.
|
||||
*/
|
||||
bool doClickEvent(int state, SkScalar x, SkScalar y);
|
||||
|
||||
/** Pass a meta-key event, such as an arrow , to the animator.
|
||||
This triggers events of the form <event kind="keyPress" code="... />
|
||||
@param code The key to match against <event> element "code"
|
||||
attributes.
|
||||
@return true if the event was dispatched successfully.
|
||||
*/
|
||||
bool doKeyEvent(SkKey code);
|
||||
bool doKeyUpEvent(SkKey code);
|
||||
|
||||
/** Send an event to the animator. The animator's clock is set
|
||||
relative to the current time.
|
||||
@return true if the event was dispatched successfully.
|
||||
*/
|
||||
bool doUserEvent(const SkEvent& evt);
|
||||
|
||||
/** The possible results from the draw function.
|
||||
*/
|
||||
enum DifferenceType {
|
||||
kNotDifferent,
|
||||
kDifferent,
|
||||
kPartiallyDifferent
|
||||
};
|
||||
/** Draws one frame of the animation. The first call to draw always
|
||||
draws the initial frame of the animation. Subsequent calls draw
|
||||
the offset into the animation by
|
||||
subtracting the initial time from the current time.
|
||||
@param canvas The canvas to draw into.
|
||||
@param paint The paint to draw with.
|
||||
@param time The offset into the current animation.
|
||||
@return kNotDifferent if there are no active animations; kDifferent if there are active animations; and
|
||||
kPartiallyDifferent if the document contains an active <bounds> element that specifies a minimal
|
||||
redraw area.
|
||||
*/
|
||||
DifferenceType draw(SkCanvas* canvas, SkPaint* paint, SkMSec time);
|
||||
|
||||
/** Draws one frame of the animation, using a new Paint each time.
|
||||
The first call to draw always
|
||||
draws the initial frame of the animation. Subsequent calls draw
|
||||
the offset into the animation by
|
||||
subtracting the initial time from the current time.
|
||||
@param canvas The canvas to draw into.
|
||||
@param time The offset into the current animation.
|
||||
@return kNotDifferent if there are no active animations; kDifferent if there are active animations; and
|
||||
kPartiallyDifferent if the document contains an active <bounds> element that specifies a minimal
|
||||
redraw area.
|
||||
*/
|
||||
DifferenceType draw(SkCanvas* canvas, SkMSec time);
|
||||
|
||||
/** Experimental:
|
||||
Helper to choose whether to return a SkView::Click handler.
|
||||
@param x ignored
|
||||
@param y ignored
|
||||
@return true if a mouseDown event handler is enabled.
|
||||
*/
|
||||
bool findClickEvent(SkScalar x, SkScalar y);
|
||||
|
||||
|
||||
/** Get the nested animator associated with this element, if any.
|
||||
Use this to access a movie's event sink, to send events to movies.
|
||||
@param element the value returned by getElement
|
||||
@return the internal animator.
|
||||
*/
|
||||
const SkAnimator* getAnimator(const SkDisplayable* element) const;
|
||||
|
||||
/** Returns the scalar value of the specified element's attribute[index]
|
||||
@param element the value returned by getElement
|
||||
@param field the value returned by getField
|
||||
@param index the array entry
|
||||
@return the integer value to retrieve, or SK_NaN32 if unsuccessful
|
||||
*/
|
||||
int32_t getArrayInt(const SkDisplayable* element, const SkMemberInfo* field, int index);
|
||||
|
||||
/** Returns the scalar value of the specified element's attribute[index]
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@param fieldName specifies the name of the attribute
|
||||
@param index the array entry
|
||||
@return the integer value to retrieve, or SK_NaN32 if unsuccessful
|
||||
*/
|
||||
int32_t getArrayInt(const char* elementID, const char* fieldName, int index);
|
||||
|
||||
/** Returns the scalar value of the specified element's attribute[index]
|
||||
@param element the value returned by getElement
|
||||
@param field the value returned by getField
|
||||
@param index the array entry
|
||||
@return the scalar value to retrieve, or SK_ScalarNaN if unsuccessful
|
||||
*/
|
||||
SkScalar getArrayScalar(const SkDisplayable* element, const SkMemberInfo* field, int index);
|
||||
|
||||
/** Returns the scalar value of the specified element's attribute[index]
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@param fieldName specifies the name of the attribute
|
||||
@param index the array entry
|
||||
@return the scalar value to retrieve, or SK_ScalarNaN if unsuccessful
|
||||
*/
|
||||
SkScalar getArrayScalar(const char* elementID, const char* fieldName, int index);
|
||||
|
||||
/** Returns the string value of the specified element's attribute[index]
|
||||
@param element is a value returned by getElement
|
||||
@param field is a value returned by getField
|
||||
@param index the array entry
|
||||
@return the string value to retrieve, or null if unsuccessful
|
||||
*/
|
||||
const char* getArrayString(const SkDisplayable* element, const SkMemberInfo* field, int index);
|
||||
|
||||
/** Returns the string value of the specified element's attribute[index]
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@param fieldName specifies the name of the attribute
|
||||
@param index the array entry
|
||||
@return the string value to retrieve, or null if unsuccessful
|
||||
*/
|
||||
const char* getArrayString(const char* elementID, const char* fieldName, int index);
|
||||
|
||||
/** Returns the XML element corresponding to the given ID.
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@return the element matching the ID, or null if the element can't be found
|
||||
*/
|
||||
const SkDisplayable* getElement(const char* elementID);
|
||||
|
||||
/** Returns the element type corresponding to the XML element.
|
||||
The element type matches the element name; for instance, <line> returns kElement_LineType
|
||||
@param element is a value returned by getElement
|
||||
@return element type, or 0 if the element can't be found
|
||||
*/
|
||||
SkElementType getElementType(const SkDisplayable* element);
|
||||
|
||||
/** Returns the element type corresponding to the given ID.
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@return element type, or 0 if the element can't be found
|
||||
*/
|
||||
SkElementType getElementType(const char* elementID);
|
||||
|
||||
/** Returns the XML field of the named attribute in the XML element.
|
||||
@param element is a value returned by getElement
|
||||
@param fieldName is the attribute to return
|
||||
@return the attribute matching the fieldName, or null if the element can't be found
|
||||
*/
|
||||
const SkMemberInfo* getField(const SkDisplayable* element, const char* fieldName);
|
||||
|
||||
/** Returns the XML field of the named attribute in the XML element matching the elementID.
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@param fieldName is the attribute to return
|
||||
@return the attribute matching the fieldName, or null if the element can't be found
|
||||
*/
|
||||
const SkMemberInfo* getField(const char* elementID, const char* fieldName);
|
||||
|
||||
/** Returns the value type coresponding to the element's attribute.
|
||||
The value type matches the XML schema: and may be kField_BooleanType, kField_ScalarType, etc.
|
||||
@param field is a value returned by getField
|
||||
@return the attribute type, or 0 if the element can't be found
|
||||
*/
|
||||
SkFieldType getFieldType(const SkMemberInfo* field);
|
||||
|
||||
/** Returns the value type coresponding to the element's attribute.
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@param fieldName specifies the name of the attribute
|
||||
@return the attribute type, or 0 if the element can't be found
|
||||
*/
|
||||
SkFieldType getFieldType(const char* elementID, const char* fieldName);
|
||||
|
||||
/** Returns the recommended animation interval. Returns zero if no
|
||||
interval is specified.
|
||||
*/
|
||||
SkMSec getInterval();
|
||||
|
||||
/** Returns the partial rectangle to invalidate after drawing. Call after draw() returns
|
||||
kIsPartiallyDifferent to do a mimimal inval(). */
|
||||
void getInvalBounds(SkRect* inval);
|
||||
|
||||
/** Returns the details of any error encountered while parsing the XML.
|
||||
*/
|
||||
const SkXMLParserError* getParserError();
|
||||
|
||||
/** Returns the details of any error encountered while parsing the XML as string.
|
||||
*/
|
||||
const char* getParserErrorString();
|
||||
|
||||
/** Returns the scalar value of the specified element's attribute
|
||||
@param element is a value returned by getElement
|
||||
@param field is a value returned by getField
|
||||
@return the integer value to retrieve, or SK_NaN32 if not found
|
||||
*/
|
||||
int32_t getInt(const SkDisplayable* element, const SkMemberInfo* field);
|
||||
|
||||
/** Returns the scalar value of the specified element's attribute
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@param fieldName specifies the name of the attribute
|
||||
@return the integer value to retrieve, or SK_NaN32 if not found
|
||||
*/
|
||||
int32_t getInt(const char* elementID, const char* fieldName);
|
||||
|
||||
/** Returns the scalar value of the specified element's attribute
|
||||
@param element is a value returned by getElement
|
||||
@param field is a value returned by getField
|
||||
@return the scalar value to retrieve, or SK_ScalarNaN if not found
|
||||
*/
|
||||
SkScalar getScalar(const SkDisplayable* element, const SkMemberInfo* field);
|
||||
|
||||
/** Returns the scalar value of the specified element's attribute
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@param fieldName specifies the name of the attribute
|
||||
@return the scalar value to retrieve, or SK_ScalarNaN if not found
|
||||
*/
|
||||
SkScalar getScalar(const char* elementID, const char* fieldName);
|
||||
|
||||
/** Returns the string value of the specified element's attribute
|
||||
@param element is a value returned by getElement
|
||||
@param field is a value returned by getField
|
||||
@return the string value to retrieve, or null if not found
|
||||
*/
|
||||
const char* getString(const SkDisplayable* element, const SkMemberInfo* field);
|
||||
|
||||
/** Returns the string value of the specified element's attribute
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@param fieldName specifies the name of the attribute
|
||||
@return the string value to retrieve, or null if not found
|
||||
*/
|
||||
const char* getString(const char* elementID, const char* fieldName);
|
||||
|
||||
/** Gets the file default directory of the URL base path set explicitly or by reading the last URL. */
|
||||
const char* getURIBase();
|
||||
|
||||
/** Resets the animator to a newly created state with no animation data. */
|
||||
void initialize();
|
||||
|
||||
/** Experimental. Resets any active animations so that the next time passed is treated as
|
||||
time zero. */
|
||||
void reset();
|
||||
|
||||
/** Sets the scalar value of the specified element's attribute
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@param fieldName specifies the name of the attribute
|
||||
@param array is the c-style array of integers
|
||||
@param count is the length of the array
|
||||
@return true if the value was set successfully
|
||||
*/
|
||||
bool setArrayInt(const char* elementID, const char* fieldName, const int* array, int count);
|
||||
|
||||
/** Sets the scalar value of the specified element's attribute
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@param fieldName specifies the name of the attribute
|
||||
@param array is the c-style array of strings
|
||||
@param count is the length of the array
|
||||
@return true if the value was set successfully
|
||||
*/
|
||||
bool setArrayString(const char* elementID, const char* fieldName, const char** array, int count);
|
||||
|
||||
/** Sets the scalar value of the specified element's attribute
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@param fieldName specifies the name of the attribute
|
||||
@param data the integer value to set
|
||||
@return true if the value was set successfully
|
||||
*/
|
||||
bool setInt(const char* elementID, const char* fieldName, int32_t data);
|
||||
|
||||
/** Sets the scalar value of the specified element's attribute
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@param fieldName specifies the name of the attribute
|
||||
@param data the scalar value to set
|
||||
@return true if the value was set successfully
|
||||
*/
|
||||
bool setScalar(const char* elementID, const char* fieldName, SkScalar data);
|
||||
|
||||
/** Sets the string value of the specified element's attribute
|
||||
@param elementID is the value of the id attribute in the XML of this element
|
||||
@param fieldName specifies the name of the attribute
|
||||
@param data the string value to set
|
||||
@return true if the value was set successfully
|
||||
*/
|
||||
bool setString(const char* elementID, const char* fieldName, const char* data);
|
||||
|
||||
/** Sets the file default directory of the URL base path
|
||||
@param path the directory path
|
||||
*/
|
||||
void setURIBase(const char* path);
|
||||
|
||||
typedef void* Handler;
|
||||
// This guy needs to be exported to java, so don't make it virtual
|
||||
void setHostHandler(Handler handler) {
|
||||
this->onSetHostHandler(handler);
|
||||
}
|
||||
|
||||
/** \class Timeline
|
||||
Returns current time to animator. To return a custom timeline, create a child
|
||||
class and override the getMSecs method.
|
||||
*/
|
||||
class Timeline {
|
||||
public:
|
||||
virtual ~Timeline() {}
|
||||
|
||||
/** Returns the current time in milliseconds */
|
||||
virtual SkMSec getMSecs() const = 0;
|
||||
};
|
||||
|
||||
/** Sets a user class to return the current time to the animator.
|
||||
Optional; if not called, the system clock will be used by calling
|
||||
SkEvent::GetMSecsSinceStartup instead.
|
||||
@param callBack the time function
|
||||
*/
|
||||
void setTimeline(const Timeline& );
|
||||
|
||||
static void Init(bool runUnitTests);
|
||||
static void Term();
|
||||
|
||||
/** The event sink events generated by the animation are posted to.
|
||||
Screenplay also posts an inval event to this event sink after processing an
|
||||
event to force a redraw.
|
||||
@param target the event sink id
|
||||
*/
|
||||
void setHostEventSinkID(SkEventSinkID hostID);
|
||||
SkEventSinkID getHostEventSinkID() const;
|
||||
|
||||
// helper
|
||||
void setHostEventSink(SkEventSink* sink) {
|
||||
this->setHostEventSinkID(sink ? sink->getSinkID() : 0);
|
||||
}
|
||||
|
||||
virtual void setJavaOwner(Handler owner);
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
virtual void eventDone(const SkEvent& evt);
|
||||
virtual bool isTrackingEvents();
|
||||
static bool NoLeaks();
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual void onSetHostHandler(Handler handler);
|
||||
virtual void onEventPost(SkEvent*, SkEventSinkID);
|
||||
virtual void onEventPostTime(SkEvent*, SkEventSinkID, SkMSec time);
|
||||
|
||||
private:
|
||||
// helper functions for setters
|
||||
bool setArray(SkDisplayable* element, const SkMemberInfo* field, SkTypedArray array);
|
||||
bool setArray(const char* elementID, const char* fieldName, SkTypedArray array);
|
||||
bool setInt(SkDisplayable* element, const SkMemberInfo* field, int32_t data);
|
||||
bool setScalar(SkDisplayable* element, const SkMemberInfo* field, SkScalar data);
|
||||
bool setString(SkDisplayable* element, const SkMemberInfo* field, const char* data);
|
||||
|
||||
virtual bool onEvent(const SkEvent&);
|
||||
SkAnimateMaker* fMaker;
|
||||
friend class SkAnimateMaker;
|
||||
friend class SkAnimatorScript;
|
||||
friend class SkAnimatorScript2;
|
||||
friend class SkApply;
|
||||
friend class SkDisplayMovie;
|
||||
friend class SkDisplayType;
|
||||
friend class SkPost;
|
||||
friend class SkXMLAnimatorWriter;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,39 @@
|
|||
|
||||
/*
|
||||
* Copyright 2006 The Android Open Source Project
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SkAnimatorView_DEFINED
|
||||
#define SkAnimatorView_DEFINED
|
||||
|
||||
#include "SkView.h"
|
||||
#include "SkAnimator.h"
|
||||
|
||||
class SkAnimatorView : public SkView {
|
||||
public:
|
||||
SkAnimatorView();
|
||||
virtual ~SkAnimatorView();
|
||||
|
||||
SkAnimator* getAnimator() const { return fAnimator; }
|
||||
|
||||
bool decodeFile(const char path[]);
|
||||
bool decodeMemory(const void* buffer, size_t size);
|
||||
bool decodeStream(SkStream* stream);
|
||||
|
||||
protected:
|
||||
// overrides
|
||||
virtual bool onEvent(const SkEvent&);
|
||||
virtual void onDraw(SkCanvas*);
|
||||
virtual void onInflate(const SkDOM&, const SkDOM::Node*);
|
||||
|
||||
private:
|
||||
SkAnimator* fAnimator;
|
||||
|
||||
typedef SkView INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -19,7 +19,7 @@ SK_C_PLUS_PLUS_BEGIN_GUARD
|
|||
Returns a new empty sk_data_t. This call must be balanced with a call to
|
||||
sk_data_unref().
|
||||
*/
|
||||
SK_API sk_data_t* sk_data_new_empty(void);
|
||||
SK_API sk_data_t* sk_data_new_empty();
|
||||
/**
|
||||
Returns a new sk_data_t by copying the specified source data.
|
||||
This call must be balanced with a call to sk_data_unref().
|
||||
|
|
|
@ -28,7 +28,7 @@ SK_C_PLUS_PLUS_BEGIN_GUARD
|
|||
maskfilter : NULL
|
||||
xfermode_mode : SRCOVER_SK_XFERMODE_MODE
|
||||
*/
|
||||
SK_API sk_paint_t* sk_paint_new(void);
|
||||
SK_API sk_paint_t* sk_paint_new();
|
||||
/**
|
||||
Release the memory storing the sk_paint_t and unref() all
|
||||
associated objects.
|
||||
|
|
|
@ -21,7 +21,7 @@ typedef enum {
|
|||
} sk_path_direction_t;
|
||||
|
||||
/** Create a new, empty path. */
|
||||
SK_API sk_path_t* sk_path_new(void);
|
||||
SK_API sk_path_t* sk_path_new();
|
||||
/** Release the memory used by a sk_path_t. */
|
||||
SK_API void sk_path_delete(sk_path_t*);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ SK_C_PLUS_PLUS_BEGIN_GUARD
|
|||
Create a new sk_picture_recorder_t. Its resources should be
|
||||
released with a call to sk_picture_recorder_delete().
|
||||
*/
|
||||
sk_picture_recorder_t* sk_picture_recorder_new(void);
|
||||
sk_picture_recorder_t* sk_picture_recorder_new();
|
||||
/**
|
||||
Release the memory and other resources used by this
|
||||
sk_picture_recorder_t.
|
||||
|
|
|
@ -81,7 +81,7 @@ typedef enum {
|
|||
/**
|
||||
Return the default sk_colortype_t; this is operating-system dependent.
|
||||
*/
|
||||
SK_API sk_colortype_t sk_colortype_get_default_8888(void);
|
||||
SK_API sk_colortype_t sk_colortype_get_default_8888();
|
||||
|
||||
typedef struct {
|
||||
int32_t width;
|
||||
|
@ -113,59 +113,6 @@ typedef struct {
|
|||
float bottom;
|
||||
} sk_rect_t;
|
||||
|
||||
/**
|
||||
The sk_matrix_t struct holds a 3x3 perspective matrix for
|
||||
transforming coordinates:
|
||||
|
||||
(X,Y) = T[M]((x,y))
|
||||
X = (M[0] * x + M[1] * y + M[2]) / (M[6] * x + M[7] * y + M[8]);
|
||||
Y = (M[3] * x + M[4] * y + M[5]) / (M[6] * x + M[7] * y + M[8]);
|
||||
|
||||
Therefore, the identity matrix is
|
||||
|
||||
sk_matrix_t identity = {{1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1}};
|
||||
|
||||
A matrix that scales by sx and sy is:
|
||||
|
||||
sk_matrix_t scale = {{sx, 0, 0,
|
||||
0, sy, 0,
|
||||
0, 0, 1}};
|
||||
|
||||
A matrix that translates by tx and ty is:
|
||||
|
||||
sk_matrix_t translate = {{1, 0, tx,
|
||||
0, 1, ty,
|
||||
0, 0, 1}};
|
||||
|
||||
A matrix that rotates around the origin by A radians:
|
||||
|
||||
sk_matrix_t rotate = {{cos(A), -sin(A), 0,
|
||||
sin(A), cos(A), 0,
|
||||
0, 0, 1}};
|
||||
|
||||
Two matrixes can be concatinated by:
|
||||
|
||||
void concat_matrices(sk_matrix_t* dst,
|
||||
const sk_matrix_t* matrixU,
|
||||
const sk_matrix_t* matrixV) {
|
||||
const float* u = matrixU->mat;
|
||||
const float* v = matrixV->mat;
|
||||
sk_matrix_t result = {{
|
||||
u[0] * v[0] + u[1] * v[3] + u[2] * v[6],
|
||||
u[0] * v[1] + u[1] * v[4] + u[2] * v[7],
|
||||
u[0] * v[2] + u[1] * v[5] + u[2] * v[8],
|
||||
u[3] * v[0] + u[4] * v[3] + u[5] * v[6],
|
||||
u[3] * v[1] + u[4] * v[4] + u[5] * v[7],
|
||||
u[3] * v[2] + u[4] * v[5] + u[5] * v[8],
|
||||
u[6] * v[0] + u[7] * v[3] + u[8] * v[6],
|
||||
u[6] * v[1] + u[7] * v[4] + u[8] * v[7],
|
||||
u[6] * v[2] + u[7] * v[5] + u[8] * v[8]
|
||||
}};
|
||||
*dst = result;
|
||||
}
|
||||
*/
|
||||
typedef struct {
|
||||
float mat[9];
|
||||
} sk_matrix_t;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#define SkAndroidCodec_DEFINED
|
||||
|
||||
#include "SkCodec.h"
|
||||
#include "SkEncodedImageFormat.h"
|
||||
#include "SkEncodedFormat.h"
|
||||
#include "SkStream.h"
|
||||
#include "SkTypes.h"
|
||||
|
||||
|
@ -51,18 +51,14 @@ public:
|
|||
/**
|
||||
* Format of the encoded data.
|
||||
*/
|
||||
SkEncodedImageFormat getEncodedFormat() const { return fCodec->getEncodedFormat(); }
|
||||
SkEncodedFormat getEncodedFormat() const { return fCodec->getEncodedFormat(); }
|
||||
|
||||
/**
|
||||
* @param requestedColorType Color type requested by the client
|
||||
*
|
||||
* |requestedColorType| may be overriden. We will default to kF16
|
||||
* for high precision images and kIndex8 for GIF and WBMP.
|
||||
*
|
||||
* In the general case, if it is possible to decode to
|
||||
* |requestedColorType|, this returns |requestedColorType|.
|
||||
* Otherwise, this returns a color type that is an appropriate
|
||||
* match for the the encoded data.
|
||||
* If it is possible to decode to requestedColorType, this returns
|
||||
* requestedColorType. Otherwise, this returns whichever color type
|
||||
* is suggested by the codec as the best match for the encoded data.
|
||||
*/
|
||||
SkColorType computeOutputColorType(SkColorType requestedColorType);
|
||||
|
||||
|
@ -75,19 +71,6 @@ public:
|
|||
*/
|
||||
SkAlphaType computeOutputAlphaType(bool requestedUnpremul);
|
||||
|
||||
/**
|
||||
* @param outputColorType Color type that the client will decode to.
|
||||
* @param prefColorSpace Preferred color space to decode to.
|
||||
* This may not return |prefColorSpace| for a couple reasons.
|
||||
* (1) Android Principles: 565 must be sRGB, F16 must be
|
||||
* linear sRGB, transfer function must be parametric.
|
||||
* (2) Codec Limitations: F16 requires a linear color space.
|
||||
*
|
||||
* Returns the appropriate color space to decode to.
|
||||
*/
|
||||
sk_sp<SkColorSpace> computeOutputColorSpace(SkColorType outputColorType,
|
||||
sk_sp<SkColorSpace> prefColorSpace = nullptr);
|
||||
|
||||
/**
|
||||
* Returns the dimensions of the scaled output image, for an input
|
||||
* sampleSize.
|
||||
|
@ -171,7 +154,7 @@ public:
|
|||
*
|
||||
* Must be within the bounds returned by getInfo().
|
||||
*
|
||||
* If the EncodedFormat is SkEncodedImageFormat::kWEBP, the top and left
|
||||
* If the EncodedFormat is kWEBP_SkEncodedFormat, the top and left
|
||||
* values must be even.
|
||||
*
|
||||
* The default is NULL, meaning a decode of the entire image.
|
||||
|
@ -277,6 +260,6 @@ private:
|
|||
// embedded SkCodec.
|
||||
const SkImageInfo& fInfo;
|
||||
|
||||
std::unique_ptr<SkCodec> fCodec;
|
||||
SkAutoTDelete<SkCodec> fCodec;
|
||||
};
|
||||
#endif // SkAndroidCodec_DEFINED
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include "../private/SkTemplates.h"
|
||||
#include "SkColor.h"
|
||||
#include "SkEncodedImageFormat.h"
|
||||
#include "SkEncodedFormat.h"
|
||||
#include "SkEncodedInfo.h"
|
||||
#include "SkImageInfo.h"
|
||||
#include "SkSize.h"
|
||||
|
@ -18,10 +18,7 @@
|
|||
#include "SkTypes.h"
|
||||
#include "SkYUVSizeInfo.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class SkColorSpace;
|
||||
class SkColorSpaceXform;
|
||||
class SkData;
|
||||
class SkPngChunkReader;
|
||||
class SkSampler;
|
||||
|
@ -35,7 +32,7 @@ class ColorCodecBench;
|
|||
/**
|
||||
* Abstraction layer directly on top of an image codec.
|
||||
*/
|
||||
class SK_API SkCodec : SkNoncopyable {
|
||||
class SkCodec : SkNoncopyable {
|
||||
public:
|
||||
/**
|
||||
* Minimum number of bytes that must be buffered in SkStream input.
|
||||
|
@ -176,7 +173,7 @@ public:
|
|||
/**
|
||||
* Format of the encoded data.
|
||||
*/
|
||||
SkEncodedImageFormat getEncodedFormat() const { return this->onGetEncodedFormat(); }
|
||||
SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat(); }
|
||||
|
||||
/**
|
||||
* Used to describe the result of a call to getPixels().
|
||||
|
@ -246,17 +243,14 @@ public:
|
|||
struct Options {
|
||||
Options()
|
||||
: fZeroInitialized(kNo_ZeroInitialized)
|
||||
, fSubset(nullptr)
|
||||
, fFrameIndex(0)
|
||||
, fHasPriorFrame(false)
|
||||
, fPremulBehavior(SkTransferFunctionBehavior::kRespect)
|
||||
, fSubset(NULL)
|
||||
{}
|
||||
|
||||
ZeroInitialized fZeroInitialized;
|
||||
ZeroInitialized fZeroInitialized;
|
||||
/**
|
||||
* If not NULL, represents a subset of the original image to decode.
|
||||
* Must be within the bounds returned by getInfo().
|
||||
* If the EncodedFormat is SkEncodedImageFormat::kWEBP (the only one which
|
||||
* If the EncodedFormat is kWEBP_SkEncodedFormat (the only one which
|
||||
* currently supports subsets), the top and left values must be even.
|
||||
*
|
||||
* In getPixels and incremental decode, we will attempt to decode the
|
||||
|
@ -270,41 +264,7 @@ public:
|
|||
* subset left and subset width to decode partial scanlines on calls
|
||||
* to getScanlines().
|
||||
*/
|
||||
const SkIRect* fSubset;
|
||||
|
||||
/**
|
||||
* The frame to decode.
|
||||
*
|
||||
* Only meaningful for multi-frame images.
|
||||
*/
|
||||
size_t fFrameIndex;
|
||||
|
||||
/**
|
||||
* If true, the dst already contains the prior frame.
|
||||
*
|
||||
* Only meaningful for multi-frame images.
|
||||
*
|
||||
* If fFrameIndex needs to be blended with a prior frame (as reported by
|
||||
* getFrameInfo[fFrameIndex].fRequiredFrame), the client can set this to
|
||||
* either true or false:
|
||||
*
|
||||
* true means that the prior frame is already in the dst, and this
|
||||
* codec only needs to decode fFrameIndex and blend it with the dst.
|
||||
* Options.fZeroInitialized is ignored in this case.
|
||||
*
|
||||
* false means that the dst does not contain the prior frame, so this
|
||||
* codec needs to first decode the prior frame (which in turn may need
|
||||
* to decode its prior frame).
|
||||
*/
|
||||
bool fHasPriorFrame;
|
||||
|
||||
/**
|
||||
* Indicates whether we should do a linear premultiply or a legacy premultiply.
|
||||
*
|
||||
* In the case where the dst SkColorSpace is nullptr, this flag is ignored and
|
||||
* we will always do a legacy premultiply.
|
||||
*/
|
||||
SkTransferFunctionBehavior fPremulBehavior;
|
||||
SkIRect* fSubset;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -562,6 +522,19 @@ public:
|
|||
* Upside down bmps are an example.
|
||||
*/
|
||||
kBottomUp_SkScanlineOrder,
|
||||
|
||||
/*
|
||||
* This indicates that the scanline decoder reliably outputs rows, but
|
||||
* they will not be in logical order. If the scanline format is
|
||||
* kOutOfOrder, the nextScanline() API should be used to determine the
|
||||
* actual y-coordinate of the next output row.
|
||||
*
|
||||
* For this scanline ordering, it is advisable to get and skip
|
||||
* scanlines one at a time.
|
||||
*
|
||||
* Interlaced gifs are an example.
|
||||
*/
|
||||
kOutOfOrder_SkScanlineOrder,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -577,7 +550,7 @@ public:
|
|||
* decoder.
|
||||
*
|
||||
* This will equal fCurrScanline, except in the case of strangely
|
||||
* encoded image types (bottom-up bmps).
|
||||
* encoded image types (bottom-up bmps, interlaced gifs).
|
||||
*
|
||||
* Results are undefined when not in scanline decoding mode.
|
||||
*/
|
||||
|
@ -593,87 +566,6 @@ public:
|
|||
*/
|
||||
int outputScanline(int inputScanline) const;
|
||||
|
||||
/**
|
||||
* Return the number of frames in the image.
|
||||
*
|
||||
* May require reading through the stream.
|
||||
*/
|
||||
size_t getFrameCount() {
|
||||
return this->onGetFrameCount();
|
||||
}
|
||||
|
||||
// The required frame for an independent frame is marked as
|
||||
// kNone.
|
||||
static constexpr size_t kNone = static_cast<size_t>(-1);
|
||||
|
||||
/**
|
||||
* Information about individual frames in a multi-framed image.
|
||||
*/
|
||||
struct FrameInfo {
|
||||
/**
|
||||
* The frame that this frame needs to be blended with, or
|
||||
* kNone.
|
||||
*/
|
||||
size_t fRequiredFrame;
|
||||
|
||||
/**
|
||||
* Number of milliseconds to show this frame.
|
||||
*/
|
||||
size_t fDuration;
|
||||
|
||||
/**
|
||||
* Whether the end marker for this frame is contained in the stream.
|
||||
*
|
||||
* Note: this does not guarantee that an attempt to decode will be complete.
|
||||
* There could be an error in the stream.
|
||||
*/
|
||||
bool fFullyReceived;
|
||||
|
||||
/**
|
||||
* This is conservative; it will still return non-opaque if e.g. a
|
||||
* color index-based frame has a color with alpha but does not use it.
|
||||
*/
|
||||
SkAlphaType fAlphaType;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return info about a single frame.
|
||||
*
|
||||
* Only supported by multi-frame images. Does not read through the stream,
|
||||
* so it should be called after getFrameCount() to parse any frames that
|
||||
* have not already been parsed.
|
||||
*/
|
||||
bool getFrameInfo(size_t index, FrameInfo* info) const {
|
||||
return this->onGetFrameInfo(index, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return info about all the frames in the image.
|
||||
*
|
||||
* May require reading through the stream to determine info about the
|
||||
* frames (including the count).
|
||||
*
|
||||
* As such, future decoding calls may require a rewind.
|
||||
*
|
||||
* For single-frame images, this will return an empty vector.
|
||||
*/
|
||||
std::vector<FrameInfo> getFrameInfo();
|
||||
|
||||
static constexpr int kRepetitionCountInfinite = -1;
|
||||
|
||||
/**
|
||||
* Return the number of times to repeat, if this image is animated.
|
||||
*
|
||||
* May require reading the stream to find the repetition count.
|
||||
*
|
||||
* As such, future decoding calls may require a rewind.
|
||||
*
|
||||
* For single-frame images, this will return 0.
|
||||
*/
|
||||
int getRepetitionCount() {
|
||||
return this->onGetRepetitionCount();
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Takes ownership of SkStream*
|
||||
|
@ -682,7 +574,7 @@ protected:
|
|||
int height,
|
||||
const SkEncodedInfo&,
|
||||
SkStream*,
|
||||
sk_sp<SkColorSpace>,
|
||||
sk_sp<SkColorSpace> = nullptr,
|
||||
Origin = kTopLeft_Origin);
|
||||
|
||||
/**
|
||||
|
@ -708,7 +600,7 @@ protected:
|
|||
return false;
|
||||
}
|
||||
|
||||
virtual SkEncodedImageFormat onGetEncodedFormat() const = 0;
|
||||
virtual SkEncodedFormat onGetEncodedFormat() const = 0;
|
||||
|
||||
/**
|
||||
* @param rowsDecoded When the encoded image stream is incomplete, this function
|
||||
|
@ -814,42 +706,25 @@ protected:
|
|||
|
||||
virtual int onOutputScanline(int inputScanline) const;
|
||||
|
||||
bool initializeColorXform(const SkImageInfo& dstInfo,
|
||||
SkTransferFunctionBehavior premulBehavior);
|
||||
SkColorSpaceXform* colorXform() const { return fColorXform.get(); }
|
||||
|
||||
virtual size_t onGetFrameCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual bool onGetFrameInfo(size_t, FrameInfo*) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual int onGetRepetitionCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void setUnsupportedICC(bool SkDEBUGCODE(value)) { SkDEBUGCODE(fUnsupportedICC = value); }
|
||||
|
||||
/**
|
||||
* Used for testing with qcms.
|
||||
* FIXME: Remove this when we are done comparing with qcms.
|
||||
*/
|
||||
virtual sk_sp<SkData> getICCData() const { return nullptr; }
|
||||
private:
|
||||
const SkEncodedInfo fEncodedInfo;
|
||||
const SkImageInfo fSrcInfo;
|
||||
std::unique_ptr<SkStream> fStream;
|
||||
bool fNeedsRewind;
|
||||
const Origin fOrigin;
|
||||
const SkEncodedInfo fEncodedInfo;
|
||||
const SkImageInfo fSrcInfo;
|
||||
SkAutoTDelete<SkStream> fStream;
|
||||
bool fNeedsRewind;
|
||||
const Origin fOrigin;
|
||||
|
||||
SkImageInfo fDstInfo;
|
||||
SkCodec::Options fOptions;
|
||||
std::unique_ptr<SkColorSpaceXform> fColorXform;
|
||||
SkImageInfo fDstInfo;
|
||||
SkCodec::Options fOptions;
|
||||
|
||||
// Only meaningful during scanline decodes.
|
||||
int fCurrScanline;
|
||||
int fCurrScanline;
|
||||
|
||||
bool fStartedIncrementalDecode;
|
||||
#ifdef SK_DEBUG
|
||||
bool fUnsupportedICC = false;
|
||||
#endif
|
||||
bool fStartedIncrementalDecode;
|
||||
|
||||
/**
|
||||
* Return whether these dimensions are supported as a scale.
|
||||
|
@ -907,14 +782,17 @@ private:
|
|||
* May create a sampler, if one is not currently being used. Otherwise, does
|
||||
* not affect ownership.
|
||||
*
|
||||
* Only valid during scanline decoding or incremental decoding.
|
||||
* Only valid during scanline decoding.
|
||||
*/
|
||||
virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr; }
|
||||
|
||||
// For testing with qcms
|
||||
// FIXME: Remove these when we are done comparing with qcms.
|
||||
friend class DM::ColorCodecSrc;
|
||||
friend class ColorCodecBench;
|
||||
|
||||
friend class DM::CodecSrc; // for fillIncompleteImage
|
||||
friend class SkSampledCodec;
|
||||
friend class SkIcoCodec;
|
||||
friend struct Sniffer; // for fUnsupportedICC
|
||||
friend class AutoCleanPng; // for setUnsupportedICC()
|
||||
};
|
||||
#endif // SkCodec_DEFINED
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkEncodedFormat_DEFINED
|
||||
#define SkEncodedFormat_DEFINED
|
||||
|
||||
/**
|
||||
* Enum describing format of encoded data.
|
||||
*/
|
||||
enum SkEncodedFormat {
|
||||
kUnknown_SkEncodedFormat,
|
||||
kBMP_SkEncodedFormat,
|
||||
kGIF_SkEncodedFormat,
|
||||
kICO_SkEncodedFormat,
|
||||
kJPEG_SkEncodedFormat,
|
||||
kPNG_SkEncodedFormat,
|
||||
kWBMP_SkEncodedFormat,
|
||||
kWEBP_SkEncodedFormat,
|
||||
kPKM_SkEncodedFormat,
|
||||
kKTX_SkEncodedFormat,
|
||||
kASTC_SkEncodedFormat,
|
||||
kDNG_SkEncodedFormat,
|
||||
};
|
||||
#endif // SkEncodedFormat_DEFINED
|
|
@ -93,6 +93,10 @@
|
|||
*/
|
||||
//#define SK_DEFAULT_IMAGE_CACHE_LIMIT (1024 * 1024)
|
||||
|
||||
/* Define this to provide font subsetter in PDF generation.
|
||||
*/
|
||||
//#define SK_SFNTLY_SUBSETTER "sample/chromium/font_subsetter.h"
|
||||
|
||||
/* Define this to set the upper limit for text to support LCD. Values that
|
||||
are very large increase the cost in the font cache and draw slower, without
|
||||
improving readability. If this is undefined, Skia will use its default
|
||||
|
@ -157,6 +161,8 @@
|
|||
|
||||
#define SK_DISABLE_SLOW_DEBUG_VALIDATION 1
|
||||
|
||||
#define MOZ_SKIA 1
|
||||
|
||||
#ifndef MOZ_IMPLICIT
|
||||
# ifdef MOZ_CLANG_PLUGIN
|
||||
# define MOZ_IMPLICIT __attribute__((annotate("moz_implicit")))
|
||||
|
@ -165,6 +171,4 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#define MOZ_SKIA
|
||||
|
||||
#endif
|
||||
|
|
|
@ -20,6 +20,8 @@ struct SkIRect;
|
|||
struct SkRect;
|
||||
class SkPaint;
|
||||
class SkPixelRef;
|
||||
class SkPixelRefFactory;
|
||||
class SkRegion;
|
||||
class SkString;
|
||||
|
||||
/** \class SkBitmap
|
||||
|
@ -31,8 +33,6 @@ class SkString;
|
|||
A const SkBitmap exposes getAddr(), which lets a caller write its pixels;
|
||||
the constness is considered to apply to the bitmap's configuration, not
|
||||
its contents.
|
||||
|
||||
SkBitmap is not thread safe. Each thread must use its own (shallow) copy.
|
||||
*/
|
||||
class SK_API SkBitmap {
|
||||
public:
|
||||
|
@ -85,7 +85,6 @@ public:
|
|||
SkColorType colorType() const { return fInfo.colorType(); }
|
||||
SkAlphaType alphaType() const { return fInfo.alphaType(); }
|
||||
SkColorSpace* colorSpace() const { return fInfo.colorSpace(); }
|
||||
sk_sp<SkColorSpace> refColorSpace() const { return fInfo.refColorSpace(); }
|
||||
|
||||
/**
|
||||
* Return the number of bytes per pixel based on the colortype. If the colortype is
|
||||
|
@ -118,7 +117,7 @@ public:
|
|||
* dimensions of the bitmap are > 0 (see empty()).
|
||||
* Hey! Before you use this, see if you really want to know drawsNothing() instead.
|
||||
*/
|
||||
bool isNull() const { return nullptr == fPixelRef; }
|
||||
bool isNull() const { return NULL == fPixelRef; }
|
||||
|
||||
/** Return true iff drawing this bitmap has no effect.
|
||||
*/
|
||||
|
@ -216,10 +215,7 @@ public:
|
|||
* this (isOpaque). Only call this if you need to compute this value from
|
||||
* "unknown" pixels.
|
||||
*/
|
||||
static bool ComputeIsOpaque(const SkBitmap& bm) {
|
||||
SkAutoPixmapUnlock result;
|
||||
return bm.requestLock(&result) && result.pixmap().computeIsOpaque();
|
||||
}
|
||||
static bool ComputeIsOpaque(const SkBitmap&);
|
||||
|
||||
/**
|
||||
* Return the bitmap's bounds [0, 0, width, height] as an SkRect
|
||||
|
@ -237,20 +233,16 @@ public:
|
|||
|
||||
bool setInfo(const SkImageInfo&, size_t rowBytes = 0);
|
||||
|
||||
enum AllocFlags {
|
||||
kZeroPixels_AllocFlag = 1 << 0,
|
||||
};
|
||||
/**
|
||||
* Allocate the bitmap's pixels to match the requested image info. If the Factory
|
||||
* is non-null, call it to allcoate the pixelref. If the ImageInfo requires
|
||||
* a colortable, then ColorTable must be non-null.
|
||||
*
|
||||
* a colortable, then ColorTable must be non-null, and will be ref'd.
|
||||
* On failure, the bitmap will be set to empty and return false.
|
||||
*/
|
||||
bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info, sk_sp<SkColorTable> ctable,
|
||||
uint32_t flags = 0);
|
||||
void allocPixels(const SkImageInfo& info, sk_sp<SkColorTable> ctable, uint32_t flags = 0) {
|
||||
if (!this->tryAllocPixels(info, std::move(ctable), flags)) {
|
||||
bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*);
|
||||
|
||||
void allocPixels(const SkImageInfo& info, SkPixelRefFactory* factory, SkColorTable* ctable) {
|
||||
if (!this->tryAllocPixels(info, factory, ctable)) {
|
||||
sk_throw();
|
||||
}
|
||||
}
|
||||
|
@ -291,11 +283,6 @@ public:
|
|||
this->allocPixels(info);
|
||||
}
|
||||
|
||||
// TEMPORARY -- remove after updating Android BitmapTests.cpp:35
|
||||
void allocPixels(const SkImageInfo& info, std::nullptr_t, SkColorTable* ctable) {
|
||||
this->allocPixels(info, sk_ref_sp(ctable));
|
||||
}
|
||||
|
||||
/**
|
||||
* Install a pixelref that wraps the specified pixels and rowBytes, and
|
||||
* optional ReleaseProc and context. When the pixels are no longer
|
||||
|
@ -345,6 +332,27 @@ public:
|
|||
*/
|
||||
void setPixels(void* p, SkColorTable* ctable = NULL);
|
||||
|
||||
/** Copies the bitmap's pixels to the location pointed at by dst and returns
|
||||
true if possible, returns false otherwise.
|
||||
|
||||
In the case when the dstRowBytes matches the bitmap's rowBytes, the copy
|
||||
may be made faster by copying over the dst's per-row padding (for all
|
||||
rows but the last). By setting preserveDstPad to true the caller can
|
||||
disable this optimization and ensure that pixels in the padding are not
|
||||
overwritten.
|
||||
|
||||
Always returns false for RLE formats.
|
||||
|
||||
@param dst Location of destination buffer.
|
||||
@param dstSize Size of destination buffer. Must be large enough to hold
|
||||
pixels using indicated stride.
|
||||
@param dstRowBytes Width of each line in the buffer. If 0, uses
|
||||
bitmap's internal stride.
|
||||
@param preserveDstPad Must we preserve padding in the dst
|
||||
*/
|
||||
bool copyPixelsTo(void* const dst, size_t dstSize, size_t dstRowBytes = 0,
|
||||
bool preserveDstPad = false) const;
|
||||
|
||||
/** Use the standard HeapAllocator to create the pixelref that manages the
|
||||
pixel memory. It will be sized based on the current ImageInfo.
|
||||
If this is called multiple times, a new pixelref object will be created
|
||||
|
@ -396,7 +404,7 @@ public:
|
|||
* Return the current pixelref object or NULL if there is none. This does
|
||||
* not affect the refcount of the pixelref.
|
||||
*/
|
||||
SkPixelRef* pixelRef() const { return fPixelRef.get(); }
|
||||
SkPixelRef* pixelRef() const { return fPixelRef; }
|
||||
|
||||
/**
|
||||
* A bitmap can reference a subset of a pixelref's pixels. That means the
|
||||
|
@ -412,12 +420,21 @@ public:
|
|||
SkIPoint pixelRefOrigin() const { return fPixelRefOrigin; }
|
||||
|
||||
/**
|
||||
* Assign a pixelref and origin to the bitmap. (dx,dy) specify the offset
|
||||
* within the pixelref's pixels for the top/left corner of the bitmap. For
|
||||
* a bitmap that encompases the entire pixels of the pixelref, these will
|
||||
* be (0,0).
|
||||
* Assign a pixelref and origin to the bitmap. Pixelrefs are reference,
|
||||
* so the existing one (if any) will be unref'd and the new one will be
|
||||
* ref'd. (x,y) specify the offset within the pixelref's pixels for the
|
||||
* top/left corner of the bitmap. For a bitmap that encompases the entire
|
||||
* pixels of the pixelref, these will be (0,0).
|
||||
*/
|
||||
void setPixelRef(sk_sp<SkPixelRef>, int dx, int dy);
|
||||
SkPixelRef* setPixelRef(SkPixelRef* pr, int dx, int dy);
|
||||
|
||||
SkPixelRef* setPixelRef(SkPixelRef* pr, const SkIPoint& origin) {
|
||||
return this->setPixelRef(pr, origin.fX, origin.fY);
|
||||
}
|
||||
|
||||
SkPixelRef* setPixelRef(SkPixelRef* pr) {
|
||||
return this->setPixelRef(pr, 0, 0);
|
||||
}
|
||||
|
||||
/** Call this to ensure that the bitmap points to the current pixel address
|
||||
in the pixelref. Balance it with a call to unlockPixels(). These calls
|
||||
|
@ -431,6 +448,15 @@ public:
|
|||
*/
|
||||
void unlockPixels() const;
|
||||
|
||||
/**
|
||||
* Some bitmaps can return a copy of their pixels for lockPixels(), but
|
||||
* that copy, if modified, will not be pushed back. These bitmaps should
|
||||
* not be used as targets for a raster device/canvas (since all pixels
|
||||
* modifications will be lost when unlockPixels() is called.)
|
||||
*/
|
||||
// DEPRECATED
|
||||
bool lockPixelsAreWritable() const;
|
||||
|
||||
bool requestLock(SkAutoPixmapUnlock* result) const;
|
||||
|
||||
/** Call this to be sure that the bitmap is valid enough to be drawn (i.e.
|
||||
|
@ -499,19 +525,13 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts the pixel at the specified coordinate to an unpremultiplied
|
||||
* SkColor. Note: this ignores any SkColorSpace information, and may return
|
||||
* lower precision data than is actually in the pixel. Alpha only
|
||||
* colortypes (e.g. kAlpha_8_SkColorType) return black with the appropriate
|
||||
* alpha set. The value is undefined for kUnknown_SkColorType or if x or y
|
||||
* are out of bounds, or if the bitmap does not have any pixels (or has not
|
||||
* be locked with lockPixels())..
|
||||
* Return the SkColor of the specified pixel. In most cases this will
|
||||
* require un-premultiplying the color. Alpha only colortypes (e.g. kAlpha_8_SkColorType)
|
||||
* return black with the appropriate alpha set. The value is undefined
|
||||
* for kUnknown_SkColorType or if x or y are out of bounds, or if the bitmap
|
||||
* does not have any pixels (or has not be locked with lockPixels()).
|
||||
*/
|
||||
SkColor getColor(int x, int y) const {
|
||||
SkPixmap pixmap;
|
||||
SkAssertResult(this->peekPixels(&pixmap));
|
||||
return pixmap.getColor(x, y);
|
||||
}
|
||||
SkColor getColor(int x, int y) const;
|
||||
|
||||
/** Returns the address of the specified pixel. This performs a runtime
|
||||
check to know the size of the pixels, and will return the same answer
|
||||
|
@ -566,7 +586,6 @@ public:
|
|||
*/
|
||||
bool extractSubset(SkBitmap* dst, const SkIRect& subset) const;
|
||||
|
||||
#ifdef SK_BUILD_FOR_ANDROID
|
||||
/** Makes a deep copy of this bitmap, respecting the requested colorType,
|
||||
* and allocating the dst pixels on the cpu.
|
||||
* Returns false if either there is an error (i.e. the src does not have
|
||||
|
@ -579,26 +598,11 @@ public:
|
|||
* will be used.
|
||||
* @return true if the copy was made.
|
||||
*/
|
||||
bool copyTo(SkBitmap* dst, SkColorType ct, Allocator*) const;
|
||||
bool copyTo(SkBitmap* dst, SkColorType ct, Allocator* = NULL) const;
|
||||
|
||||
bool copyTo(SkBitmap* dst, Allocator* allocator) const {
|
||||
bool copyTo(SkBitmap* dst, Allocator* allocator = NULL) const {
|
||||
return this->copyTo(dst, this->colorType(), allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Makes a deep copy of this bitmap, respecting the requested colorType.
|
||||
* Returns false if either there is an error (i.e. the src does not have
|
||||
* pixels) or the request cannot be satisfied (e.g. the src has per-pixel
|
||||
* alpha, and the requested colortype does not support alpha).
|
||||
* @param dst The bitmap to be sized and allocated
|
||||
* @param ct The desired colorType for dst
|
||||
* @return true if the copy was made.
|
||||
*/
|
||||
bool copyTo(SkBitmap* dst, SkColorType ct) const;
|
||||
|
||||
bool copyTo(SkBitmap* dst) const {
|
||||
return this->copyTo(dst, this->colorType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the bitmap's pixels into the specified buffer (pixels + rowBytes),
|
||||
|
@ -621,23 +625,6 @@ public:
|
|||
*/
|
||||
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
|
||||
int srcX, int srcY) const;
|
||||
bool readPixels(const SkPixmap& dst, int srcX, int srcY) const;
|
||||
bool readPixels(const SkPixmap& dst) const {
|
||||
return this->readPixels(dst, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the src pixmap's pixels into this bitmap, offset by dstX, dstY.
|
||||
*
|
||||
* This is logically the same as creating a bitmap around src, and calling readPixels on it
|
||||
* with this bitmap as the dst.
|
||||
*/
|
||||
bool writePixels(const SkPixmap& src, int dstX, int dstY) {
|
||||
return this->writePixels(src, dstX, dstY, SkTransferFunctionBehavior::kRespect);
|
||||
}
|
||||
bool writePixels(const SkPixmap& src) {
|
||||
return this->writePixels(src, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this bitmap's pixels can be converted into the requested
|
||||
|
@ -728,16 +715,37 @@ public:
|
|||
bool allocPixelRef(SkBitmap*, SkColorTable*) override;
|
||||
};
|
||||
|
||||
class RLEPixels {
|
||||
public:
|
||||
RLEPixels(int width, int height);
|
||||
virtual ~RLEPixels();
|
||||
|
||||
uint8_t* packedAtY(int y) const {
|
||||
SkASSERT((unsigned)y < (unsigned)fHeight);
|
||||
return fYPtrs[y];
|
||||
}
|
||||
|
||||
// called by subclasses during creation
|
||||
void setPackedAtY(int y, uint8_t* addr) {
|
||||
SkASSERT((unsigned)y < (unsigned)fHeight);
|
||||
fYPtrs[y] = addr;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t** fYPtrs;
|
||||
int fHeight;
|
||||
};
|
||||
|
||||
SK_TO_STRING_NONVIRT()
|
||||
|
||||
private:
|
||||
mutable sk_sp<SkPixelRef> fPixelRef;
|
||||
mutable int fPixelLockCount;
|
||||
mutable SkPixelRef* fPixelRef;
|
||||
mutable int fPixelLockCount;
|
||||
// These are just caches from the locked pixelref
|
||||
mutable void* fPixels;
|
||||
mutable SkColorTable* fColorTable; // only meaningful for kIndex8
|
||||
mutable void* fPixels;
|
||||
mutable SkColorTable* fColorTable; // only meaningful for kIndex8
|
||||
|
||||
SkIPoint fPixelRefOrigin;
|
||||
SkIPoint fPixelRefOrigin;
|
||||
|
||||
enum Flags {
|
||||
kImageIsVolatile_Flag = 0x02,
|
||||
|
@ -750,13 +758,9 @@ private:
|
|||
#endif
|
||||
};
|
||||
|
||||
SkImageInfo fInfo;
|
||||
uint32_t fRowBytes;
|
||||
uint8_t fFlags;
|
||||
|
||||
bool writePixels(const SkPixmap& src, int x, int y, SkTransferFunctionBehavior behavior);
|
||||
|
||||
bool internalCopyTo(SkBitmap* dst, SkColorType ct, Allocator*) const;
|
||||
SkImageInfo fInfo;
|
||||
uint32_t fRowBytes;
|
||||
uint8_t fFlags;
|
||||
|
||||
/* Unreference any pixelrefs or colortables
|
||||
*/
|
||||
|
@ -766,7 +770,6 @@ private:
|
|||
static void WriteRawPixels(SkWriteBuffer*, const SkBitmap&);
|
||||
static bool ReadRawPixels(SkReadBuffer*, SkBitmap*);
|
||||
|
||||
friend class SkImage_Raster;
|
||||
friend class SkReadBuffer; // unflatten, rawpixels
|
||||
friend class SkBinaryWriteBuffer; // rawpixels
|
||||
friend struct SkBitmapProcState;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* Copyright 2013 Google Inc.
|
||||
*
|
||||
|
@ -13,23 +14,22 @@
|
|||
#include "SkColor.h"
|
||||
#include "SkDevice.h"
|
||||
#include "SkImageInfo.h"
|
||||
#include "SkPixelRef.h"
|
||||
#include "SkRasterClip.h"
|
||||
#include "SkRasterClipStack.h"
|
||||
#include "SkRect.h"
|
||||
#include "SkScalar.h"
|
||||
#include "SkSize.h"
|
||||
#include "SkSurfaceProps.h"
|
||||
#include "SkTypes.h"
|
||||
|
||||
class SkDraw;
|
||||
class SkImageFilterCache;
|
||||
class SkMatrix;
|
||||
class SkPaint;
|
||||
class SkPath;
|
||||
class SkPixelRef;
|
||||
class SkPixmap;
|
||||
class SkRasterHandleAllocator;
|
||||
class SkRRect;
|
||||
class SkSurface;
|
||||
class SkXfermode;
|
||||
struct SkPoint;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -54,27 +54,27 @@ public:
|
|||
* valid for the bitmap to have no pixels associated with it. In that case,
|
||||
* any drawing to this device will have no effect.
|
||||
*/
|
||||
SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps,
|
||||
void* externalHandle = nullptr);
|
||||
SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps);
|
||||
|
||||
static SkBitmapDevice* Create(const SkImageInfo&, const SkSurfaceProps&,
|
||||
SkRasterHandleAllocator* = nullptr);
|
||||
static SkBitmapDevice* Create(const SkImageInfo&, const SkSurfaceProps&);
|
||||
|
||||
protected:
|
||||
bool onShouldDisableLCD(const SkPaint&) const override;
|
||||
void* getRasterHandle() const override { return fRasterHandle; }
|
||||
|
||||
/** These are called inside the per-device-layer loop for each draw call.
|
||||
When these are called, we have already applied any saveLayer operations,
|
||||
and are handling any looping from the paint, and any effects from the
|
||||
DrawFilter.
|
||||
*/
|
||||
void drawPaint(const SkPaint& paint) override;
|
||||
void drawPoints(SkCanvas::PointMode mode, size_t count,
|
||||
void drawPaint(const SkDraw&, const SkPaint& paint) override;
|
||||
virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
|
||||
const SkPoint[], const SkPaint& paint) override;
|
||||
void drawRect(const SkRect& r, const SkPaint& paint) override;
|
||||
void drawOval(const SkRect& oval, const SkPaint& paint) override;
|
||||
void drawRRect(const SkRRect& rr, const SkPaint& paint) override;
|
||||
virtual void drawRect(const SkDraw&, const SkRect& r,
|
||||
const SkPaint& paint) override;
|
||||
virtual void drawOval(const SkDraw&, const SkRect& oval,
|
||||
const SkPaint& paint) override;
|
||||
virtual void drawRRect(const SkDraw&, const SkRRect& rr,
|
||||
const SkPaint& paint) override;
|
||||
|
||||
/**
|
||||
* If pathIsMutable, then the implementation is allowed to cast path to a
|
||||
|
@ -87,65 +87,78 @@ protected:
|
|||
* affect the geometry/rasterization, then the pre matrix can just be
|
||||
* pre-concated with the current matrix.
|
||||
*/
|
||||
void drawPath(const SkPath&, const SkPaint&, const SkMatrix* prePathMatrix,
|
||||
bool pathIsMutable) override;
|
||||
void drawBitmap(const SkBitmap&, const SkMatrix&, const SkPaint&) override;
|
||||
void drawSprite(const SkBitmap&, int x, int y, const SkPaint&) override;
|
||||
virtual void drawPath(const SkDraw&, const SkPath& path,
|
||||
const SkPaint& paint,
|
||||
const SkMatrix* prePathMatrix = NULL,
|
||||
bool pathIsMutable = false) override;
|
||||
virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
|
||||
const SkMatrix& matrix, const SkPaint& paint) override;
|
||||
virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
|
||||
int x, int y, const SkPaint& paint) override;
|
||||
|
||||
/**
|
||||
* The default impl. will create a bitmap-shader from the bitmap,
|
||||
* and call drawRect with it.
|
||||
*/
|
||||
void drawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&,
|
||||
void drawBitmapRect(const SkDraw&, const SkBitmap&, const SkRect*, const SkRect&,
|
||||
const SkPaint&, SkCanvas::SrcRectConstraint) override;
|
||||
|
||||
/**
|
||||
* Does not handle text decoration.
|
||||
* Decorations (underline and stike-thru) will be handled by SkCanvas.
|
||||
*/
|
||||
void drawText(const void* text, size_t len, SkScalar x, SkScalar y,
|
||||
const SkPaint&) override;
|
||||
void drawPosText(const void* text, size_t len, const SkScalar pos[],
|
||||
int scalarsPerPos, const SkPoint& offset, const SkPaint& paint) override;
|
||||
void drawVertices(const SkVertices*, SkBlendMode, const SkPaint&) override;
|
||||
void drawDevice(SkBaseDevice*, int x, int y, const SkPaint&) override;
|
||||
virtual void drawText(const SkDraw&, const void* text, size_t len,
|
||||
SkScalar x, SkScalar y, const SkPaint& paint) override;
|
||||
virtual void drawPosText(const SkDraw&, const void* text, size_t len,
|
||||
const SkScalar pos[], int scalarsPerPos,
|
||||
const SkPoint& offset, const SkPaint& paint) override;
|
||||
virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount,
|
||||
const SkPoint verts[], const SkPoint texs[],
|
||||
const SkColor colors[], SkXfermode* xmode,
|
||||
const uint16_t indices[], int indexCount,
|
||||
const SkPaint& paint) override;
|
||||
virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, const SkPaint&) override;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void drawSpecial(SkSpecialImage*, int x, int y, const SkPaint&) override;
|
||||
|
||||
void drawSpecial(const SkDraw&, SkSpecialImage*, int x, int y, const SkPaint&) override;
|
||||
sk_sp<SkSpecialImage> makeSpecial(const SkBitmap&) override;
|
||||
sk_sp<SkSpecialImage> makeSpecial(const SkImage*) override;
|
||||
sk_sp<SkSpecialImage> snapSpecial() override;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Update as needed the pixel value in the bitmap, so that the caller can
|
||||
access the pixels directly. Note: only the pixels field should be
|
||||
altered. The config/width/height/rowbytes must remain unchanged.
|
||||
@return the device contents as a bitmap
|
||||
*/
|
||||
#ifdef SK_SUPPORT_LEGACY_ACCESSBITMAP
|
||||
const SkBitmap& onAccessBitmap() override;
|
||||
#else
|
||||
const SkBitmap& onAccessBitmap();
|
||||
#endif
|
||||
|
||||
SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
|
||||
// just for subclasses, to assign a custom pixelref
|
||||
SkPixelRef* setPixelRef(SkPixelRef* pr) {
|
||||
fBitmap.setPixelRef(pr);
|
||||
return pr;
|
||||
}
|
||||
|
||||
bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y) override;
|
||||
bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) override;
|
||||
bool onPeekPixels(SkPixmap*) override;
|
||||
bool onAccessPixels(SkPixmap*) override;
|
||||
|
||||
void onSave() override;
|
||||
void onRestore() override;
|
||||
void onClipRect(const SkRect& rect, SkClipOp, bool aa) override;
|
||||
void onClipRRect(const SkRRect& rrect, SkClipOp, bool aa) override;
|
||||
void onClipPath(const SkPath& path, SkClipOp, bool aa) override;
|
||||
void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override;
|
||||
void onSetDeviceClipRestriction(SkIRect* mutableClipRestriction) override;
|
||||
bool onClipIsAA() const override;
|
||||
void onAsRgnClip(SkRegion*) const override;
|
||||
void validateDevBounds(const SkIRect& r) override;
|
||||
ClipType onGetClipType() const override;
|
||||
|
||||
private:
|
||||
friend class SkCanvas;
|
||||
friend struct DeviceCM; //for setMatrixClip
|
||||
friend class SkDraw;
|
||||
friend class SkDrawIter;
|
||||
friend class SkDeviceFilteredPaint;
|
||||
friend class SkSurface_Raster;
|
||||
friend class SkThreadedBMPDevice; // to copy fRCStack
|
||||
|
||||
class BDDraw;
|
||||
friend class SkSurface_Raster;
|
||||
|
||||
// used to change the backend's pixels (and possibly config/rowbytes)
|
||||
// but cannot change the width/height, so there should be no change to
|
||||
|
@ -159,8 +172,8 @@ private:
|
|||
SkImageFilterCache* getImageFilterCache() override;
|
||||
|
||||
SkBitmap fBitmap;
|
||||
void* fRasterHandle = nullptr;
|
||||
SkRasterClipStack fRCStack;
|
||||
|
||||
void setNewSize(const SkISize&); // Used by SkCanvas for resetForNextPicture().
|
||||
|
||||
typedef SkBaseDevice INHERITED;
|
||||
};
|
|
@ -8,8 +8,6 @@
|
|||
#ifndef SkBlendMode_DEFINED
|
||||
#define SkBlendMode_DEFINED
|
||||
|
||||
#include "SkTypes.h"
|
||||
|
||||
enum class SkBlendMode {
|
||||
kClear, //!< [0, 0]
|
||||
kSrc, //!< [Sa, Sc]
|
||||
|
@ -50,9 +48,4 @@ enum class SkBlendMode {
|
|||
kLastMode = kLuminosity
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the (c-string) name of the blendmode.
|
||||
*/
|
||||
SK_API const char* SkBlendMode_Name(SkBlendMode);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,41 +8,42 @@
|
|||
#ifndef SkCanvas_DEFINED
|
||||
#define SkCanvas_DEFINED
|
||||
|
||||
#include "SkTypes.h"
|
||||
#include "SkBlendMode.h"
|
||||
#include "SkBitmap.h"
|
||||
#include "SkClipOp.h"
|
||||
#include "SkDeque.h"
|
||||
#include "SkImage.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkRasterHandleAllocator.h"
|
||||
#include "SkRefCnt.h"
|
||||
#include "SkRegion.h"
|
||||
#include "SkSurfaceProps.h"
|
||||
#include "SkXfermode.h"
|
||||
#include "SkLights.h"
|
||||
#include "../private/SkShadowParams.h"
|
||||
|
||||
class GrContext;
|
||||
class GrRenderTargetContext;
|
||||
class GrDrawContext;
|
||||
class SkBaseDevice;
|
||||
class SkBitmap;
|
||||
#ifdef SK_SUPPORT_OBSOLETE_REPLAYCLIP
|
||||
class SkCanvasClipVisitor;
|
||||
#endif
|
||||
class SkClipStack;
|
||||
class SkData;
|
||||
class SkDraw;
|
||||
class SkDrawable;
|
||||
class SkDrawFilter;
|
||||
class SkImage;
|
||||
class SkImageFilter;
|
||||
class SkMetaData;
|
||||
class SkPath;
|
||||
class SkPicture;
|
||||
class SkPixmap;
|
||||
class SkRasterClip;
|
||||
class SkRegion;
|
||||
class SkRRect;
|
||||
struct SkRSXform;
|
||||
class SkSurface;
|
||||
class SkSurface_Base;
|
||||
class SkTextBlob;
|
||||
class SkVertices;
|
||||
|
||||
//#define SK_SUPPORT_LEGACY_CLIP_REGIONOPS
|
||||
|
||||
/** \class SkCanvas
|
||||
|
||||
|
@ -59,12 +60,31 @@ class SkVertices;
|
|||
color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns),
|
||||
etc.
|
||||
*/
|
||||
class SK_API SkCanvas : SkNoncopyable {
|
||||
class SK_API SkCanvas : public SkRefCnt {
|
||||
enum PrivateSaveLayerFlags {
|
||||
kDontClipToLayer_PrivateSaveLayerFlag = 1U << 31,
|
||||
};
|
||||
|
||||
public:
|
||||
#ifdef SK_SUPPORT_LEGACY_CLIP_REGIONOPS
|
||||
typedef SkRegion::Op ClipOp;
|
||||
|
||||
static const ClipOp kDifference_Op = SkRegion::kDifference_Op;
|
||||
static const ClipOp kIntersect_Op = SkRegion::kIntersect_Op;
|
||||
static const ClipOp kUnion_Op = SkRegion::kUnion_Op;
|
||||
static const ClipOp kXOR_Op = SkRegion::kXOR_Op;
|
||||
static const ClipOp kReverseDifference_Op = SkRegion::kReverseDifference_Op;
|
||||
static const ClipOp kReplace_Op = SkRegion::kReplace_Op;
|
||||
#else
|
||||
typedef SkClipOp ClipOp;
|
||||
|
||||
static const ClipOp kDifference_Op = kDifference_SkClipOp;
|
||||
static const ClipOp kIntersect_Op = kIntersect_SkClipOp;
|
||||
static const ClipOp kUnion_Op = kUnion_SkClipOp;
|
||||
static const ClipOp kXOR_Op = kXOR_SkClipOp;
|
||||
static const ClipOp kReverseDifference_Op = kReverseDifference_SkClipOp;
|
||||
static const ClipOp kReplace_Op = kReplace_SkClipOp;
|
||||
#endif
|
||||
/**
|
||||
* Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the
|
||||
* specified pixels. To access the pixels after drawing to them, the caller should call
|
||||
|
@ -80,11 +100,10 @@ public:
|
|||
* Note: it is valid to request a supported ImageInfo, but with zero
|
||||
* dimensions.
|
||||
*/
|
||||
static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo&, void*, size_t);
|
||||
static SkCanvas* NewRasterDirect(const SkImageInfo&, void*, size_t);
|
||||
|
||||
static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels,
|
||||
size_t rowBytes) {
|
||||
return MakeRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
|
||||
static SkCanvas* NewRasterDirectN32(int width, int height, SkPMColor* pixels, size_t rowBytes) {
|
||||
return NewRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,19 +131,6 @@ public:
|
|||
*/
|
||||
explicit SkCanvas(const SkBitmap& bitmap);
|
||||
|
||||
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
||||
enum class ColorBehavior {
|
||||
kLegacy,
|
||||
};
|
||||
|
||||
/**
|
||||
* Android framework only constructor.
|
||||
* Allows the creation of a legacy SkCanvas even though the |bitmap|
|
||||
* and its pixel ref may have an SkColorSpace.
|
||||
*/
|
||||
SkCanvas(const SkBitmap& bitmap, ColorBehavior);
|
||||
#endif
|
||||
|
||||
/** Construct a canvas with the specified bitmap to draw into.
|
||||
@param bitmap Specifies a bitmap for the canvas to draw into. Its
|
||||
structure are copied to the canvas.
|
||||
|
@ -165,6 +171,45 @@ public:
|
|||
*/
|
||||
virtual SkISize getBaseLayerSize() const;
|
||||
|
||||
/**
|
||||
* DEPRECATED: call getBaseLayerSize
|
||||
*/
|
||||
SkISize getDeviceSize() const { return this->getBaseLayerSize(); }
|
||||
|
||||
/**
|
||||
* DEPRECATED.
|
||||
* Return the canvas' device object, which may be null. The device holds
|
||||
* the bitmap of the pixels that the canvas draws into. The reference count
|
||||
* of the returned device is not changed by this call.
|
||||
*/
|
||||
#ifndef SK_SUPPORT_LEGACY_GETDEVICE
|
||||
protected: // Can we make this private?
|
||||
#endif
|
||||
SkBaseDevice* getDevice() const;
|
||||
public:
|
||||
SkBaseDevice* getDevice_just_for_deprecated_compatibility_testing() const {
|
||||
return this->getDevice();
|
||||
}
|
||||
|
||||
/**
|
||||
* saveLayer() can create another device (which is later drawn onto
|
||||
* the previous device). getTopDevice() returns the top-most device current
|
||||
* installed. Note that this can change on other calls like save/restore,
|
||||
* so do not access this device after subsequent canvas calls.
|
||||
* The reference count of the device is not changed.
|
||||
*
|
||||
* @param updateMatrixClip If this is true, then before the device is
|
||||
* returned, we ensure that its has been notified about the current
|
||||
* matrix and clip. Note: this happens automatically when the device
|
||||
* is drawn to, but is optional here, as there is a small perf hit
|
||||
* sometimes.
|
||||
*/
|
||||
#ifndef SK_SUPPORT_LEGACY_GETTOPDEVICE
|
||||
private:
|
||||
#endif
|
||||
SkBaseDevice* getTopDevice(bool updateMatrixClip = false) const;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new surface matching the specified info, one that attempts to
|
||||
* be maximally compatible when used with this canvas. If there is no matching Surface type,
|
||||
|
@ -175,6 +220,9 @@ public:
|
|||
* surface, then the new surface is created with default properties.
|
||||
*/
|
||||
sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps* = nullptr);
|
||||
#ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API
|
||||
SkSurface* newSurface(const SkImageInfo& info, const SkSurfaceProps* props = NULL);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Return the GPU context of the device that is associated with the canvas.
|
||||
|
@ -197,8 +245,6 @@ public:
|
|||
*/
|
||||
void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = NULL);
|
||||
|
||||
SkRasterHandleAllocator::Handle accessTopRasterHandle() const;
|
||||
|
||||
/**
|
||||
* If the canvas has readable pixels in its base layer (and is not recording to a picture
|
||||
* or other non-raster target) and has direct access to its pixels (i.e. they are in
|
||||
|
@ -212,6 +258,10 @@ public:
|
|||
*/
|
||||
bool peekPixels(SkPixmap*);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PEEKPIXELS_PARMS
|
||||
const void* peekPixels(SkImageInfo* info, size_t* rowBytes);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes),
|
||||
* converting them into the requested format (SkImageInfo). The base-layer pixels are read
|
||||
|
@ -329,9 +379,6 @@ public:
|
|||
kIsOpaque_SaveLayerFlag = 1 << 0,
|
||||
kPreserveLCDText_SaveLayerFlag = 1 << 1,
|
||||
|
||||
/** initialize the new layer with the contents of the previous layer */
|
||||
kInitWithPrevious_SaveLayerFlag = 1 << 2,
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
|
||||
kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag,
|
||||
#endif
|
||||
|
@ -453,37 +500,26 @@ public:
|
|||
* @param op The region op to apply to the current clip
|
||||
* @param doAntiAlias true if the clip should be antialiased
|
||||
*/
|
||||
void clipRect(const SkRect& rect, SkClipOp, bool doAntiAlias);
|
||||
void clipRect(const SkRect& rect, SkClipOp op) {
|
||||
void clipRect(const SkRect& rect, ClipOp, bool doAntiAlias);
|
||||
void clipRect(const SkRect& rect, ClipOp op) {
|
||||
this->clipRect(rect, op, false);
|
||||
}
|
||||
void clipRect(const SkRect& rect, bool doAntiAlias = false) {
|
||||
this->clipRect(rect, SkClipOp::kIntersect, doAntiAlias);
|
||||
this->clipRect(rect, kIntersect_Op, doAntiAlias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the max clip rectangle, which can be set by clipRect, clipRRect and
|
||||
* clipPath and intersect the current clip with the specified rect.
|
||||
* The max clip affects only future ops (it is not retroactive).
|
||||
* We DON'T record the clip restriction in pictures.
|
||||
* This is private API to be used only by Android framework.
|
||||
* @param rect The maximum allowed clip in device coordinates.
|
||||
* Empty rect means max clip is not enforced.
|
||||
*/
|
||||
void androidFramework_setDeviceClipRestriction(const SkIRect& rect);
|
||||
|
||||
/**
|
||||
* Modify the current clip with the specified SkRRect.
|
||||
* @param rrect The rrect to combine with the current clip
|
||||
* @param op The region op to apply to the current clip
|
||||
* @param doAntiAlias true if the clip should be antialiased
|
||||
*/
|
||||
void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias);
|
||||
void clipRRect(const SkRRect& rrect, SkClipOp op) {
|
||||
void clipRRect(const SkRRect& rrect, ClipOp op, bool doAntiAlias);
|
||||
void clipRRect(const SkRRect& rrect, ClipOp op) {
|
||||
this->clipRRect(rrect, op, false);
|
||||
}
|
||||
void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) {
|
||||
this->clipRRect(rrect, SkClipOp::kIntersect, doAntiAlias);
|
||||
this->clipRRect(rrect, kIntersect_Op, doAntiAlias);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -492,12 +528,12 @@ public:
|
|||
* @param op The region op to apply to the current clip
|
||||
* @param doAntiAlias true if the clip should be antialiased
|
||||
*/
|
||||
void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias);
|
||||
void clipPath(const SkPath& path, SkClipOp op) {
|
||||
void clipPath(const SkPath& path, ClipOp op, bool doAntiAlias);
|
||||
void clipPath(const SkPath& path, ClipOp op) {
|
||||
this->clipPath(path, op, false);
|
||||
}
|
||||
void clipPath(const SkPath& path, bool doAntiAlias = false) {
|
||||
this->clipPath(path, SkClipOp::kIntersect, doAntiAlias);
|
||||
this->clipPath(path, kIntersect_Op, doAntiAlias);
|
||||
}
|
||||
|
||||
/** EXPERIMENTAL -- only used for testing
|
||||
|
@ -514,7 +550,7 @@ public:
|
|||
@param deviceRgn The region to apply to the current clip
|
||||
@param op The region op to apply to the current clip
|
||||
*/
|
||||
void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect);
|
||||
void clipRegion(const SkRegion& deviceRgn, ClipOp op = kIntersect_Op);
|
||||
|
||||
/** Return true if the specified rectangle, after being transformed by the
|
||||
current matrix, would lie completely outside of the current clip. Call
|
||||
|
@ -538,33 +574,34 @@ public:
|
|||
*/
|
||||
bool quickReject(const SkPath& path) const;
|
||||
|
||||
/**
|
||||
* Return the bounds of the current clip in local coordinates. If the clip is empty,
|
||||
* return { 0, 0, 0, 0 }.
|
||||
*/
|
||||
SkRect getLocalClipBounds() const { return this->onGetLocalClipBounds(); }
|
||||
/** Return the bounds of the current clip (in local coordinates) in the
|
||||
bounds parameter, and return true if it is non-empty. This can be useful
|
||||
in a way similar to quickReject, in that it tells you that drawing
|
||||
outside of these bounds will be clipped out.
|
||||
*/
|
||||
virtual bool getClipBounds(SkRect* bounds) const;
|
||||
|
||||
/**
|
||||
* Returns true if the clip bounds are non-empty.
|
||||
*/
|
||||
bool getLocalClipBounds(SkRect* bounds) const {
|
||||
*bounds = this->onGetLocalClipBounds();
|
||||
return !bounds->isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bounds of the current clip in device coordinates. If the clip is empty,
|
||||
* return { 0, 0, 0, 0 }.
|
||||
*/
|
||||
SkIRect getDeviceClipBounds() const { return this->onGetDeviceClipBounds(); }
|
||||
|
||||
/**
|
||||
* Returns true if the clip bounds are non-empty.
|
||||
*/
|
||||
bool getDeviceClipBounds(SkIRect* bounds) const {
|
||||
*bounds = this->onGetDeviceClipBounds();
|
||||
return !bounds->isEmpty();
|
||||
/** Return the bounds of the current clip, in device coordinates; returns
|
||||
true if non-empty. Maybe faster than getting the clip explicitly and
|
||||
then taking its bounds.
|
||||
*/
|
||||
virtual bool getClipDeviceBounds(SkIRect* bounds) const;
|
||||
|
||||
|
||||
/** Fill the entire canvas' bitmap (restricted to the current clip) with the
|
||||
specified ARGB color, using the specified mode.
|
||||
@param a the alpha component (0..255) of the color to fill the canvas
|
||||
@param r the red component (0..255) of the color to fill the canvas
|
||||
@param g the green component (0..255) of the color to fill the canvas
|
||||
@param b the blue component (0..255) of the color to fill the canvas
|
||||
@param mode the mode to apply the color in (defaults to SrcOver)
|
||||
*/
|
||||
void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b, SkBlendMode mode = SkBlendMode::kSrcOver);
|
||||
#ifdef SK_SUPPORT_LEGACY_XFERMODE_OBJECT
|
||||
void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b, SkXfermode::Mode mode) {
|
||||
this->drawARGB(a, r, g, b, (SkBlendMode)mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Fill the entire canvas' bitmap (restricted to the current clip) with the
|
||||
specified color and mode.
|
||||
|
@ -572,6 +609,11 @@ public:
|
|||
@param mode the mode to apply the color in (defaults to SrcOver)
|
||||
*/
|
||||
void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver);
|
||||
#ifdef SK_SUPPORT_LEGACY_XFERMODE_OBJECT
|
||||
void drawColor(SkColor color, SkXfermode::Mode mode) {
|
||||
this->drawColor(color, (SkBlendMode)mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Helper method for drawing a color in SRC mode, completely replacing all the pixels
|
||||
|
@ -634,10 +676,18 @@ public:
|
|||
*/
|
||||
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint);
|
||||
|
||||
/** Helper method for drawing a single point. See drawPoints() for more details.
|
||||
*/
|
||||
/** Helper method for drawing a single point. See drawPoints() for a more
|
||||
details.
|
||||
*/
|
||||
void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
|
||||
|
||||
/** Draws a single pixel in the specified color.
|
||||
@param x The X coordinate of which pixel to draw
|
||||
@param y The Y coordiante of which pixel to draw
|
||||
@param color The color to draw
|
||||
*/
|
||||
void drawPoint(SkScalar x, SkScalar y, SkColor color);
|
||||
|
||||
/** Draw a line segment with the specified start and stop x,y coordinates,
|
||||
using the specified paint. NOTE: since a line is always "framed", the
|
||||
paint's Style is ignored.
|
||||
|
@ -647,7 +697,8 @@ public:
|
|||
@param y1 The y-coordinate of the end point of the line
|
||||
@param paint The paint used to draw the line
|
||||
*/
|
||||
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint& paint);
|
||||
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1,
|
||||
const SkPaint& paint);
|
||||
|
||||
/** Draw the specified rectangle using the specified paint. The rectangle
|
||||
will be filled or stroked based on the Style in the paint.
|
||||
|
@ -667,6 +718,17 @@ public:
|
|||
this->drawRect(r, paint);
|
||||
}
|
||||
|
||||
/** Draw the specified rectangle using the specified paint. The rectangle
|
||||
will be filled or framed based on the Style in the paint.
|
||||
@param left The left side of the rectangle to be drawn
|
||||
@param top The top side of the rectangle to be drawn
|
||||
@param right The right side of the rectangle to be drawn
|
||||
@param bottom The bottom side of the rectangle to be drawn
|
||||
@param paint The paint used to draw the rect
|
||||
*/
|
||||
void drawRectCoords(SkScalar left, SkScalar top, SkScalar right,
|
||||
SkScalar bottom, const SkPaint& paint);
|
||||
|
||||
/** Draw the outline of the specified region using the specified paint.
|
||||
@param region The region to be drawn
|
||||
@param paint The paint used to draw the region
|
||||
|
@ -703,7 +765,8 @@ public:
|
|||
@param radius The radius of the cirle to be drawn
|
||||
@param paint The paint used to draw the circle
|
||||
*/
|
||||
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint);
|
||||
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius,
|
||||
const SkPaint& paint);
|
||||
|
||||
/** Draw the specified arc, which will be scaled to fit inside the
|
||||
specified oval. Sweep angles are not treated as modulo 360 and thus can
|
||||
|
@ -729,7 +792,8 @@ public:
|
|||
@param ry The y-radius of the oval used to round the corners
|
||||
@param paint The paint used to draw the roundRect
|
||||
*/
|
||||
void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, const SkPaint& paint);
|
||||
void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,
|
||||
const SkPaint& paint);
|
||||
|
||||
/** Draw the specified path using the specified paint. The path will be
|
||||
filled or framed based on the Style in the paint.
|
||||
|
@ -1112,16 +1176,48 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
/** Draw vertices from an immutable SkVertices object.
|
||||
enum VertexMode {
|
||||
kTriangles_VertexMode,
|
||||
kTriangleStrip_VertexMode,
|
||||
kTriangleFan_VertexMode
|
||||
};
|
||||
|
||||
@param vertices The mesh to draw.
|
||||
@param mode Used if both texs and colors are present and paint has a
|
||||
shader. In this case the colors are combined with the texture
|
||||
using mode, before being drawn using the paint.
|
||||
/** Draw the array of vertices, interpreted as triangles (based on mode).
|
||||
|
||||
If both textures and vertex-colors are NULL, it strokes hairlines with
|
||||
the paint's color. This behavior is a useful debugging mode to visualize
|
||||
the mesh.
|
||||
|
||||
@param vmode How to interpret the array of vertices
|
||||
@param vertexCount The number of points in the vertices array (and
|
||||
corresponding texs and colors arrays if non-null)
|
||||
@param vertices Array of vertices for the mesh
|
||||
@param texs May be null. If not null, specifies the coordinate
|
||||
in _texture_ space (not uv space) for each vertex.
|
||||
@param colors May be null. If not null, specifies a color for each
|
||||
vertex, to be interpolated across the triangle.
|
||||
@param xmode Used if both texs and colors are present. In this
|
||||
case the colors are combined with the texture using mode,
|
||||
before being drawn using the paint. If mode is null, then
|
||||
kModulate_Mode is used.
|
||||
@param indices If not null, array of indices to reference into the
|
||||
vertex (texs, colors) array.
|
||||
@param indexCount number of entries in the indices array (if not null)
|
||||
@param paint Specifies the shader/texture if present.
|
||||
*/
|
||||
void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint);
|
||||
void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint);
|
||||
*/
|
||||
void drawVertices(VertexMode vmode, int vertexCount,
|
||||
const SkPoint vertices[], const SkPoint texs[],
|
||||
const SkColor colors[], SkXfermode* xmode,
|
||||
const uint16_t indices[], int indexCount,
|
||||
const SkPaint& paint);
|
||||
void drawVertices(VertexMode vmode, int vertexCount,
|
||||
const SkPoint vertices[], const SkPoint texs[],
|
||||
const SkColor colors[], const sk_sp<SkXfermode>& xmode,
|
||||
const uint16_t indices[], int indexCount,
|
||||
const SkPaint& paint) {
|
||||
this->drawVertices(vmode, vertexCount, vertices, texs, colors, xmode.get(),
|
||||
indices, indexCount, paint);
|
||||
}
|
||||
|
||||
/**
|
||||
Draw a cubic coons patch
|
||||
|
@ -1132,15 +1228,15 @@ public:
|
|||
their order is clockwise starting at the top left corner.
|
||||
@param texCoords specifies the texture coordinates that will be bilerp across the patch,
|
||||
their order is the same as the colors.
|
||||
@param mode specifies how are the colors and the textures combined if both of them are
|
||||
@param xmode specifies how are the colors and the textures combined if both of them are
|
||||
present.
|
||||
@param paint Specifies the shader/texture if present.
|
||||
*/
|
||||
void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
|
||||
const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint);
|
||||
void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
|
||||
const SkPoint texCoords[4], const SkPaint& paint) {
|
||||
this->drawPatch(cubics, colors, texCoords, SkBlendMode::kModulate, paint);
|
||||
const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
|
||||
void drawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4],
|
||||
const sk_sp<SkXfermode>& xmode, const SkPaint& paint) {
|
||||
this->drawPatch(cubics, colors, texCoords, xmode.get(), paint);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1151,30 +1247,32 @@ public:
|
|||
* xform maps [0, 0, tex.width, tex.height] -> quad
|
||||
*
|
||||
* The color array is optional. When specified, each color modulates the pixels in its
|
||||
* corresponding quad (via the specified SkBlendMode).
|
||||
* corresponding quad (via the specified SkXfermode::Mode).
|
||||
*
|
||||
* The cullRect is optional. When specified, it must be a conservative bounds of all of the
|
||||
* resulting transformed quads, allowing the canvas to skip drawing if the cullRect does not
|
||||
* intersect the current clip.
|
||||
*
|
||||
* The paint is optional. If specified, its antialiasing, alpha, color-filter, image-filter
|
||||
* and blendmode are used to affect each of the quads.
|
||||
* and xfermode are used to affect each of the quads.
|
||||
*/
|
||||
void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
|
||||
const SkColor colors[], int count, SkBlendMode, const SkRect* cullRect,
|
||||
const SkColor colors[], int count, SkXfermode::Mode, const SkRect* cullRect,
|
||||
const SkPaint* paint);
|
||||
void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
|
||||
const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
|
||||
const SkPaint* paint) {
|
||||
this->drawAtlas(atlas.get(), xform, tex, colors, count, mode, cullRect, paint);
|
||||
}
|
||||
|
||||
void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count,
|
||||
const SkRect* cullRect, const SkPaint* paint) {
|
||||
this->drawAtlas(atlas, xform, tex, nullptr, count, SkBlendMode::kDst, cullRect, paint);
|
||||
this->drawAtlas(atlas, xform, tex, NULL, count, SkXfermode::kDst_Mode, cullRect, paint);
|
||||
}
|
||||
|
||||
void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
|
||||
const SkColor colors[], int count, SkXfermode::Mode mode, const SkRect* cull,
|
||||
const SkPaint* paint) {
|
||||
this->drawAtlas(atlas.get(), xform, tex, colors, count, mode, cull, paint);
|
||||
}
|
||||
void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
|
||||
int count, const SkRect* cullRect, const SkPaint* paint) {
|
||||
this->drawAtlas(atlas.get(), xform, tex, nullptr, count, SkBlendMode::kDst,
|
||||
this->drawAtlas(atlas.get(), xform, tex, nullptr, count, SkXfermode::kDst_Mode,
|
||||
cullRect, paint);
|
||||
}
|
||||
|
||||
|
@ -1253,7 +1351,15 @@ public:
|
|||
*/
|
||||
const SkMatrix& getTotalMatrix() const;
|
||||
|
||||
#ifdef SK_SUPPORT_OBSOLETE_REPLAYCLIP
|
||||
/** Return the clip stack. The clip stack stores all the individual
|
||||
* clips organized by the save/restore frame in which they were
|
||||
* added.
|
||||
* @return the current clip stack ("list" of individual clip elements)
|
||||
*/
|
||||
const SkClipStack* getClipStack() const {
|
||||
return fClipStack;
|
||||
}
|
||||
|
||||
typedef SkCanvasClipVisitor ClipVisitor;
|
||||
/**
|
||||
* Replays the clip operations, back to front, that have been applied to
|
||||
|
@ -1261,12 +1367,11 @@ public:
|
|||
* clip. All clips have already been transformed into device space.
|
||||
*/
|
||||
void replayClips(ClipVisitor*) const;
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// don't call
|
||||
GrRenderTargetContext* internal_private_accessTopLayerRenderTargetContext();
|
||||
GrDrawContext* internal_private_accessTopLayerDrawContext();
|
||||
|
||||
// don't call
|
||||
static void Internal_Private_SetIgnoreSaveLayerBounds(bool);
|
||||
|
@ -1288,12 +1393,6 @@ public:
|
|||
*/
|
||||
void temporary_internal_describeTopLayer(SkMatrix* matrix, SkIRect* clip_bounds);
|
||||
|
||||
/**
|
||||
* Returns the global clip as a region. If the clip contains AA, then only the bounds
|
||||
* of the clip may be returned.
|
||||
*/
|
||||
void temporary_internal_getRgnClip(SkRegion*);
|
||||
|
||||
protected:
|
||||
#ifdef SK_EXPERIMENTAL_SHADOWING
|
||||
/** Returns the current (cumulative) draw depth of the canvas.
|
||||
|
@ -1338,10 +1437,6 @@ protected:
|
|||
virtual void didTranslateZ(SkScalar) {}
|
||||
#endif
|
||||
|
||||
virtual SkRect onGetLocalClipBounds() const;
|
||||
virtual SkIRect onGetDeviceClipBounds() const;
|
||||
|
||||
|
||||
virtual void onDrawAnnotation(const SkRect&, const char key[], SkData* value);
|
||||
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
|
||||
|
||||
|
@ -1365,7 +1460,7 @@ protected:
|
|||
const SkPaint& paint);
|
||||
|
||||
virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
|
||||
const SkPoint texCoords[4], SkBlendMode, const SkPaint& paint);
|
||||
const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
|
||||
|
||||
virtual void onDrawDrawable(SkDrawable*, const SkMatrix*);
|
||||
|
||||
|
@ -1377,9 +1472,12 @@ protected:
|
|||
const SkPaint&);
|
||||
virtual void onDrawRRect(const SkRRect&, const SkPaint&);
|
||||
virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&);
|
||||
virtual void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&);
|
||||
virtual void onDrawVertices(VertexMode, int vertexCount, const SkPoint vertices[],
|
||||
const SkPoint texs[], const SkColor colors[], SkXfermode*,
|
||||
const uint16_t indices[], int indexCount, const SkPaint&);
|
||||
|
||||
virtual void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
|
||||
int count, SkBlendMode, const SkRect* cull, const SkPaint*);
|
||||
int count, SkXfermode::Mode, const SkRect* cull, const SkPaint*);
|
||||
virtual void onDrawPath(const SkPath&, const SkPaint&);
|
||||
virtual void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*);
|
||||
virtual void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*,
|
||||
|
@ -1402,10 +1500,10 @@ protected:
|
|||
kSoft_ClipEdgeStyle
|
||||
};
|
||||
|
||||
virtual void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle);
|
||||
virtual void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle);
|
||||
virtual void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle);
|
||||
virtual void onClipRegion(const SkRegion& deviceRgn, SkClipOp);
|
||||
virtual void onClipRect(const SkRect& rect, ClipOp, ClipEdgeStyle);
|
||||
virtual void onClipRRect(const SkRRect& rrect, ClipOp, ClipEdgeStyle);
|
||||
virtual void onClipPath(const SkPath& path, ClipOp, ClipEdgeStyle);
|
||||
virtual void onClipRegion(const SkRegion& deviceRgn, ClipOp);
|
||||
|
||||
virtual void onDiscard();
|
||||
|
||||
|
@ -1417,6 +1515,12 @@ protected:
|
|||
const SkPaint*,
|
||||
const SkShadowParams& params);
|
||||
#endif
|
||||
|
||||
// Returns the canvas to be used by DrawIter. Default implementation
|
||||
// returns this. Subclasses that encapsulate an indirect canvas may
|
||||
// need to overload this method. The impl must keep track of this, as it
|
||||
// is not released or deleted by the caller.
|
||||
virtual SkCanvas* canvasForDrawIter();
|
||||
|
||||
// Clip rectangle bounds. Called internally by saveLayer.
|
||||
// returns false if the entire rectangle is entirely clipped out
|
||||
|
@ -1447,7 +1551,7 @@ private:
|
|||
|
||||
SkBaseDevice* device() const;
|
||||
const SkMatrix& matrix() const;
|
||||
void clip(SkRegion*) const;
|
||||
const SkRasterClip& clip() const;
|
||||
const SkPaint& paint() const;
|
||||
int x() const;
|
||||
int y() const;
|
||||
|
@ -1463,13 +1567,13 @@ private:
|
|||
SkPaint fDefaultPaint;
|
||||
bool fDone;
|
||||
};
|
||||
|
||||
|
||||
static bool BoundsAffectsClip(SaveLayerFlags);
|
||||
static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFlags);
|
||||
|
||||
static void DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filter,
|
||||
SkBaseDevice* dst, const SkIPoint& dstOrigin,
|
||||
const SkMatrix& ctm);
|
||||
SkBaseDevice* dst, const SkMatrix& ctm,
|
||||
const SkClipStack* clipStack);
|
||||
|
||||
enum ShaderOverrideOpacity {
|
||||
kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitmap or image)
|
||||
|
@ -1486,13 +1590,9 @@ private:
|
|||
: kNotOpaque_ShaderOverrideOpacity);
|
||||
}
|
||||
|
||||
public:
|
||||
SkBaseDevice* getDevice() const;
|
||||
SkBaseDevice* getTopDevice() const;
|
||||
private:
|
||||
|
||||
class MCRec;
|
||||
|
||||
SkAutoTUnref<SkClipStack> fClipStack;
|
||||
SkDeque fMCStack;
|
||||
// points to top of stack
|
||||
MCRec* fMCRec;
|
||||
|
@ -1500,7 +1600,7 @@ private:
|
|||
enum {
|
||||
kMCRecSize = 128, // most recent measurement
|
||||
kMCRecCount = 32, // common depth for save/restores
|
||||
kDeviceCMSize = 184, // most recent measurement
|
||||
kDeviceCMSize = 176, // most recent measurement
|
||||
};
|
||||
intptr_t fMCRecStorage[kMCRecSize * kMCRecCount / sizeof(intptr_t)];
|
||||
intptr_t fDeviceCMStorage[kDeviceCMSize / sizeof(intptr_t)];
|
||||
|
@ -1510,7 +1610,6 @@ private:
|
|||
int fSaveCount; // value returned by getSaveCount()
|
||||
|
||||
SkMetaData* fMetaData;
|
||||
std::unique_ptr<SkRasterHandleAllocator> fAllocator;
|
||||
|
||||
SkSurface_Base* fSurfaceBase;
|
||||
SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
|
||||
|
@ -1520,7 +1619,8 @@ private:
|
|||
friend class SkSurface_Base;
|
||||
friend class SkSurface_Gpu;
|
||||
|
||||
SkIRect fClipRestrictionRect = SkIRect::MakeEmpty();
|
||||
bool fDeviceCMDirty; // cleared by updateDeviceCMCache()
|
||||
void updateDeviceCMCache();
|
||||
|
||||
void doSave();
|
||||
void checkForDeferredSave();
|
||||
|
@ -1528,17 +1628,15 @@ private:
|
|||
|
||||
friend class SkDrawIter; // needs setupDrawForLayerDevice()
|
||||
friend class AutoDrawLooper;
|
||||
friend class SkLua; // needs top layer size and offset
|
||||
friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip
|
||||
friend class SkSurface_Raster; // needs getDevice()
|
||||
friend class SkRecorder; // resetForNextPicture
|
||||
friend class SkLiteRecorder; // resetForNextPicture
|
||||
friend class SkNoDrawCanvas; // InitFlags
|
||||
friend class SkRecorder; // InitFlags
|
||||
friend class SkLiteRecorder; // InitFlags
|
||||
friend class SkNoSaveLayerCanvas; // InitFlags
|
||||
friend class SkPictureImageFilter; // SkCanvas(SkBaseDevice*, SkSurfaceProps*, InitFlags)
|
||||
friend class SkPictureRecord; // predrawNotify (why does it need it? <reed>)
|
||||
friend class SkPicturePlayback; // SaveFlagsToSaveLayerFlags
|
||||
friend class SkDeferredCanvas; // For use of resetForNextPicture
|
||||
friend class SkOverdrawCanvas;
|
||||
friend class SkRasterHandleAllocator;
|
||||
|
||||
enum InitFlags {
|
||||
kDefault_InitFlags = 0,
|
||||
|
@ -1546,8 +1644,6 @@ private:
|
|||
};
|
||||
SkCanvas(const SkIRect& bounds, InitFlags);
|
||||
SkCanvas(SkBaseDevice* device, InitFlags);
|
||||
SkCanvas(const SkBitmap&, std::unique_ptr<SkRasterHandleAllocator>,
|
||||
SkRasterHandleAllocator::Handle);
|
||||
|
||||
void resetForNextPicture(const SkIRect& bounds);
|
||||
|
||||
|
@ -1577,6 +1673,14 @@ private:
|
|||
// shared by save() and saveLayer()
|
||||
void internalSave();
|
||||
void internalRestore();
|
||||
static void DrawRect(const SkDraw& draw, const SkPaint& paint,
|
||||
const SkRect& r, SkScalar textSize);
|
||||
static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint,
|
||||
const char text[], size_t byteLength,
|
||||
SkScalar x, SkScalar y);
|
||||
|
||||
// only for canvasutils
|
||||
const SkRegion& internal_private_getTotalClip() const;
|
||||
|
||||
/*
|
||||
* Returns true if drawing the specified rect (or all if it is null) with the specified
|
||||
|
@ -1590,11 +1694,6 @@ private:
|
|||
*/
|
||||
bool canDrawBitmapAsSprite(SkScalar x, SkScalar y, int w, int h, const SkPaint&);
|
||||
|
||||
/**
|
||||
* Returns true if the clip (for any active layer) contains antialiasing.
|
||||
* If the clip is empty, this will return false.
|
||||
*/
|
||||
bool androidFramework_isClipAA() const;
|
||||
|
||||
/**
|
||||
* Keep track of the device clip bounds and if the matrix is scale-translate. This allows
|
||||
|
@ -1605,6 +1704,7 @@ private:
|
|||
|
||||
bool fAllowSoftClip;
|
||||
bool fAllowSimplifyClip;
|
||||
const bool fConservativeRasterClip;
|
||||
|
||||
class AutoValidateClip : ::SkNoncopyable {
|
||||
public:
|
||||
|
@ -1663,14 +1763,12 @@ private:
|
|||
};
|
||||
#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
|
||||
|
||||
#ifdef SK_SUPPORT_OBSOLETE_REPLAYCLIP
|
||||
class SkCanvasClipVisitor {
|
||||
public:
|
||||
virtual ~SkCanvasClipVisitor();
|
||||
virtual void clipRect(const SkRect&, SkClipOp, bool antialias) = 0;
|
||||
virtual void clipRRect(const SkRRect&, SkClipOp, bool antialias) = 0;
|
||||
virtual void clipPath(const SkPath&, SkClipOp, bool antialias) = 0;
|
||||
virtual void clipRect(const SkRect&, SkCanvas::ClipOp, bool antialias) = 0;
|
||||
virtual void clipRRect(const SkRRect&, SkCanvas::ClipOp, bool antialias) = 0;
|
||||
virtual void clipPath(const SkPath&, SkCanvas::ClipOp, bool antialias) = 0;
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
|
||||
/*
|
||||
* Copyright 2006 The Android Open Source Project
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SkChunkAlloc_DEFINED
|
||||
#define SkChunkAlloc_DEFINED
|
||||
|
||||
#include "SkTypes.h"
|
||||
|
||||
class SkChunkAlloc : SkNoncopyable {
|
||||
public:
|
||||
SkChunkAlloc(size_t minSize);
|
||||
~SkChunkAlloc();
|
||||
|
||||
/**
|
||||
* Free up all allocated blocks. This invalidates all returned
|
||||
* pointers.
|
||||
*/
|
||||
void reset();
|
||||
/**
|
||||
* Reset to 0 used bytes preserving as much memory as possible.
|
||||
* This invalidates all returned pointers.
|
||||
*/
|
||||
void rewind();
|
||||
|
||||
enum AllocFailType {
|
||||
kReturnNil_AllocFailType,
|
||||
kThrow_AllocFailType
|
||||
};
|
||||
|
||||
/**
|
||||
* Allocates a memory block of size bytes.
|
||||
* On success: returns a pointer to beginning of memory block that is
|
||||
* 8 byte aligned. The content of allocated block is not initialized.
|
||||
* On failure: calls abort() if called with kThrow_AllocFailType,
|
||||
* otherwise returns NULL pointer.
|
||||
*/
|
||||
void* alloc(size_t bytes, AllocFailType);
|
||||
|
||||
/**
|
||||
* Shortcut for calling alloc with kThrow_AllocFailType.
|
||||
*/
|
||||
void* allocThrow(size_t bytes) {
|
||||
return this->alloc(bytes, kThrow_AllocFailType);
|
||||
}
|
||||
|
||||
/** Call this to unalloc the most-recently allocated ptr by alloc(). On
|
||||
success, the number of bytes freed is returned, or 0 if the block could
|
||||
not be unallocated. This is a hint to the underlying allocator that
|
||||
the previous allocation may be reused, but the implementation is free
|
||||
to ignore this call (and return 0).
|
||||
*/
|
||||
size_t unalloc(void* ptr);
|
||||
|
||||
size_t totalCapacity() const { return fTotalCapacity; }
|
||||
size_t totalUsed() const { return fTotalUsed; }
|
||||
SkDEBUGCODE(int blockCount() const { return fBlockCount; })
|
||||
SkDEBUGCODE(size_t totalLost() const { return fTotalLost; })
|
||||
|
||||
/**
|
||||
* Returns true if the specified address is within one of the chunks, and
|
||||
* has at least 1-byte following the address (i.e. if addr points to the
|
||||
* end of a chunk, then contains() will return false).
|
||||
*/
|
||||
bool contains(const void* addr) const;
|
||||
|
||||
private:
|
||||
struct Block;
|
||||
|
||||
Block* fBlock;
|
||||
size_t fMinSize;
|
||||
size_t fChunkSize;
|
||||
size_t fTotalCapacity;
|
||||
size_t fTotalUsed; // will be <= fTotalCapacity
|
||||
SkDEBUGCODE(int fBlockCount;)
|
||||
SkDEBUGCODE(size_t fTotalLost;) // will be <= fTotalCapacity
|
||||
|
||||
Block* newBlock(size_t bytes, AllocFailType ftype);
|
||||
Block* addBlockIfNecessary(size_t bytes, AllocFailType ftype);
|
||||
|
||||
SkDEBUGCODE(void validate();)
|
||||
};
|
||||
|
||||
#endif
|
|
@ -10,20 +10,17 @@
|
|||
|
||||
#include "SkTypes.h"
|
||||
|
||||
// SkClipOp enum values always match the corresponding values in SkRegion::Op
|
||||
|
||||
enum class SkClipOp {
|
||||
kDifference = 0,
|
||||
kIntersect = 1,
|
||||
// these kept in SkRegion::Op order for now ...
|
||||
enum SkClipOp {
|
||||
kDifference_SkClipOp = 0,
|
||||
kIntersect_SkClipOp = 1,
|
||||
|
||||
// Goal: remove these, since they can grow the current clip
|
||||
|
||||
kUnion_deprecated = 2,
|
||||
kXOR_deprecated = 3,
|
||||
kReverseDifference_deprecated = 4,
|
||||
kReplace_deprecated = 5,
|
||||
|
||||
kMax_EnumValue = kReplace_deprecated,
|
||||
kUnion_SkClipOp = 2,
|
||||
kXOR_SkClipOp = 3,
|
||||
kReverseDifference_SkClipOp = 4,
|
||||
kReplace_SkClipOp = 5,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,22 +8,15 @@
|
|||
#ifndef SkClipStack_DEFINED
|
||||
#define SkClipStack_DEFINED
|
||||
|
||||
#include "../private/SkMessageBus.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkDeque.h"
|
||||
#include "SkPath.h"
|
||||
#include "SkRRect.h"
|
||||
#include "SkRect.h"
|
||||
#include "SkRRect.h"
|
||||
#include "SkRegion.h"
|
||||
#include "SkTLazy.h"
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrResourceKey.h"
|
||||
#endif
|
||||
|
||||
#ifdef SK_SUPPORT_OBSOLETE_REPLAYCLIP
|
||||
class SkCanvasClipVisitor;
|
||||
#endif
|
||||
|
||||
// Because a single save/restore state can have multiple clips, this class
|
||||
// stores the stack depth (fSaveCount) and clips (fDeque) separately.
|
||||
|
@ -31,7 +24,7 @@ class SkCanvasClipVisitor;
|
|||
// (i.e., the fSaveCount in force when it was added). Restores are thus
|
||||
// implemented by removing clips from fDeque that have an fSaveCount larger
|
||||
// then the freshly decremented count.
|
||||
class SkClipStack {
|
||||
class SK_API SkClipStack : public SkNVRefCnt<SkClipStack> {
|
||||
public:
|
||||
enum BoundsType {
|
||||
// The bounding box contains all the pixels that can be written to
|
||||
|
@ -61,32 +54,24 @@ public:
|
|||
static const int kTypeCnt = kLastType + 1;
|
||||
|
||||
Element() {
|
||||
this->initCommon(0, SkClipOp::kReplace_deprecated, false);
|
||||
this->initCommon(0, SkCanvas::kReplace_Op, false);
|
||||
this->setEmpty();
|
||||
}
|
||||
|
||||
Element(const Element&);
|
||||
|
||||
Element(const SkRect& rect, SkClipOp op, bool doAA) {
|
||||
Element(const SkRect& rect, SkCanvas::ClipOp op, bool doAA) {
|
||||
this->initRect(0, rect, op, doAA);
|
||||
}
|
||||
|
||||
Element(const SkRRect& rrect, SkClipOp op, bool doAA) {
|
||||
Element(const SkRRect& rrect, SkCanvas::ClipOp op, bool doAA) {
|
||||
this->initRRect(0, rrect, op, doAA);
|
||||
}
|
||||
|
||||
Element(const SkPath& path, SkClipOp op, bool doAA) {
|
||||
Element(const SkPath& path, SkCanvas::ClipOp op, bool doAA) {
|
||||
this->initPath(0, path, op, doAA);
|
||||
}
|
||||
|
||||
~Element() {
|
||||
#if SK_SUPPORT_GPU
|
||||
for (int i = 0; i < fMessages.count(); ++i) {
|
||||
SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(*fMessages[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool operator== (const Element& element) const;
|
||||
bool operator!= (const Element& element) const { return !(*this == element); }
|
||||
|
||||
|
@ -109,7 +94,7 @@ public:
|
|||
}
|
||||
|
||||
//!< Call if getType() is not kEmpty to get the set operation used to combine this element.
|
||||
SkClipOp getOp() const { return fOp; }
|
||||
SkCanvas::ClipOp getOp() const { return fOp; }
|
||||
|
||||
//!< Call to get the element as a path, regardless of its type.
|
||||
void asPath(SkPath* path) const;
|
||||
|
@ -125,7 +110,7 @@ public:
|
|||
void invertShapeFillType();
|
||||
|
||||
//!< Sets the set operation represented by the element.
|
||||
void setOp(SkClipOp op) { fOp = op; }
|
||||
void setOp(SkCanvas::ClipOp op) { fOp = op; }
|
||||
|
||||
/** The GenID can be used by clip stack clients to cache representations of the clip. The
|
||||
ID corresponds to the set of clip elements up to and including this element within the
|
||||
|
@ -198,12 +183,10 @@ public:
|
|||
return kPath_Type == fType && fPath.get()->isInverseFillType();
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_OBSOLETE_REPLAYCLIP
|
||||
/**
|
||||
* Replay this clip into the visitor.
|
||||
*/
|
||||
void replay(SkCanvasClipVisitor*) const;
|
||||
#endif
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
/**
|
||||
|
@ -213,26 +196,15 @@ public:
|
|||
void dump() const;
|
||||
#endif
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
/**
|
||||
* This is used to purge any GPU resource cache items that become unreachable when
|
||||
* the element is destroyed because their key is based on this element's gen ID.
|
||||
*/
|
||||
void addResourceInvalidationMessage(
|
||||
std::unique_ptr<GrUniqueKeyInvalidatedMessage> msg) const {
|
||||
fMessages.emplace_back(std::move(msg));
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
friend class SkClipStack;
|
||||
|
||||
SkTLazy<SkPath> fPath;
|
||||
SkRRect fRRect;
|
||||
int fSaveCount; // save count of stack when this element was added.
|
||||
SkClipOp fOp;
|
||||
Type fType;
|
||||
bool fDoAA;
|
||||
SkRRect fRRect;
|
||||
int fSaveCount; // save count of stack when this element was added.
|
||||
SkCanvas::ClipOp fOp;
|
||||
Type fType;
|
||||
bool fDoAA;
|
||||
|
||||
/* fFiniteBoundType and fFiniteBound are used to incrementally update the clip stack's
|
||||
bound. When fFiniteBoundType is kNormal_BoundsType, fFiniteBound represents the
|
||||
|
@ -245,34 +217,32 @@ public:
|
|||
can capture the cancelling out of the extensions to infinity when two inverse filled
|
||||
clips are Booleaned together. */
|
||||
SkClipStack::BoundsType fFiniteBoundType;
|
||||
SkRect fFiniteBound;
|
||||
SkRect fFiniteBound;
|
||||
|
||||
// When element is applied to the previous elements in the stack is the result known to be
|
||||
// equivalent to a single rect intersection? IIOW, is the clip effectively a rectangle.
|
||||
bool fIsIntersectionOfRects;
|
||||
bool fIsIntersectionOfRects;
|
||||
|
||||
int fGenID;
|
||||
|
||||
int fGenID;
|
||||
#if SK_SUPPORT_GPU
|
||||
mutable SkTArray<std::unique_ptr<GrUniqueKeyInvalidatedMessage>> fMessages;
|
||||
#endif
|
||||
Element(int saveCount) {
|
||||
this->initCommon(saveCount, SkClipOp::kReplace_deprecated, false);
|
||||
this->initCommon(saveCount, SkCanvas::kReplace_Op, false);
|
||||
this->setEmpty();
|
||||
}
|
||||
|
||||
Element(int saveCount, const SkRRect& rrect, SkClipOp op, bool doAA) {
|
||||
Element(int saveCount, const SkRRect& rrect, SkCanvas::ClipOp op, bool doAA) {
|
||||
this->initRRect(saveCount, rrect, op, doAA);
|
||||
}
|
||||
|
||||
Element(int saveCount, const SkRect& rect, SkClipOp op, bool doAA) {
|
||||
Element(int saveCount, const SkRect& rect, SkCanvas::ClipOp op, bool doAA) {
|
||||
this->initRect(saveCount, rect, op, doAA);
|
||||
}
|
||||
|
||||
Element(int saveCount, const SkPath& path, SkClipOp op, bool doAA) {
|
||||
Element(int saveCount, const SkPath& path, SkCanvas::ClipOp op, bool doAA) {
|
||||
this->initPath(saveCount, path, op, doAA);
|
||||
}
|
||||
|
||||
void initCommon(int saveCount, SkClipOp op, bool doAA) {
|
||||
void initCommon(int saveCount, SkCanvas::ClipOp op, bool doAA) {
|
||||
fSaveCount = saveCount;
|
||||
fOp = op;
|
||||
fDoAA = doAA;
|
||||
|
@ -284,13 +254,13 @@ public:
|
|||
fGenID = kInvalidGenID;
|
||||
}
|
||||
|
||||
void initRect(int saveCount, const SkRect& rect, SkClipOp op, bool doAA) {
|
||||
void initRect(int saveCount, const SkRect& rect, SkCanvas::ClipOp op, bool doAA) {
|
||||
fRRect.setRect(rect);
|
||||
fType = kRect_Type;
|
||||
this->initCommon(saveCount, op, doAA);
|
||||
}
|
||||
|
||||
void initRRect(int saveCount, const SkRRect& rrect, SkClipOp op, bool doAA) {
|
||||
void initRRect(int saveCount, const SkRRect& rrect, SkCanvas::ClipOp op, bool doAA) {
|
||||
SkRRect::Type type = rrect.getType();
|
||||
fRRect = rrect;
|
||||
if (SkRRect::kRect_Type == type || SkRRect::kEmpty_Type == type) {
|
||||
|
@ -301,13 +271,13 @@ public:
|
|||
this->initCommon(saveCount, op, doAA);
|
||||
}
|
||||
|
||||
void initPath(int saveCount, const SkPath& path, SkClipOp op, bool doAA);
|
||||
void initPath(int saveCount, const SkPath& path, SkCanvas::ClipOp op, bool doAA);
|
||||
|
||||
void setEmpty();
|
||||
|
||||
// All Element methods below are only used within SkClipStack.cpp
|
||||
inline void checkEmpty() const;
|
||||
inline bool canBeIntersectedInPlace(int saveCount, SkClipOp op) const;
|
||||
inline bool canBeIntersectedInPlace(int saveCount, SkCanvas::ClipOp op) const;
|
||||
/* This method checks to see if two rect clips can be safely merged into one. The issue here
|
||||
is that to be strictly correct all the edges of the resulting rect must have the same
|
||||
anti-aliasing. */
|
||||
|
@ -331,7 +301,6 @@ public:
|
|||
};
|
||||
|
||||
SkClipStack();
|
||||
SkClipStack(void* storage, size_t size);
|
||||
SkClipStack(const SkClipStack& b);
|
||||
~SkClipStack();
|
||||
|
||||
|
@ -345,27 +314,6 @@ public:
|
|||
void save();
|
||||
void restore();
|
||||
|
||||
class AutoRestore {
|
||||
public:
|
||||
AutoRestore(SkClipStack* cs, bool doSave)
|
||||
: fCS(cs), fSaveCount(cs->getSaveCount())
|
||||
{
|
||||
if (doSave) {
|
||||
fCS->save();
|
||||
}
|
||||
}
|
||||
~AutoRestore() {
|
||||
SkASSERT(fCS->getSaveCount() >= fSaveCount); // no underflow
|
||||
while (fCS->getSaveCount() > fSaveCount) {
|
||||
fCS->restore();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
SkClipStack* fCS;
|
||||
const int fSaveCount;
|
||||
};
|
||||
|
||||
/**
|
||||
* getBounds places the current finite bound in its first parameter. In its
|
||||
* second, it indicates which kind of bound is being returned. If
|
||||
|
@ -379,9 +327,6 @@ public:
|
|||
BoundsType* boundType,
|
||||
bool* isIntersectionOfRects = NULL) const;
|
||||
|
||||
SkRect bounds(const SkIRect& deviceBounds) const;
|
||||
bool isEmpty(const SkIRect& deviceBounds) const;
|
||||
|
||||
/**
|
||||
* Returns true if the input (r)rect in device space is entirely contained
|
||||
* by the clip. A return value of false does not guarantee that the (r)rect
|
||||
|
@ -401,19 +346,16 @@ public:
|
|||
*/
|
||||
bool asPath(SkPath* path) const;
|
||||
|
||||
void clipDevRect(const SkIRect& ir, SkClipOp op) {
|
||||
void clipDevRect(const SkIRect& ir, SkCanvas::ClipOp op) {
|
||||
SkRect r;
|
||||
r.set(ir);
|
||||
this->clipRect(r, SkMatrix::I(), op, false);
|
||||
}
|
||||
void clipRect(const SkRect&, const SkMatrix& matrix, SkClipOp, bool doAA);
|
||||
void clipRRect(const SkRRect&, const SkMatrix& matrix, SkClipOp, bool doAA);
|
||||
void clipPath(const SkPath&, const SkMatrix& matrix, SkClipOp, bool doAA);
|
||||
void clipRect(const SkRect&, const SkMatrix& matrix, SkCanvas::ClipOp, bool doAA);
|
||||
void clipRRect(const SkRRect&, const SkMatrix& matrix, SkCanvas::ClipOp, bool doAA);
|
||||
void clipPath(const SkPath&, const SkMatrix& matrix, SkCanvas::ClipOp, bool doAA);
|
||||
// An optimized version of clipDevRect(emptyRect, kIntersect, ...)
|
||||
void clipEmpty();
|
||||
void setDeviceClipRestriction(const SkIRect& rect) {
|
||||
fClipRestrictionRect = SkRect::Make(rect);
|
||||
}
|
||||
|
||||
/**
|
||||
* isWideOpen returns true if the clip state corresponds to the infinite
|
||||
|
@ -482,7 +424,7 @@ public:
|
|||
* Moves the iterator to the topmost element with the specified RegionOp and returns that
|
||||
* element. If no clip element with that op is found, the first element is returned.
|
||||
*/
|
||||
const Element* skipToTopmost(SkClipOp op);
|
||||
const Element* skipToTopmost(SkCanvas::ClipOp op);
|
||||
|
||||
/**
|
||||
* Restarts the iterator on a clip stack.
|
||||
|
@ -555,7 +497,6 @@ private:
|
|||
// clipDevRect and clipDevPath call. 0 is reserved to indicate an
|
||||
// invalid ID.
|
||||
static int32_t gGenID;
|
||||
SkRect fClipRestrictionRect = SkRect::MakeEmpty();
|
||||
|
||||
bool internalQuickContains(const SkRect& devRect) const;
|
||||
bool internalQuickContains(const SkRRect& devRRect) const;
|
||||
|
@ -570,10 +511,6 @@ private:
|
|||
*/
|
||||
void restoreTo(int saveCount);
|
||||
|
||||
inline bool hasClipRestriction(SkClipOp op) {
|
||||
return op >= SkClipOp::kUnion_deprecated && !fClipRestrictionRect.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the next unique generation ID.
|
||||
*/
|
|
@ -67,7 +67,7 @@ static inline SkColor SkColorSetARGBInline(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
|
|||
/** return the blue byte from a SkColor value */
|
||||
#define SkColorGetB(color) (((color) >> 0) & 0xFF)
|
||||
|
||||
static constexpr inline SkColor SkColorSetA(SkColor c, U8CPU a) {
|
||||
static inline SkColor SkColorSetA(SkColor c, U8CPU a) {
|
||||
return (c & 0x00FFFFFF) | (a << 24);
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,6 @@ struct SkColor4f {
|
|||
float* vec() { return &fR; }
|
||||
|
||||
static SkColor4f Pin(float r, float g, float b, float a);
|
||||
/** Convert to SkColor4f, assuming SkColor is sRGB */
|
||||
static SkColor4f FromColor(SkColor);
|
||||
static SkColor4f FromColor3f(SkColor3f, float a);
|
||||
|
||||
|
|
|
@ -8,16 +8,14 @@
|
|||
#ifndef SkColorFilter_DEFINED
|
||||
#define SkColorFilter_DEFINED
|
||||
|
||||
#include "SkBlendMode.h"
|
||||
#include "SkColor.h"
|
||||
#include "SkFlattenable.h"
|
||||
#include "SkRefCnt.h"
|
||||
#include "SkXfermode.h"
|
||||
|
||||
class GrContext;
|
||||
class GrFragmentProcessor;
|
||||
class SkArenaAlloc;
|
||||
class SkBitmap;
|
||||
class SkColorSpace;
|
||||
class SkRasterPipeline;
|
||||
|
||||
/**
|
||||
|
@ -35,7 +33,7 @@ public:
|
|||
* returns true, and sets (if not NULL) the color and mode appropriately.
|
||||
* If not, this returns false and ignores the parameters.
|
||||
*/
|
||||
virtual bool asColorMode(SkColor* color, SkBlendMode* bmode) const;
|
||||
virtual bool asColorMode(SkColor* color, SkXfermode::Mode* mode) const;
|
||||
|
||||
/**
|
||||
* If the filter can be represented by a 5x4 matrix, this
|
||||
|
@ -73,8 +71,7 @@ public:
|
|||
|
||||
virtual void filterSpan4f(const SkPM4f src[], int count, SkPM4f result[]) const;
|
||||
|
||||
bool appendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
|
||||
bool shaderIsOpaque) const;
|
||||
bool appendStages(SkRasterPipeline*) const;
|
||||
|
||||
enum Flags {
|
||||
/** If set the filter methods will not change the alpha channel of the colors.
|
||||
|
@ -112,12 +109,15 @@ public:
|
|||
If the Mode is DST, this function will return NULL (since that
|
||||
mode will have no effect on the result).
|
||||
@param c The source color used with the specified mode
|
||||
@param mode The blend that is applied to each color in
|
||||
@param mode The xfermode mode that is applied to each color in
|
||||
the colorfilter's filterSpan[16,32] methods
|
||||
@return colorfilter object that applies the src color and mode,
|
||||
or NULL if the mode will have no effect.
|
||||
*/
|
||||
static sk_sp<SkColorFilter> MakeModeFilter(SkColor c, SkBlendMode mode);
|
||||
static sk_sp<SkColorFilter> MakeModeFilter(SkColor c, SkXfermode::Mode mode);
|
||||
static sk_sp<SkColorFilter> MakeModeFilter(SkColor c, SkBlendMode mode) {
|
||||
return MakeModeFilter(c, (SkXfermode::Mode)mode);
|
||||
}
|
||||
|
||||
/** Construct a colorfilter whose effect is to first apply the inner filter and then apply
|
||||
* the outer filter to the result of the inner's.
|
||||
|
@ -134,6 +134,21 @@ public:
|
|||
*/
|
||||
static sk_sp<SkColorFilter> MakeMatrixFilterRowMajor255(const SkScalar array[20]);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
|
||||
static SkColorFilter* CreateModeFilter(SkColor c, SkXfermode::Mode mode) {
|
||||
return MakeModeFilter(c, mode).release();
|
||||
}
|
||||
static SkColorFilter* CreateComposeFilter(SkColorFilter* outer, SkColorFilter* inner) {
|
||||
return MakeComposeFilter(sk_ref_sp(outer), sk_ref_sp(inner)).release();
|
||||
}
|
||||
static SkColorFilter* CreateMatrixFilterRowMajor255(const SkScalar array[20]) {
|
||||
return MakeMatrixFilterRowMajor255(array).release();
|
||||
}
|
||||
virtual SkColorFilter* newComposed(const SkColorFilter* inner) const {
|
||||
return this->makeComposed(sk_ref_sp(const_cast<SkColorFilter*>(inner))).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
/**
|
||||
* A subclass may implement this factory function to work with the GPU backend. It returns
|
||||
|
@ -144,8 +159,7 @@ public:
|
|||
*
|
||||
* A null return indicates that the color filter isn't implemented for the GPU backend.
|
||||
*/
|
||||
virtual sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*,
|
||||
SkColorSpace* dstColorSpace) const;
|
||||
virtual sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*) const;
|
||||
#endif
|
||||
|
||||
bool affectsTransparentBlack() const {
|
||||
|
@ -160,8 +174,7 @@ public:
|
|||
protected:
|
||||
SkColorFilter() {}
|
||||
|
||||
virtual bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
|
||||
bool shaderIsOpaque) const;
|
||||
virtual bool onAppendStages(SkRasterPipeline*) const;
|
||||
|
||||
private:
|
||||
/*
|
||||
|
|
|
@ -204,8 +204,12 @@ static inline unsigned Sk255To256(U8CPU value) {
|
|||
* for [0,255] value and [0,256] alpha256.
|
||||
*/
|
||||
static inline U16CPU SkAlphaMulInv256(U16CPU value, U16CPU alpha256) {
|
||||
#ifdef SK_SUPPORT_LEGACY_BROKEN_LERP
|
||||
return SkAlpha255To256(255 - SkAlphaMul(value, alpha256));
|
||||
#else
|
||||
unsigned prod = 0xFFFF - value * alpha256;
|
||||
return (prod + (prod >> 8)) >> 8;
|
||||
#endif
|
||||
}
|
||||
|
||||
// The caller may want negative values, so keep all params signed (int)
|
||||
|
@ -580,13 +584,22 @@ static inline SkPMColor SkPMSrcOver(SkPMColor src, SkPMColor dst) {
|
|||
* Interpolates between colors src and dst using [0,256] scale.
|
||||
*/
|
||||
static inline SkPMColor SkPMLerp(SkPMColor src, SkPMColor dst, unsigned scale) {
|
||||
#ifdef SK_SUPPORT_LEGACY_BROKEN_LERP
|
||||
return SkAlphaMulQ(src, scale) + SkAlphaMulQ(dst, 256 - scale);
|
||||
#else
|
||||
return SkFastFourByteInterp256(src, dst, scale);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline SkPMColor SkBlendARGB32(SkPMColor src, SkPMColor dst, U8CPU aa) {
|
||||
SkASSERT((unsigned)aa <= 255);
|
||||
|
||||
unsigned src_scale = SkAlpha255To256(aa);
|
||||
#ifdef SK_SUPPORT_LEGACY_BROKEN_LERP
|
||||
unsigned dst_scale = SkAlpha255To256(255 - SkAlphaMul(SkGetPackedA32(src), src_scale));
|
||||
|
||||
return SkAlphaMulQ(src, src_scale) + SkAlphaMulQ(dst, dst_scale);
|
||||
#else
|
||||
unsigned dst_scale = SkAlphaMulInv256(SkGetPackedA32(src), src_scale);
|
||||
|
||||
const uint32_t mask = 0xFF00FF;
|
||||
|
@ -598,6 +611,7 @@ static inline SkPMColor SkBlendARGB32(SkPMColor src, SkPMColor dst, U8CPU aa) {
|
|||
uint32_t dst_ag = ((dst >> 8) & mask) * dst_scale;
|
||||
|
||||
return (((src_rb + dst_rb) >> 8) & mask) | ((src_ag + dst_ag) & ~mask);
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -13,62 +13,31 @@
|
|||
|
||||
class SkData;
|
||||
|
||||
/**
|
||||
* Describes a color gamut with primaries and a white point.
|
||||
*/
|
||||
struct SK_API SkColorSpacePrimaries {
|
||||
float fRX, fRY;
|
||||
float fGX, fGY;
|
||||
float fBX, fBY;
|
||||
float fWX, fWY;
|
||||
|
||||
/**
|
||||
* Convert primaries and a white point to a toXYZD50 matrix, the preferred color gamut
|
||||
* representation of SkColorSpace.
|
||||
*/
|
||||
bool toXYZD50(SkMatrix44* toXYZD50) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* Contains the coefficients for a common transfer function equation, specified as
|
||||
* a transformation from a curved space to linear.
|
||||
*
|
||||
* LinearVal = C*InputVal + F , for 0.0f <= InputVal < D
|
||||
* LinearVal = (A*InputVal + B)^G + E, for D <= InputVal <= 1.0f
|
||||
*
|
||||
* Function is undefined if InputVal is not in [ 0.0f, 1.0f ].
|
||||
* Resulting LinearVals must be in [ 0.0f, 1.0f ].
|
||||
* Function must be positive and increasing.
|
||||
*/
|
||||
struct SK_API SkColorSpaceTransferFn {
|
||||
float fG;
|
||||
float fA;
|
||||
float fB;
|
||||
float fC;
|
||||
float fD;
|
||||
float fE;
|
||||
float fF;
|
||||
|
||||
/**
|
||||
* Produces a new parametric transfer function equation that is the mathematical inverse of
|
||||
* this one.
|
||||
*/
|
||||
SkColorSpaceTransferFn invert() const;
|
||||
};
|
||||
|
||||
class SK_API SkColorSpace : public SkRefCnt {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create the sRGB color space.
|
||||
* Common, named profiles that we can recognize.
|
||||
*/
|
||||
static sk_sp<SkColorSpace> MakeSRGB();
|
||||
enum Named : uint8_t {
|
||||
/**
|
||||
* By far the most common color space.
|
||||
* This is the default space for images, unmarked content, and monitors.
|
||||
*/
|
||||
kSRGB_Named,
|
||||
|
||||
/**
|
||||
* Colorspace with the sRGB primaries, but a linear (1.0) gamma. Commonly used for
|
||||
* half-float surfaces, and high precision individual colors (gradient stops, etc...)
|
||||
*/
|
||||
static sk_sp<SkColorSpace> MakeSRGBLinear();
|
||||
/**
|
||||
* Very common wide gamut color space.
|
||||
* Often used by images and monitors.
|
||||
*/
|
||||
kAdobeRGB_Named,
|
||||
|
||||
/**
|
||||
* Colorspace with the sRGB primaries, but a linear (1.0) gamma. Commonly used for
|
||||
* half-float surfaces, and high precision individual colors (gradient stops, etc...)
|
||||
*/
|
||||
kSRGBLinear_Named,
|
||||
};
|
||||
|
||||
enum RenderTargetGamma : uint8_t {
|
||||
kLinear_RenderTargetGamma,
|
||||
|
@ -80,34 +49,28 @@ public:
|
|||
kSRGB_RenderTargetGamma,
|
||||
};
|
||||
|
||||
enum Gamut {
|
||||
kSRGB_Gamut,
|
||||
kAdobeRGB_Gamut,
|
||||
kDCIP3_D65_Gamut,
|
||||
kRec2020_Gamut,
|
||||
};
|
||||
/**
|
||||
* Create an SkColorSpace from a transfer function and a color gamut transform to D50 XYZ.
|
||||
*/
|
||||
static sk_sp<SkColorSpace> NewRGB(RenderTargetGamma gamma, const SkMatrix44& toXYZD50);
|
||||
|
||||
/**
|
||||
* Create an SkColorSpace from a transfer function and a color gamut.
|
||||
*
|
||||
* Transfer function can be specified as an enum or as the coefficients to an equation.
|
||||
* Gamut can be specified as an enum or as the matrix transformation to XYZ D50.
|
||||
* Create a common, named SkColorSpace.
|
||||
*/
|
||||
static sk_sp<SkColorSpace> MakeRGB(RenderTargetGamma gamma, Gamut gamut);
|
||||
static sk_sp<SkColorSpace> MakeRGB(RenderTargetGamma gamma, const SkMatrix44& toXYZD50);
|
||||
static sk_sp<SkColorSpace> MakeRGB(const SkColorSpaceTransferFn& coeffs, Gamut gamut);
|
||||
static sk_sp<SkColorSpace> MakeRGB(const SkColorSpaceTransferFn& coeffs,
|
||||
const SkMatrix44& toXYZD50);
|
||||
static sk_sp<SkColorSpace> NewNamed(Named);
|
||||
|
||||
/**
|
||||
* Create an SkColorSpace from an ICC profile.
|
||||
*/
|
||||
static sk_sp<SkColorSpace> MakeICC(const void*, size_t);
|
||||
static sk_sp<SkColorSpace> NewICC(const void*, size_t);
|
||||
|
||||
/**
|
||||
* Create an SkColorSpace with the same gamut as this color space, but with linear gamma.
|
||||
*/
|
||||
sk_sp<SkColorSpace> makeLinearGamma();
|
||||
|
||||
/**
|
||||
* Returns true if the color space gamma is near enough to be approximated as sRGB.
|
||||
* This includes the canonical sRGB transfer function as well as a 2.2f exponential
|
||||
* transfer function.
|
||||
*/
|
||||
bool gammaCloseToSRGB() const;
|
||||
|
||||
|
@ -116,34 +79,6 @@ public:
|
|||
*/
|
||||
bool gammaIsLinear() const;
|
||||
|
||||
/**
|
||||
* If the transfer function can be represented as coefficients to the standard
|
||||
* equation, returns true and sets |fn| to the proper values.
|
||||
*
|
||||
* If not, returns false.
|
||||
*/
|
||||
bool isNumericalTransferFn(SkColorSpaceTransferFn* fn) const;
|
||||
|
||||
/**
|
||||
* Returns true and sets |toXYZD50| if the color gamut can be described as a matrix.
|
||||
* Returns false otherwise.
|
||||
*/
|
||||
bool toXYZD50(SkMatrix44* toXYZD50) const;
|
||||
|
||||
/**
|
||||
* Returns true if the color space is sRGB.
|
||||
* Returns false otherwise.
|
||||
*
|
||||
* This allows a little bit of tolerance, given that we might see small numerical error
|
||||
* in some cases: converting ICC fixed point to float, converting white point to D50,
|
||||
* rounding decisions on transfer function and matrix.
|
||||
*
|
||||
* This does not consider a 2.2f exponential transfer function to be sRGB. While these
|
||||
* functions are similar (and it is sometimes useful to consider them together), this
|
||||
* function checks for logical equality.
|
||||
*/
|
||||
bool isSRGB() const;
|
||||
|
||||
/**
|
||||
* Returns nullptr on failure. Fails when we fallback to serializing ICC data and
|
||||
* the data is too large to serialize.
|
||||
|
@ -168,17 +103,4 @@ protected:
|
|||
SkColorSpace() {}
|
||||
};
|
||||
|
||||
enum class SkTransferFunctionBehavior {
|
||||
/**
|
||||
* Converts to a linear space before premultiplying, unpremultiplying, or blending.
|
||||
*/
|
||||
kRespect,
|
||||
|
||||
/**
|
||||
* Premultiplies, unpremultiplies, and blends ignoring the transfer function. Pixels are
|
||||
* treated as if they are linear, regardless of their transfer function encoding.
|
||||
*/
|
||||
kIgnore,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Copyright 2016 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkColorSpaceXform_DEFINED
|
||||
#define SkColorSpaceXform_DEFINED
|
||||
|
||||
#include "SkImageInfo.h"
|
||||
|
||||
class SkColorSpace;
|
||||
|
||||
class SK_API SkColorSpaceXform : SkNoncopyable {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create an object to handle color space conversions.
|
||||
*
|
||||
* @param srcSpace The encoded color space.
|
||||
* @param dstSpace The destination color space.
|
||||
*
|
||||
*/
|
||||
static std::unique_ptr<SkColorSpaceXform> New(SkColorSpace* srcSpace, SkColorSpace* dstSpace);
|
||||
|
||||
enum ColorFormat {
|
||||
kRGBA_8888_ColorFormat,
|
||||
kBGRA_8888_ColorFormat,
|
||||
|
||||
// Unsigned, big-endian, 16-bit integer
|
||||
kRGB_U16_BE_ColorFormat, // Src only
|
||||
kRGBA_U16_BE_ColorFormat, // Src only
|
||||
|
||||
kRGBA_F16_ColorFormat,
|
||||
kRGBA_F32_ColorFormat,
|
||||
|
||||
kBGR_565_ColorFormat, // Dst only, kOpaque only
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply the color conversion to a |src| buffer, storing the output in the |dst| buffer.
|
||||
*
|
||||
* F16 and F32 are only supported when the color space is linear. This function will return
|
||||
* false in unsupported cases.
|
||||
*
|
||||
* @param dst Stored in the format described by |dstColorFormat|
|
||||
* @param src Stored in the format described by |srcColorFormat|
|
||||
* @param len Number of pixels in the buffers
|
||||
* @param dstColorFormat Describes color format of |dst|
|
||||
* @param srcColorFormat Describes color format of |src|
|
||||
* @param alphaType Describes alpha properties of the |dst| (and |src|)
|
||||
* kUnpremul preserves input alpha values
|
||||
* kPremul performs a premultiplication and also preserves alpha values
|
||||
* kOpaque optimization hint, |dst| alphas set to 1
|
||||
*
|
||||
*/
|
||||
bool apply(ColorFormat dstFormat, void* dst, ColorFormat srcFormat, const void* src, int count,
|
||||
SkAlphaType alphaType) const;
|
||||
|
||||
virtual ~SkColorSpaceXform() {}
|
||||
|
||||
protected:
|
||||
SkColorSpaceXform() {}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* Copyright 2017 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkColorSpaceXformCanvas_DEFINED
|
||||
#define SkColorSpaceXformCanvas_DEFINED
|
||||
|
||||
#include <SkCanvas.h>
|
||||
#include <SkColorSpace.h>
|
||||
#include <memory>
|
||||
|
||||
// Proxy SkCanvas calls to unowned target, transforming colors into targetCS as it goes.
|
||||
// May return nullptr if |targetCS| is unsupported.
|
||||
std::unique_ptr<SkCanvas> SK_API SkCreateColorSpaceXformCanvas(SkCanvas* target,
|
||||
sk_sp<SkColorSpace> targetCS);
|
||||
|
||||
#endif //SkColorSpaceXformCanvas_DEFINED
|
|
@ -24,12 +24,10 @@
|
|||
*/
|
||||
class SK_API SkColorTable : public SkRefCnt {
|
||||
public:
|
||||
static sk_sp<SkColorTable> Make(const SkPMColor colors[], int count);
|
||||
|
||||
/** Copy up to 256 colors into a new SkColorTable.
|
||||
*/
|
||||
SkColorTable(const SkPMColor colors[], int count);
|
||||
~SkColorTable() override;
|
||||
virtual ~SkColorTable();
|
||||
|
||||
/** Returns the number of colors in the table.
|
||||
*/
|
||||
|
@ -54,7 +52,7 @@ public:
|
|||
void writeToBuffer(SkWriteBuffer&) const;
|
||||
|
||||
// may return null
|
||||
static sk_sp<SkColorTable> Create(SkReadBuffer&);
|
||||
static SkColorTable* Create(SkReadBuffer&);
|
||||
|
||||
private:
|
||||
enum AllocatedWithMalloc {
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Copyright 2017 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SkCrossContextImageData_DEFINED
|
||||
#define SkCrossContextImageData_DEFINED
|
||||
|
||||
#include "SkImage.h"
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrExternalTextureData.h"
|
||||
#endif
|
||||
|
||||
class SK_API SkCrossContextImageData : SkNoncopyable {
|
||||
public:
|
||||
/**
|
||||
* Decodes and uploads the encoded data to a texture using the supplied GrContext, then
|
||||
* returns an instance of SkCrossContextImageData that can be used to transport that texture
|
||||
* to a different GrContext, across thread boundaries. The GrContext used here, and the one
|
||||
* used to reconstruct the texture-backed image later must be in the same GL share group,
|
||||
* or otherwise be able to share resources. After calling this, you *must* construct exactly
|
||||
* one SkImage from the returned value, using SkImage::MakeFromCrossContextImageData.
|
||||
*
|
||||
* The texture will be decoded and uploaded to be suitable for use with surfaces that have the
|
||||
* supplied destination color space. The color space of the texture itself will be determined
|
||||
* from the encoded data.
|
||||
*/
|
||||
static std::unique_ptr<SkCrossContextImageData> MakeFromEncoded(
|
||||
GrContext*, sk_sp<SkData>, SkColorSpace* dstColorSpace);
|
||||
|
||||
private:
|
||||
SkCrossContextImageData(sk_sp<SkImage> image) : fImage(std::move(image)) {
|
||||
SkASSERT(!fImage->isTextureBacked());
|
||||
}
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
SkCrossContextImageData(const GrBackendTextureDesc& desc,
|
||||
std::unique_ptr<GrExternalTextureData> textureData,
|
||||
SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace)
|
||||
: fAlphaType(alphaType)
|
||||
, fColorSpace(std::move(colorSpace))
|
||||
, fDesc(desc)
|
||||
, fTextureData(std::move(textureData)) {
|
||||
// Point our texture desc at our copy of the backend information
|
||||
fDesc.fTextureHandle = fTextureData->getBackendObject();
|
||||
}
|
||||
#endif
|
||||
|
||||
// For non-GPU backed images
|
||||
sk_sp<SkImage> fImage;
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
// GPU-backed images store some generic information (needed to reconstruct the SkImage),
|
||||
// and some backend-specific info (to reconstruct the texture).
|
||||
SkAlphaType fAlphaType;
|
||||
sk_sp<SkColorSpace> fColorSpace;
|
||||
GrBackendTextureDesc fDesc;
|
||||
std::unique_ptr<GrExternalTextureData> fTextureData;
|
||||
#endif
|
||||
|
||||
friend class SkImage;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -168,8 +168,14 @@ private:
|
|||
explicit SkData(size_t size); // inplace new/delete
|
||||
~SkData();
|
||||
|
||||
// Ensure the unsized delete is called.
|
||||
void operator delete(void* p) { ::operator delete(p); }
|
||||
|
||||
// Objects of this type are sometimes created in a custom fashion using sk_malloc_throw and
|
||||
// therefore must be sk_freed. We overload new to also call sk_malloc_throw so that memory
|
||||
// can be unconditionally released using sk_free in an overloaded delete. Overloading regular
|
||||
// new means we must also overload placement new.
|
||||
void* operator new(size_t size) { return sk_malloc_throw(size); }
|
||||
void* operator new(size_t, void* p) { return p; }
|
||||
void operator delete(void* p) { sk_free(p); }
|
||||
|
||||
// Called the first time someone calls NewEmpty to initialize the singleton.
|
||||
friend SkData* sk_new_empty_data();
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#define SkDataTable_DEFINED
|
||||
|
||||
#include "../private/SkTDArray.h"
|
||||
#include "SkChunkAlloc.h"
|
||||
#include "SkData.h"
|
||||
#include "SkString.h"
|
||||
|
||||
|
@ -116,4 +117,58 @@ private:
|
|||
typedef SkRefCnt INHERITED;
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper class that allows for incrementally building up the data needed to
|
||||
* create a SkDataTable.
|
||||
*/
|
||||
class SK_API SkDataTableBuilder : SkNoncopyable {
|
||||
public:
|
||||
SkDataTableBuilder(size_t minChunkSize);
|
||||
~SkDataTableBuilder();
|
||||
|
||||
int count() const { return fDir.count(); }
|
||||
size_t minChunkSize() const { return fMinChunkSize; }
|
||||
|
||||
/**
|
||||
* Forget any previously appended entries, setting count() back to 0.
|
||||
*/
|
||||
void reset(size_t minChunkSize);
|
||||
void reset() {
|
||||
this->reset(fMinChunkSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy size-bytes from data, and append it to the growing SkDataTable.
|
||||
*/
|
||||
void append(const void* data, size_t size);
|
||||
|
||||
/**
|
||||
* Helper version of append() passes strlen() + 1 for the size,
|
||||
* so the trailing-zero will be copied as well.
|
||||
*/
|
||||
void appendStr(const char str[]) {
|
||||
this->append(str, strlen(str) + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper version of append() passes string.size() + 1 for the size,
|
||||
* so the trailing-zero will be copied as well.
|
||||
*/
|
||||
void appendString(const SkString& string) {
|
||||
this->append(string.c_str(), string.size() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an SkDataTable from the accumulated entries that were added by
|
||||
* calls to append(). This call also clears any accumluated entries from
|
||||
* this builder, so its count() will be 0 after this call.
|
||||
*/
|
||||
sk_sp<SkDataTable> detachDataTable();
|
||||
|
||||
private:
|
||||
SkTDArray<SkDataTable::Dir> fDir;
|
||||
SkChunkAlloc* fHeap;
|
||||
size_t fMinChunkSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,18 +14,26 @@
|
|||
#include "SkSurfaceProps.h"
|
||||
|
||||
class SkBitmap;
|
||||
class SkClipStack;
|
||||
class SkDraw;
|
||||
class SkDrawFilter;
|
||||
class SkImageFilterCache;
|
||||
struct SkIRect;
|
||||
class SkMatrix;
|
||||
class SkRasterHandleAllocator;
|
||||
class SkMetaData;
|
||||
class SkRegion;
|
||||
class SkSpecialImage;
|
||||
class GrRenderTarget;
|
||||
|
||||
class SK_API SkBaseDevice : public SkRefCnt {
|
||||
public:
|
||||
SkBaseDevice(const SkImageInfo&, const SkSurfaceProps&);
|
||||
/**
|
||||
* Construct a new device.
|
||||
*/
|
||||
explicit SkBaseDevice(const SkImageInfo&, const SkSurfaceProps&);
|
||||
virtual ~SkBaseDevice();
|
||||
|
||||
SkMetaData& getMetaData();
|
||||
|
||||
/**
|
||||
* Return ImageInfo for this device. If the canvas is not backed by pixels
|
||||
|
@ -69,6 +77,16 @@ public:
|
|||
return this->imageInfo().isOpaque();
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_ACCESSBITMAP
|
||||
/** Return the bitmap associated with this device. Call this each time you need
|
||||
to access the bitmap, as it notifies the subclass to perform any flushing
|
||||
etc. before you examine the pixels.
|
||||
@param changePixels set to true if the caller plans to change the pixels
|
||||
@return the device's bitmap
|
||||
*/
|
||||
const SkBitmap& accessBitmap(bool changePixels);
|
||||
#endif
|
||||
|
||||
bool writePixels(const SkImageInfo&, const void*, size_t rowBytes, int x, int y);
|
||||
|
||||
/**
|
||||
|
@ -94,37 +112,6 @@ public:
|
|||
*/
|
||||
const SkIPoint& getOrigin() const { return fOrigin; }
|
||||
|
||||
virtual void* getRasterHandle() const { return nullptr; }
|
||||
|
||||
void save() { this->onSave(); }
|
||||
void restore(const SkMatrix& ctm) {
|
||||
this->onRestore();
|
||||
this->setGlobalCTM(ctm);
|
||||
}
|
||||
void clipRect(const SkRect& rect, SkClipOp op, bool aa) {
|
||||
this->onClipRect(rect, op, aa);
|
||||
}
|
||||
void clipRRect(const SkRRect& rrect, SkClipOp op, bool aa) {
|
||||
this->onClipRRect(rrect, op, aa);
|
||||
}
|
||||
void clipPath(const SkPath& path, SkClipOp op, bool aa) {
|
||||
this->onClipPath(path, op, aa);
|
||||
}
|
||||
void clipRegion(const SkRegion& region, SkClipOp op) {
|
||||
this->onClipRegion(region, op);
|
||||
}
|
||||
void androidFramework_setDeviceClipRestriction(SkIRect* mutableClipRestriction) {
|
||||
this->onSetDeviceClipRestriction(mutableClipRestriction);
|
||||
}
|
||||
bool clipIsWideOpen() const;
|
||||
|
||||
const SkMatrix& ctm() const { return fCTM; }
|
||||
void setCTM(const SkMatrix& ctm) {
|
||||
fCTM = ctm;
|
||||
}
|
||||
void setGlobalCTM(const SkMatrix& ctm);
|
||||
virtual void validateDevBounds(const SkIRect&) {}
|
||||
|
||||
protected:
|
||||
enum TileUsage {
|
||||
kPossible_TileUsage, //!< the created device may be drawn tiled
|
||||
|
@ -143,44 +130,28 @@ protected:
|
|||
|
||||
virtual bool onShouldDisableLCD(const SkPaint&) const { return false; }
|
||||
|
||||
virtual void onSave() {}
|
||||
virtual void onRestore() {}
|
||||
virtual void onClipRect(const SkRect& rect, SkClipOp, bool aa) {}
|
||||
virtual void onClipRRect(const SkRRect& rrect, SkClipOp, bool aa) {}
|
||||
virtual void onClipPath(const SkPath& path, SkClipOp, bool aa) {}
|
||||
virtual void onClipRegion(const SkRegion& deviceRgn, SkClipOp) {}
|
||||
virtual void onSetDeviceClipRestriction(SkIRect* mutableClipRestriction) {}
|
||||
virtual bool onClipIsAA() const = 0;
|
||||
virtual void onAsRgnClip(SkRegion*) const = 0;
|
||||
enum ClipType {
|
||||
kEmpty_ClipType,
|
||||
kRect_ClipType,
|
||||
kComplex_ClipType
|
||||
};
|
||||
virtual ClipType onGetClipType() const = 0;
|
||||
|
||||
/** These are called inside the per-device-layer loop for each draw call.
|
||||
When these are called, we have already applied any saveLayer operations,
|
||||
and are handling any looping from the paint, and any effects from the
|
||||
DrawFilter.
|
||||
*/
|
||||
virtual void drawPaint(const SkPaint& paint) = 0;
|
||||
virtual void drawPoints(SkCanvas::PointMode mode, size_t count,
|
||||
virtual void drawPaint(const SkDraw&, const SkPaint& paint) = 0;
|
||||
virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
|
||||
const SkPoint[], const SkPaint& paint) = 0;
|
||||
virtual void drawRect(const SkRect& r,
|
||||
virtual void drawRect(const SkDraw&, const SkRect& r,
|
||||
const SkPaint& paint) = 0;
|
||||
virtual void drawRegion(const SkRegion& r,
|
||||
virtual void drawRegion(const SkDraw&, const SkRegion& r,
|
||||
const SkPaint& paint);
|
||||
virtual void drawOval(const SkRect& oval,
|
||||
virtual void drawOval(const SkDraw&, const SkRect& oval,
|
||||
const SkPaint& paint) = 0;
|
||||
/** By the time this is called we know that abs(sweepAngle) is in the range [0, 360). */
|
||||
virtual void drawArc(const SkRect& oval, SkScalar startAngle,
|
||||
virtual void drawArc(const SkDraw&, const SkRect& oval, SkScalar startAngle,
|
||||
SkScalar sweepAngle, bool useCenter, const SkPaint& paint);
|
||||
virtual void drawRRect(const SkRRect& rr,
|
||||
virtual void drawRRect(const SkDraw&, const SkRRect& rr,
|
||||
const SkPaint& paint) = 0;
|
||||
|
||||
// Default impl calls drawPath()
|
||||
virtual void drawDRRect(const SkRRect& outer,
|
||||
virtual void drawDRRect(const SkDraw&, const SkRRect& outer,
|
||||
const SkRRect& inner, const SkPaint&);
|
||||
|
||||
/**
|
||||
|
@ -194,71 +165,75 @@ protected:
|
|||
* affect the geometry/rasterization, then the pre matrix can just be
|
||||
* pre-concated with the current matrix.
|
||||
*/
|
||||
virtual void drawPath(const SkPath& path,
|
||||
virtual void drawPath(const SkDraw&, const SkPath& path,
|
||||
const SkPaint& paint,
|
||||
const SkMatrix* prePathMatrix = NULL,
|
||||
bool pathIsMutable = false) = 0;
|
||||
virtual void drawBitmap(const SkBitmap& bitmap,
|
||||
virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
|
||||
const SkMatrix& matrix, const SkPaint& paint) = 0;
|
||||
virtual void drawSprite(const SkBitmap& bitmap,
|
||||
virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
|
||||
int x, int y, const SkPaint& paint) = 0;
|
||||
|
||||
/**
|
||||
* The default impl. will create a bitmap-shader from the bitmap,
|
||||
* and call drawRect with it.
|
||||
*/
|
||||
virtual void drawBitmapRect(const SkBitmap&,
|
||||
virtual void drawBitmapRect(const SkDraw&, const SkBitmap&,
|
||||
const SkRect* srcOrNull, const SkRect& dst,
|
||||
const SkPaint& paint,
|
||||
SkCanvas::SrcRectConstraint) = 0;
|
||||
virtual void drawBitmapNine(const SkBitmap&, const SkIRect& center,
|
||||
virtual void drawBitmapNine(const SkDraw&, const SkBitmap&, const SkIRect& center,
|
||||
const SkRect& dst, const SkPaint&);
|
||||
virtual void drawBitmapLattice(const SkBitmap&, const SkCanvas::Lattice&,
|
||||
virtual void drawBitmapLattice(const SkDraw&, const SkBitmap&, const SkCanvas::Lattice&,
|
||||
const SkRect& dst, const SkPaint&);
|
||||
|
||||
virtual void drawImage(const SkImage*, SkScalar x, SkScalar y, const SkPaint&);
|
||||
virtual void drawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
|
||||
virtual void drawImage(const SkDraw&, const SkImage*, SkScalar x, SkScalar y, const SkPaint&);
|
||||
virtual void drawImageRect(const SkDraw&, const SkImage*, const SkRect* src, const SkRect& dst,
|
||||
const SkPaint&, SkCanvas::SrcRectConstraint);
|
||||
virtual void drawImageNine(const SkImage*, const SkIRect& center,
|
||||
virtual void drawImageNine(const SkDraw&, const SkImage*, const SkIRect& center,
|
||||
const SkRect& dst, const SkPaint&);
|
||||
virtual void drawImageLattice(const SkImage*, const SkCanvas::Lattice&,
|
||||
virtual void drawImageLattice(const SkDraw&, const SkImage*, const SkCanvas::Lattice&,
|
||||
const SkRect& dst, const SkPaint&);
|
||||
|
||||
/**
|
||||
* Does not handle text decoration.
|
||||
* Decorations (underline and stike-thru) will be handled by SkCanvas.
|
||||
*/
|
||||
virtual void drawText(const void* text, size_t len,
|
||||
virtual void drawText(const SkDraw&, const void* text, size_t len,
|
||||
SkScalar x, SkScalar y, const SkPaint& paint) = 0;
|
||||
virtual void drawPosText(const void* text, size_t len,
|
||||
virtual void drawPosText(const SkDraw&, const void* text, size_t len,
|
||||
const SkScalar pos[], int scalarsPerPos,
|
||||
const SkPoint& offset, const SkPaint& paint) = 0;
|
||||
virtual void drawVertices(const SkVertices*, SkBlendMode, const SkPaint&) = 0;
|
||||
virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount,
|
||||
const SkPoint verts[], const SkPoint texs[],
|
||||
const SkColor colors[], SkXfermode* xmode,
|
||||
const uint16_t indices[], int indexCount,
|
||||
const SkPaint& paint) = 0;
|
||||
// default implementation unrolls the blob runs.
|
||||
virtual void drawTextBlob(const SkTextBlob*, SkScalar x, SkScalar y,
|
||||
virtual void drawTextBlob(const SkDraw&, const SkTextBlob*, SkScalar x, SkScalar y,
|
||||
const SkPaint& paint, SkDrawFilter* drawFilter);
|
||||
// default implementation calls drawVertices
|
||||
virtual void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
|
||||
const SkPoint texCoords[4], SkBlendMode, const SkPaint& paint);
|
||||
virtual void drawPatch(const SkDraw&, const SkPoint cubics[12], const SkColor colors[4],
|
||||
const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
|
||||
|
||||
// default implementation calls drawPath
|
||||
virtual void drawAtlas(const SkImage* atlas, const SkRSXform[], const SkRect[],
|
||||
const SkColor[], int count, SkBlendMode, const SkPaint&);
|
||||
virtual void drawAtlas(const SkDraw&, const SkImage* atlas, const SkRSXform[], const SkRect[],
|
||||
const SkColor[], int count, SkXfermode::Mode, const SkPaint&);
|
||||
|
||||
virtual void drawAnnotation(const SkRect&, const char[], SkData*) {}
|
||||
virtual void drawAnnotation(const SkDraw&, const SkRect&, const char[], SkData*) {}
|
||||
|
||||
/** The SkDevice passed will be an SkDevice which was returned by a call to
|
||||
onCreateDevice on this device with kNeverTile_TileExpectation.
|
||||
*/
|
||||
virtual void drawDevice(SkBaseDevice*, int x, int y,
|
||||
virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
|
||||
const SkPaint&) = 0;
|
||||
|
||||
virtual void drawTextOnPath(const void* text, size_t len, const SkPath&,
|
||||
virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, const SkPath&,
|
||||
const SkMatrix*, const SkPaint&);
|
||||
virtual void drawTextRSXform(const void* text, size_t len, const SkRSXform[],
|
||||
virtual void drawTextRSXform(const SkDraw&, const void* text, size_t len, const SkRSXform[],
|
||||
const SkPaint&);
|
||||
|
||||
virtual void drawSpecial(SkSpecialImage*, int x, int y, const SkPaint&);
|
||||
virtual void drawSpecial(const SkDraw&, SkSpecialImage*, int x, int y, const SkPaint&);
|
||||
virtual sk_sp<SkSpecialImage> makeSpecial(const SkBitmap&);
|
||||
virtual sk_sp<SkSpecialImage> makeSpecial(const SkImage*);
|
||||
virtual sk_sp<SkSpecialImage> snapSpecial();
|
||||
|
@ -267,8 +242,20 @@ protected:
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_ACCESSBITMAP
|
||||
/** Update as needed the pixel value in the bitmap, so that the caller can
|
||||
access the pixels directly.
|
||||
@return The device contents as a bitmap
|
||||
*/
|
||||
virtual const SkBitmap& onAccessBitmap() {
|
||||
SkASSERT(0);
|
||||
return fLegacyBitmap;
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual GrContext* context() const { return nullptr; }
|
||||
|
||||
protected:
|
||||
virtual sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps&);
|
||||
virtual bool onPeekPixels(SkPixmap*) { return false; }
|
||||
|
||||
|
@ -306,18 +293,15 @@ protected:
|
|||
CreateInfo(const SkImageInfo& info,
|
||||
TileUsage tileUsage,
|
||||
SkPixelGeometry geo,
|
||||
bool preserveLCDText,
|
||||
SkRasterHandleAllocator* allocator)
|
||||
bool preserveLCDText)
|
||||
: fInfo(info)
|
||||
, fTileUsage(tileUsage)
|
||||
, fPixelGeometry(AdjustGeometry(info, tileUsage, geo, preserveLCDText))
|
||||
, fAllocator(allocator)
|
||||
{}
|
||||
|
||||
const SkImageInfo fInfo;
|
||||
const TileUsage fTileUsage;
|
||||
const SkPixelGeometry fPixelGeometry;
|
||||
SkRasterHandleAllocator* fAllocator = nullptr;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -359,10 +343,10 @@ private:
|
|||
/**
|
||||
* Don't call this!
|
||||
*/
|
||||
virtual GrRenderTargetContext* accessRenderTargetContext() { return nullptr; }
|
||||
virtual GrDrawContext* accessDrawContext() { return nullptr; }
|
||||
|
||||
// just called by SkCanvas when built as a layer
|
||||
void setOrigin(const SkMatrix& ctm, int x, int y);
|
||||
void setOrigin(int x, int y) { fOrigin.set(x, y); }
|
||||
|
||||
/** Causes any deferred drawing to the device to be completed.
|
||||
*/
|
||||
|
@ -370,35 +354,21 @@ private:
|
|||
|
||||
virtual SkImageFilterCache* getImageFilterCache() { return NULL; }
|
||||
|
||||
friend class SkNoPixelsDevice;
|
||||
friend class SkBitmapDevice;
|
||||
void privateResize(int w, int h) {
|
||||
*const_cast<SkImageInfo*>(&fInfo) = fInfo.makeWH(w, h);
|
||||
}
|
||||
|
||||
SkIPoint fOrigin;
|
||||
SkIPoint fOrigin;
|
||||
SkMetaData* fMetaData;
|
||||
const SkImageInfo fInfo;
|
||||
const SkSurfaceProps fSurfaceProps;
|
||||
SkMatrix fCTM;
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_ACCESSBITMAP
|
||||
SkBitmap fLegacyBitmap;
|
||||
#endif
|
||||
|
||||
typedef SkRefCnt INHERITED;
|
||||
};
|
||||
|
||||
class SkAutoDeviceCTMRestore : SkNoncopyable {
|
||||
public:
|
||||
SkAutoDeviceCTMRestore(SkBaseDevice* device, const SkMatrix& ctm)
|
||||
: fDevice(device)
|
||||
, fPrevCTM(device->ctm())
|
||||
{
|
||||
fDevice->setCTM(ctm);
|
||||
}
|
||||
~SkAutoDeviceCTMRestore() {
|
||||
fDevice->setCTM(fPrevCTM);
|
||||
}
|
||||
|
||||
private:
|
||||
SkBaseDevice* fDevice;
|
||||
const SkMatrix fPrevCTM;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -19,10 +19,6 @@
|
|||
class SkCanvas;
|
||||
class SkWStream;
|
||||
|
||||
#ifdef SK_BUILD_FOR_WIN
|
||||
struct IXpsOMObjectFactory;
|
||||
#endif
|
||||
|
||||
/** SK_ScalarDefaultDPI is 72 DPI.
|
||||
*/
|
||||
#define SK_ScalarDefaultRasterDPI 72.0f
|
||||
|
@ -50,7 +46,7 @@ public:
|
|||
*/
|
||||
struct PDFMetadata {
|
||||
/**
|
||||
* The document's title.
|
||||
* The document’s title.
|
||||
*/
|
||||
SkString fTitle;
|
||||
/**
|
||||
|
@ -145,34 +141,19 @@ public:
|
|||
static sk_sp<SkDocument> MakePDF(const char outputFilePath[],
|
||||
SkScalar dpi = SK_ScalarDefaultRasterDPI);
|
||||
|
||||
#ifdef SK_BUILD_FOR_WIN
|
||||
/**
|
||||
* Create a XPS-backed document, writing the results into the stream.
|
||||
*
|
||||
* @param stream A XPS document will be written to this stream. The
|
||||
* document may write to the stream at anytime during its
|
||||
* lifetime, until either close() or abort() are called or
|
||||
* the document is deleted.
|
||||
* @param xpsFactory A pointer to a COM XPS factory. Must be non-null.
|
||||
* The document will take a ref to the factory. See
|
||||
* dm/DMSrcSink.cpp for an example.
|
||||
* @param dpi The DPI (pixels-per-inch) at which features without
|
||||
* native XPS support will be rasterized (e.g. draw image
|
||||
* with perspective, draw text with perspective, ...) A
|
||||
* larger DPI would create a XPS that reflects the
|
||||
* original intent with better fidelity, but it can make
|
||||
* for larger XPS files too, which would use more memory
|
||||
* while rendering, and it would be slower to be processed
|
||||
* or sent online or to printer.
|
||||
*
|
||||
* @returns nullptr if XPS is not supported.
|
||||
* Returns NULL if XPS is not supported.
|
||||
*/
|
||||
static sk_sp<SkDocument> MakeXPS(SkWStream* stream,
|
||||
IXpsOMObjectFactory* xpsFactory,
|
||||
SkScalar dpi = SK_ScalarDefaultRasterDPI);
|
||||
#endif
|
||||
// DEPRECATED; TODO(halcanary): remove this function after Chromium switches to new API.
|
||||
static sk_sp<SkDocument> MakeXPS(SkWStream*) { return nullptr; }
|
||||
|
||||
/**
|
||||
* Create a XPS-backed document, writing the results into a file.
|
||||
* Returns NULL if XPS is not supported.
|
||||
*/
|
||||
static sk_sp<SkDocument> MakeXPS(const char path[],
|
||||
SkScalar dpi = SK_ScalarDefaultRasterDPI);
|
||||
|
||||
/**
|
||||
* Begin a new page for the document, returning the canvas that will draw
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "SkMask.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkStrokeRec.h"
|
||||
#include "SkVertices.h"
|
||||
|
||||
class SkBitmap;
|
||||
class SkClipStack;
|
||||
|
@ -34,7 +33,7 @@ public:
|
|||
|
||||
void drawPaint(const SkPaint&) const;
|
||||
void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[],
|
||||
const SkPaint&, SkBaseDevice*) const;
|
||||
const SkPaint&, bool forceUseDevice = false) const;
|
||||
void drawRect(const SkRect& prePaintRect, const SkPaint&, const SkMatrix* paintMatrix,
|
||||
const SkRect* postPaintRect) const;
|
||||
void drawRect(const SkRect& rect, const SkPaint& paint) const {
|
||||
|
@ -65,13 +64,13 @@ public:
|
|||
const SkPaint&) const;
|
||||
void drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const;
|
||||
void drawText(const char text[], size_t byteLength, SkScalar x,
|
||||
SkScalar y, const SkPaint& paint, const SkSurfaceProps*) const;
|
||||
SkScalar y, const SkPaint& paint) const;
|
||||
void drawPosText(const char text[], size_t byteLength,
|
||||
const SkScalar pos[], int scalarsPerPosition,
|
||||
const SkPoint& offset, const SkPaint&, const SkSurfaceProps*) const;
|
||||
void drawVertices(SkVertices::VertexMode mode, int count,
|
||||
const SkPoint& offset, const SkPaint& paint) const;
|
||||
void drawVertices(SkCanvas::VertexMode mode, int count,
|
||||
const SkPoint vertices[], const SkPoint textures[],
|
||||
const SkColor colors[], SkBlendMode bmode,
|
||||
const SkColor colors[], SkXfermode* xmode,
|
||||
const uint16_t indices[], int ptCount,
|
||||
const SkPaint& paint) const;
|
||||
|
||||
|
@ -115,11 +114,11 @@ public:
|
|||
SkPoint* strokeSize);
|
||||
|
||||
static bool ShouldDrawTextAsPaths(const SkPaint&, const SkMatrix&);
|
||||
void drawText_asPaths(const char text[], size_t byteLength, SkScalar x, SkScalar y,
|
||||
const SkPaint&) const;
|
||||
void drawPosText_asPaths(const char text[], size_t byteLength, const SkScalar pos[],
|
||||
int scalarsPerPosition, const SkPoint& offset,
|
||||
const SkPaint&, const SkSurfaceProps*) const;
|
||||
void drawText_asPaths(const char text[], size_t byteLength,
|
||||
SkScalar x, SkScalar y, const SkPaint&) const;
|
||||
void drawPosText_asPaths(const char text[], size_t byteLength,
|
||||
const SkScalar pos[], int scalarsPerPosition,
|
||||
const SkPoint& offset, const SkPaint&) const;
|
||||
static SkScalar ComputeResScaleForStroking(const SkMatrix& );
|
||||
private:
|
||||
void drawDevMask(const SkMask& mask, const SkPaint&) const;
|
||||
|
@ -151,6 +150,9 @@ public:
|
|||
const SkMatrix* fMatrix; // required
|
||||
const SkRasterClip* fRC; // required
|
||||
|
||||
const SkClipStack* fClipStack; // optional, may be null
|
||||
SkBaseDevice* fDevice; // optional, may be null
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
void validate() const;
|
||||
#else
|
|
@ -15,12 +15,10 @@
|
|||
#include "SkPoint.h"
|
||||
#include "SkColor.h"
|
||||
|
||||
class SkArenaAlloc;
|
||||
class SkCanvas;
|
||||
class SkColorSpaceXformer;
|
||||
class SkPaint;
|
||||
class SkCanvas;
|
||||
class SkPaint;
|
||||
struct SkRect;
|
||||
class SkString;
|
||||
class SkString;
|
||||
|
||||
/** \class SkDrawLooper
|
||||
Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are,
|
||||
|
@ -63,8 +61,19 @@ public:
|
|||
/**
|
||||
* Called right before something is being drawn. Returns a Context
|
||||
* whose next() method should be called until it returns false.
|
||||
* The caller has to ensure that the storage pointer provides enough
|
||||
* memory for the Context. The required size can be queried by calling
|
||||
* contextSize(). It is also the caller's responsibility to destroy the
|
||||
* object after use.
|
||||
*/
|
||||
virtual Context* makeContext(SkCanvas*, SkArenaAlloc*) const = 0;
|
||||
virtual Context* createContext(SkCanvas*, void* storage) const = 0;
|
||||
|
||||
/**
|
||||
* Returns the number of bytes needed to store subclasses of Context (belonging to the
|
||||
* corresponding SkDrawLooper subclass).
|
||||
*/
|
||||
virtual size_t contextSize() const = 0;
|
||||
|
||||
|
||||
/**
|
||||
* The fast bounds functions are used to enable the paint to be culled early
|
||||
|
@ -101,16 +110,9 @@ public:
|
|||
SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper)
|
||||
|
||||
protected:
|
||||
sk_sp<SkDrawLooper> makeColorSpace(SkColorSpaceXformer* xformer) const {
|
||||
return this->onMakeColorSpace(xformer);
|
||||
}
|
||||
virtual sk_sp<SkDrawLooper> onMakeColorSpace(SkColorSpaceXformer*) const = 0;
|
||||
|
||||
SkDrawLooper() {}
|
||||
|
||||
private:
|
||||
friend class SkColorSpaceXformer;
|
||||
|
||||
typedef SkFlattenable INHERITED;
|
||||
};
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#define SkDrawable_DEFINED
|
||||
|
||||
#include "SkFlattenable.h"
|
||||
#include "SkScalar.h"
|
||||
|
||||
class SkCanvas;
|
||||
class SkMatrix;
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkEncodedImageFormat_DEFINED
|
||||
#define SkEncodedImageFormat_DEFINED
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Enum describing format of encoded data.
|
||||
*/
|
||||
enum class SkEncodedImageFormat {
|
||||
#ifdef GOOGLE3
|
||||
kUnknown,
|
||||
#endif
|
||||
kBMP,
|
||||
kGIF,
|
||||
kICO,
|
||||
kJPEG,
|
||||
kPNG,
|
||||
kWBMP,
|
||||
kWEBP,
|
||||
kPKM,
|
||||
kKTX,
|
||||
kASTC,
|
||||
kDNG,
|
||||
};
|
||||
|
||||
#endif // SkEncodedImageFormat_DEFINED
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright 2013 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkError_DEFINED
|
||||
#define SkError_DEFINED
|
||||
|
||||
|
||||
/** \file SkError.h
|
||||
*/
|
||||
|
||||
enum SkError {
|
||||
/** All is well
|
||||
*/
|
||||
kNoError_SkError=0,
|
||||
|
||||
/** User argument passed to Skia function was invalid: NULL when that’s
|
||||
* not allowed, out of numeric range, bad enum, or violating some
|
||||
* other general precondition.
|
||||
*/
|
||||
kInvalidArgument_SkError,
|
||||
|
||||
/** User tried to perform some operation in a state when the operation
|
||||
* was not legal, or the operands make no sense (e.g., asking for
|
||||
* pixels from an SkPictureCanvas). Other examples might be
|
||||
* inset()’ing a rectangle to make it degenerate (negative width/height).
|
||||
*/
|
||||
kInvalidOperation_SkError,
|
||||
|
||||
/** Probably not needed right now, but in the future we could have opaque
|
||||
* handles for SkPictures floating around, and it would be a good idea
|
||||
* to anticipate this kind of issue.
|
||||
*/
|
||||
kInvalidHandle_SkError,
|
||||
|
||||
/** This is probably not possible because paint surely has defaults for
|
||||
* everything, but perhaps a paint can get into a bad state somehow.
|
||||
*/
|
||||
kInvalidPaint_SkError,
|
||||
|
||||
/** Skia was unable to allocate memory to perform some task.
|
||||
*/
|
||||
kOutOfMemory_SkError,
|
||||
|
||||
/** Skia failed while trying to consume some external resource.
|
||||
*/
|
||||
kParseError_SkError,
|
||||
|
||||
/** Something went wrong internally; could be resource exhaustion but
|
||||
* will often be a bug.
|
||||
*/
|
||||
kInternalError_SkError
|
||||
};
|
||||
|
||||
/** Return the current per-thread error code. Error codes are "sticky"; they
|
||||
* are not not reset by subsequent successful operations.
|
||||
*/
|
||||
SkError SkGetLastError();
|
||||
|
||||
/** Clear the current per-thread error code back to kNoError_SkError.
|
||||
*/
|
||||
void SkClearLastError();
|
||||
|
||||
/** Type for callback functions to be invoked whenever an error is registered.
|
||||
* Callback functions take the error code being set, as well as a context
|
||||
* argument that is provided when the callback is registered.
|
||||
*/
|
||||
typedef void (*SkErrorCallbackFunction)(SkError, void *);
|
||||
|
||||
/** Set the current per-thread error callback.
|
||||
*
|
||||
* @param cb The callback function to be invoked. Passing NULL
|
||||
* for cb will revert to the default error callback which
|
||||
* does nothing on release builds, but on debug builds will
|
||||
* print an informative error message to the screen.
|
||||
* @param context An arbitrary pointer that will be passed to
|
||||
* the provided callback function.
|
||||
*/
|
||||
void SkSetErrorCallback(SkErrorCallbackFunction cb, void *context);
|
||||
|
||||
/** Get a human-readable description of the last (per-thread) error that
|
||||
* occurred. The returned error message will include not only a human
|
||||
* readable version of the error code, but also information about the
|
||||
* conditions that led to the error itself.
|
||||
*/
|
||||
const char *SkGetLastErrorString();
|
||||
|
||||
#endif /* SkError_DEFINED */
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright 2017 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkExecutor_DEFINED
|
||||
#define SkExecutor_DEFINED
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
class SkExecutor {
|
||||
public:
|
||||
virtual ~SkExecutor();
|
||||
|
||||
// Create a thread pool SkExecutor with a fixed thread count, by default the number of cores.
|
||||
static std::unique_ptr<SkExecutor> MakeThreadPool(int threads = 0);
|
||||
|
||||
// There is always a default SkExecutor available by calling SkExecutor::GetDefault().
|
||||
static SkExecutor& GetDefault();
|
||||
static void SetDefault(SkExecutor*); // Does not take ownership. Not thread safe.
|
||||
|
||||
// Add work to execute.
|
||||
virtual void add(std::function<void(void)>) = 0;
|
||||
|
||||
// If it makes sense for this executor, use this thread to execute work for a little while.
|
||||
virtual void borrow() {}
|
||||
};
|
||||
|
||||
#endif//SkExecutor_DEFINED
|
|
@ -11,12 +11,9 @@
|
|||
#include "SkFlattenable.h"
|
||||
|
||||
class SkData;
|
||||
class SkImageFilter;
|
||||
|
||||
SK_API SkData* SkValidatingSerializeFlattenable(SkFlattenable*);
|
||||
SK_API SkFlattenable* SkValidatingDeserializeFlattenable(const void* data, size_t size,
|
||||
SkFlattenable::Type type);
|
||||
|
||||
SK_API sk_sp<SkImageFilter> SkValidatingDeserializeImageFilter(const void* data, size_t size);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* Copyright 2017 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkFontAgruments_DEFINED
|
||||
#define SkFontAgruments_DEFINED
|
||||
|
||||
#include "SkScalar.h"
|
||||
#include "SkTypes.h"
|
||||
|
||||
/** Represents a set of actual arguments for a font. */
|
||||
struct SkFontArguments {
|
||||
struct VariationPosition {
|
||||
struct Coordinate {
|
||||
SkFourByteTag axis;
|
||||
SkScalar value;
|
||||
};
|
||||
const Coordinate* coordinates;
|
||||
int coordinateCount;
|
||||
};
|
||||
// deprecated, use VariationCoordinate instead
|
||||
struct Axis {
|
||||
SkFourByteTag fTag;
|
||||
SkScalar fStyleValue;
|
||||
};
|
||||
|
||||
SkFontArguments() : fCollectionIndex(0), fVariationDesignPosition{nullptr, 0} {}
|
||||
|
||||
/** Specify the index of the desired font.
|
||||
*
|
||||
* Font formats like ttc, dfont, cff, cid, pfr, t42, t1, and fon may actually be indexed
|
||||
* collections of fonts.
|
||||
*/
|
||||
SkFontArguments& setCollectionIndex(int collectionIndex) {
|
||||
fCollectionIndex = collectionIndex;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// deprecated, use setVariationDesignPosition instead.
|
||||
SkFontArguments& setAxes(const Axis* axes, int axisCount) {
|
||||
fVariationDesignPosition.coordinates =
|
||||
reinterpret_cast<const VariationPosition::Coordinate*>(axes);
|
||||
fVariationDesignPosition.coordinateCount = axisCount;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Specify a position in the variation design space.
|
||||
*
|
||||
* Any axis not specified will use the default value.
|
||||
* Any specified axis not actually present in the font will be ignored.
|
||||
*
|
||||
* @param position not copied. The value must remain valid for life of SkFontArguments.
|
||||
*/
|
||||
SkFontArguments& setVariationDesignPosition(VariationPosition position) {
|
||||
fVariationDesignPosition.coordinates = position.coordinates;
|
||||
fVariationDesignPosition.coordinateCount = position.coordinateCount;
|
||||
return *this;
|
||||
}
|
||||
|
||||
int getCollectionIndex() const {
|
||||
return fCollectionIndex;
|
||||
}
|
||||
// deprecated, use getVariationDesignPosition instead.
|
||||
const Axis* getAxes(int* axisCount) const {
|
||||
*axisCount = fVariationDesignPosition.coordinateCount;
|
||||
return reinterpret_cast<const Axis*>(fVariationDesignPosition.coordinates);
|
||||
}
|
||||
VariationPosition getVariationDesignPosition() const {
|
||||
return fVariationDesignPosition;
|
||||
}
|
||||
private:
|
||||
int fCollectionIndex;
|
||||
VariationPosition fVariationDesignPosition;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -8,7 +8,7 @@
|
|||
#ifndef SkGraphics_DEFINED
|
||||
#define SkGraphics_DEFINED
|
||||
|
||||
#include "SkRefCnt.h"
|
||||
#include "SkTypes.h"
|
||||
|
||||
class SkData;
|
||||
class SkImageGenerator;
|
||||
|
@ -157,8 +157,7 @@ public:
|
|||
*/
|
||||
static void SetTLSFontCacheLimit(size_t bytes);
|
||||
|
||||
typedef std::unique_ptr<SkImageGenerator>
|
||||
(*ImageGeneratorFromEncodedDataFactory)(sk_sp<SkData>);
|
||||
typedef SkImageGenerator* (*ImageGeneratorFromEncodedFactory)(SkData*);
|
||||
|
||||
/**
|
||||
* To instantiate images from encoded data, first looks at this runtime function-ptr. If it
|
||||
|
@ -167,8 +166,8 @@ public:
|
|||
*
|
||||
* Returns the previous factory (which could be NULL).
|
||||
*/
|
||||
static ImageGeneratorFromEncodedDataFactory
|
||||
SetImageGeneratorFromEncodedDataFactory(ImageGeneratorFromEncodedDataFactory);
|
||||
static ImageGeneratorFromEncodedFactory
|
||||
SetImageGeneratorFromEncodedFactory(ImageGeneratorFromEncodedFactory);
|
||||
};
|
||||
|
||||
class SkAutoGraphics {
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
/*
|
||||
* Copyright 2016 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkICC_DEFINED
|
||||
#define SkICC_DEFINED
|
||||
|
||||
#include "SkData.h"
|
||||
#include "SkRefCnt.h"
|
||||
|
||||
struct SkColorSpaceTransferFn;
|
||||
class SkColorSpace;
|
||||
class SkData;
|
||||
class SkMatrix44;
|
||||
|
||||
class SK_API SkICC : public SkRefCnt {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Parse an ICC profile.
|
||||
*
|
||||
* Returns nullptr if the data is not a valid ICC profile or if the profile
|
||||
* input space is not RGB.
|
||||
*/
|
||||
static sk_sp<SkICC> Make(const void*, size_t);
|
||||
|
||||
/**
|
||||
* If the gamut can be represented as transformation into XYZ D50, returns
|
||||
* true and sets the proper values in |toXYZD50|.
|
||||
*
|
||||
* If not, returns false. This indicates that the ICC data is too complex
|
||||
* to isolate a simple gamut transformation.
|
||||
*/
|
||||
bool toXYZD50(SkMatrix44* toXYZD50) const;
|
||||
|
||||
/**
|
||||
* If the transfer function can be represented as coefficients to the standard
|
||||
* equation, returns true and sets |fn| to the proper values.
|
||||
*
|
||||
* If not, returns false. This indicates one of the following:
|
||||
* (1) The R, G, and B transfer functions are not the same.
|
||||
* (2) The transfer function is represented as a table that we have not managed
|
||||
* to match to a standard curve.
|
||||
* (3) The ICC data is too complex to isolate a single transfer function.
|
||||
*/
|
||||
bool isNumericalTransferFn(SkColorSpaceTransferFn* fn) const;
|
||||
|
||||
/**
|
||||
* Please do not call this unless isNumericalTransferFn() has been called and it
|
||||
* fails. SkColorSpaceTransferFn is the preferred representation.
|
||||
*
|
||||
* If it is not possible to represent the R, G, and B transfer functions numerically
|
||||
* and it is still necessary to get the transfer function, this will return the
|
||||
* transfer functions as three tables (R, G, and B).
|
||||
*
|
||||
* If possible, this will return tables of the same length as they were specified in
|
||||
* the ICC profile. This means that the lengths of the three tables are not
|
||||
* guaranteed to be the same. If the ICC representation was not a table, the length
|
||||
* will be chosen arbitrarily.
|
||||
*
|
||||
* The lengths of the tables are all guaranteed to be at least 2. Entries in the
|
||||
* tables are guaranteed to be in [0, 1].
|
||||
*
|
||||
* This API may be deleted in favor of a numerical approximation of the raw data.
|
||||
*
|
||||
* This function may fail, indicating that the ICC profile does not have transfer
|
||||
* functions.
|
||||
*/
|
||||
struct Channel {
|
||||
// Byte offset of the start of the table in |fStorage|
|
||||
size_t fOffset;
|
||||
int fCount;
|
||||
};
|
||||
struct Tables {
|
||||
Channel fRed;
|
||||
Channel fGreen;
|
||||
Channel fBlue;
|
||||
|
||||
const float* red() {
|
||||
return (const float*) (fStorage->bytes() + fRed.fOffset);
|
||||
}
|
||||
const float* green() {
|
||||
return (const float*) (fStorage->bytes() + fGreen.fOffset);
|
||||
}
|
||||
const float* blue() {
|
||||
return (const float*) (fStorage->bytes() + fBlue.fOffset);
|
||||
}
|
||||
|
||||
sk_sp<SkData> fStorage;
|
||||
};
|
||||
bool rawTransferFnData(Tables* tables) const;
|
||||
|
||||
/**
|
||||
* Write an ICC profile with transfer function |fn| and gamut |toXYZD50|.
|
||||
*/
|
||||
static sk_sp<SkData> WriteToICC(const SkColorSpaceTransferFn& fn, const SkMatrix44& toXYZD50);
|
||||
|
||||
private:
|
||||
SkICC(sk_sp<SkColorSpace> colorSpace);
|
||||
|
||||
sk_sp<SkColorSpace> fColorSpace;
|
||||
|
||||
friend class ICCTest;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -18,7 +18,6 @@
|
|||
class SkData;
|
||||
class SkCanvas;
|
||||
class SkColorTable;
|
||||
class SkCrossContextImageData;
|
||||
class SkImageGenerator;
|
||||
class SkPaint;
|
||||
class SkPicture;
|
||||
|
@ -74,8 +73,7 @@ public:
|
|||
*
|
||||
* If a subset is specified, it must be contained within the generator's bounds.
|
||||
*/
|
||||
static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator>,
|
||||
const SkIRect* subset = nullptr);
|
||||
static sk_sp<SkImage> MakeFromGenerator(SkImageGenerator*, const SkIRect* subset = nullptr);
|
||||
|
||||
/**
|
||||
* Construct a new SkImage based on the specified encoded data. Returns NULL on failure,
|
||||
|
@ -156,18 +154,10 @@ public:
|
|||
const SkISize nv12Sizes[2], GrSurfaceOrigin,
|
||||
sk_sp<SkColorSpace> = nullptr);
|
||||
|
||||
enum class BitDepth {
|
||||
kU8,
|
||||
kF16,
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new image from the specified picture.
|
||||
* On creation of the SkImage, snap the SkPicture to a particular BitDepth and SkColorSpace.
|
||||
*/
|
||||
static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture>, const SkISize& dimensions,
|
||||
const SkMatrix*, const SkPaint*, BitDepth,
|
||||
sk_sp<SkColorSpace>);
|
||||
const SkMatrix*, const SkPaint*);
|
||||
|
||||
static sk_sp<SkImage> MakeTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted budgeted);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -177,21 +167,6 @@ public:
|
|||
SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); }
|
||||
uint32_t uniqueID() const { return fUniqueID; }
|
||||
SkAlphaType alphaType() const;
|
||||
|
||||
/**
|
||||
* Returns the color space of the SkImage.
|
||||
*
|
||||
* This is the color space that was supplied on creation of the SkImage or a color
|
||||
* space that was parsed from encoded data. This color space is not guaranteed to be
|
||||
* renderable. Can return nullptr if the SkImage was created without a color space.
|
||||
*/
|
||||
SkColorSpace* colorSpace() const;
|
||||
sk_sp<SkColorSpace> refColorSpace() const;
|
||||
|
||||
/**
|
||||
* Returns true fi the image will be drawn as a mask, with no intrinsic color of its own.
|
||||
*/
|
||||
bool isAlphaOnly() const;
|
||||
bool isOpaque() const { return SkAlphaTypeIsOpaque(this->alphaType()); }
|
||||
|
||||
/**
|
||||
|
@ -201,6 +176,11 @@ public:
|
|||
bool readYUV8Planes(const SkISize[3], void* const planes[3], const size_t rowBytes[3],
|
||||
SkYUVColorSpace) const;
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR
|
||||
SkShader* newShader(SkShader::TileMode, SkShader::TileMode,
|
||||
const SkMatrix* localMatrix = nullptr) const;
|
||||
#endif
|
||||
|
||||
sk_sp<SkShader> makeShader(SkShader::TileMode, SkShader::TileMode,
|
||||
const SkMatrix* localMatrix = nullptr) const;
|
||||
|
||||
|
@ -213,6 +193,35 @@ public:
|
|||
*/
|
||||
bool peekPixels(SkPixmap* pixmap) const;
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PEEKPIXELS_PARMS
|
||||
/**
|
||||
* If the image has direct access to its pixels (i.e. they are in local
|
||||
* RAM) return the (const) address of those pixels, and if not null, return
|
||||
* the ImageInfo and rowBytes. The returned address is only valid while
|
||||
* the image object is in scope.
|
||||
*
|
||||
* On failure, returns NULL and the info and rowBytes parameters are
|
||||
* ignored.
|
||||
*
|
||||
* DEPRECATED -- use the SkPixmap variant instead
|
||||
*/
|
||||
const void* peekPixels(SkImageInfo* info, size_t* rowBytes) const;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Some images have to perform preliminary work in preparation for drawing. This can be
|
||||
* decoding, uploading to a GPU, or other tasks. These happen automatically when an image
|
||||
* is drawn, and often they are cached so that the cost is only paid the first time.
|
||||
*
|
||||
* Preroll() can be called before drawing to try to perform this prepatory work ahead of time.
|
||||
* For images that have no such work, this returns instantly. Others may do some thing to
|
||||
* prepare their cache and then return.
|
||||
*
|
||||
* If the image will drawn to a GPU-backed canvas or surface, pass the associated GrContext.
|
||||
* If the image will be drawn to any other type of canvas or surface, pass null.
|
||||
*/
|
||||
void preroll(GrContext* = nullptr) const;
|
||||
|
||||
// DEPRECATED - currently used by Canvas2DLayerBridge in Chromium.
|
||||
GrTexture* getTexture() const;
|
||||
|
||||
|
@ -225,11 +234,8 @@ public:
|
|||
* Retrieves the backend API handle of the texture. If flushPendingGrContextIO then the
|
||||
* GrContext will issue to the backend API any deferred IO operations on the texture before
|
||||
* returning.
|
||||
* If 'origin' is supplied it will be filled in with the origin of the content drawn
|
||||
* into the image.
|
||||
*/
|
||||
GrBackendObject getTextureHandle(bool flushPendingGrContextIO,
|
||||
GrSurfaceOrigin* origin = nullptr) const;
|
||||
GrBackendObject getTextureHandle(bool flushPendingGrContextIO) const;
|
||||
|
||||
/**
|
||||
* Hints to image calls where the system might cache computed intermediates (e.g. the results
|
||||
|
@ -284,7 +290,7 @@ public:
|
|||
* Note: this will attempt to encode the image's pixels in the specified format,
|
||||
* even if the image returns a data from refEncoded(). That data will be ignored.
|
||||
*/
|
||||
SkData* encode(SkEncodedImageFormat, int quality) const;
|
||||
SkData* encode(SkImageEncoder::Type, int quality) const;
|
||||
|
||||
/**
|
||||
* Encode the image and return the result as a caller-managed SkData. This will
|
||||
|
@ -325,20 +331,11 @@ public:
|
|||
sk_sp<SkImage> makeSubset(const SkIRect& subset) const;
|
||||
|
||||
/**
|
||||
* Ensures that an image is backed by a texture (when GrContext is non-null), suitable for use
|
||||
* with surfaces that have the supplied destination color space. If no transformation is
|
||||
* required, the returned image may be the same as this image. If this image is from a
|
||||
* different GrContext, this will fail.
|
||||
* Ensures that an image is backed by a texture (when GrContext is non-null). If no
|
||||
* transformation is required, the returned image may be the same as this image. If the this
|
||||
* image is from a different GrContext, this will fail.
|
||||
*/
|
||||
sk_sp<SkImage> makeTextureImage(GrContext*, SkColorSpace* dstColorSpace) const;
|
||||
|
||||
/**
|
||||
* Constructs a texture backed image from data that was previously uploaded on another thread
|
||||
* and GrContext. The GrContext used to upload the data must be in the same GL share group as
|
||||
* the one passed in here, or otherwise be able to share resources with the passed in context.
|
||||
*/
|
||||
static sk_sp<SkImage> MakeFromCrossContextImageData(GrContext*,
|
||||
std::unique_ptr<SkCrossContextImageData>);
|
||||
sk_sp<SkImage> makeTextureImage(GrContext*) const;
|
||||
|
||||
/**
|
||||
* If the image is texture-backed this will make a raster copy of it (or nullptr if reading back
|
||||
|
@ -395,16 +392,13 @@ public:
|
|||
* When buffer is not null this fills in the deferred texture data for this image in the
|
||||
* provided buffer (assuming this is an appropriate candidate image and the buffer is
|
||||
* appropriately aligned). Upon success the size written is returned, otherwise 0.
|
||||
*
|
||||
* dstColorSpace is the color space of the surface where this texture will ultimately be used.
|
||||
* If the method determines that mip-maps are needed, this helps determine the correct strategy
|
||||
* for building them (gamma-correct or not).
|
||||
*/
|
||||
size_t getDeferredTextureImageData(const GrContextThreadSafeProxy&,
|
||||
const DeferredTextureImageUsageParams[],
|
||||
int paramCnt,
|
||||
void* buffer,
|
||||
SkColorSpace* dstColorSpace = nullptr) const;
|
||||
SkSourceGammaTreatment treatment =
|
||||
SkSourceGammaTreatment::kIgnore) const;
|
||||
|
||||
/**
|
||||
* Returns a texture-backed image from data produced in SkImage::getDeferredTextureImageData.
|
||||
|
@ -437,21 +431,39 @@ public:
|
|||
*/
|
||||
bool isLazyGenerated() const;
|
||||
|
||||
/**
|
||||
* If |target| is supported, returns an SkImage in the |target| color space.
|
||||
* Otherwise, returns nullptr.
|
||||
*
|
||||
* This will leave the image as is if it already in the |target| color space.
|
||||
* Otherwise, it will convert the pixels from the src color space to the |target|
|
||||
* color space. If this->colorSpace() is nullptr, the src color space will be
|
||||
* treated as sRGB.
|
||||
*
|
||||
* If |premulBehavior| is kIgnore, any premultiplication or unpremultiplication will
|
||||
* be performed in the gamma encoded space. If it is kRespect, premultiplication is
|
||||
* assumed to be linear.
|
||||
*/
|
||||
sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target,
|
||||
SkTransferFunctionBehavior premulBehavior) const;
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFACTORY
|
||||
static SkImage* NewRasterCopy(const Info&, const void* pixels, size_t rowBytes,
|
||||
SkColorTable* ctable = nullptr);
|
||||
static SkImage* NewRasterData(const Info&, SkData* pixels, size_t rowBytes);
|
||||
static SkImage* NewFromRaster(const Info&, const void* pixels, size_t rowBytes,
|
||||
RasterReleaseProc, ReleaseContext);
|
||||
static SkImage* NewFromBitmap(const SkBitmap&);
|
||||
static SkImage* NewFromGenerator(SkImageGenerator*, const SkIRect* subset = nullptr);
|
||||
static SkImage* NewFromEncoded(SkData* encoded, const SkIRect* subset = nullptr);
|
||||
static SkImage* NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc) {
|
||||
return NewFromTexture(ctx, desc, kPremul_SkAlphaType, nullptr, nullptr);
|
||||
}
|
||||
|
||||
static SkImage* NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& de, SkAlphaType at) {
|
||||
return NewFromTexture(ctx, de, at, nullptr, nullptr);
|
||||
}
|
||||
static SkImage* NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
|
||||
TextureReleaseProc, ReleaseContext);
|
||||
static SkImage* NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
|
||||
SkAlphaType = kPremul_SkAlphaType);
|
||||
static SkImage* NewFromYUVTexturesCopy(GrContext*, SkYUVColorSpace,
|
||||
const GrBackendObject yuvTextureHandles[3],
|
||||
const SkISize yuvSizes[3],
|
||||
GrSurfaceOrigin);
|
||||
static SkImage* NewFromPicture(const SkPicture*, const SkISize& dimensions,
|
||||
const SkMatrix*, const SkPaint*);
|
||||
static SkImage* NewTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted budgeted);
|
||||
static SkImage* NewFromDeferredTextureImageData(GrContext*, const void*, SkBudgeted);
|
||||
|
||||
SkImage* newSubset(const SkIRect& subset) const { return this->makeSubset(subset).release(); }
|
||||
SkImage* newTextureImage(GrContext* ctx) const { return this->makeTextureImage(ctx).release(); }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
SkImage(int width, int height, uint32_t uniqueID);
|
||||
|
@ -459,7 +471,7 @@ protected:
|
|||
private:
|
||||
static sk_sp<SkImage> MakeTextureFromMipMap(GrContext*, const SkImageInfo&,
|
||||
const GrMipLevel* texels, int mipLevelCount,
|
||||
SkBudgeted, SkDestinationSurfaceColorMode);
|
||||
SkBudgeted, SkSourceGammaTreatment);
|
||||
|
||||
const int fWidth;
|
||||
const int fHeight;
|
||||
|
|
|
@ -8,35 +8,112 @@
|
|||
#ifndef SkImageEncoder_DEFINED
|
||||
#define SkImageEncoder_DEFINED
|
||||
|
||||
#include "SkBitmap.h"
|
||||
#include "SkEncodedImageFormat.h"
|
||||
#include "SkStream.h"
|
||||
#include "SkImageInfo.h"
|
||||
#include "SkTRegistry.h"
|
||||
|
||||
/**
|
||||
* Encode SkPixmap in the given binary image format.
|
||||
*
|
||||
* @param dst results are written to this stream.
|
||||
* @param src source pixels.
|
||||
* @param format image format, not all formats are supported.
|
||||
* @param quality range from 0-100, not all formats respect quality.
|
||||
*
|
||||
* @return false iff input is bad or format is unsupported.
|
||||
*
|
||||
* Will always return false if Skia is compiled without image
|
||||
* encoders.
|
||||
*
|
||||
* For examples of encoding an image to a file or to a block of memory,
|
||||
* see tools/sk_tool_utils.h.
|
||||
*/
|
||||
SK_API bool SkEncodeImage(SkWStream* dst, const SkPixmap& src,
|
||||
SkEncodedImageFormat format, int quality);
|
||||
/**
|
||||
* The following helper function wraps SkEncodeImage().
|
||||
*/
|
||||
inline bool SkEncodeImage(SkWStream* dst, const SkBitmap& src, SkEncodedImageFormat f, int q) {
|
||||
SkAutoLockPixels autoLockPixels(src);
|
||||
SkPixmap pixmap;
|
||||
return src.peekPixels(&pixmap) && SkEncodeImage(dst, pixmap, f, q);
|
||||
}
|
||||
class SkBitmap;
|
||||
class SkPixelSerializer;
|
||||
class SkPixmap;
|
||||
class SkData;
|
||||
class SkWStream;
|
||||
|
||||
#endif // SkImageEncoder_DEFINED
|
||||
class SkImageEncoder {
|
||||
public:
|
||||
// TODO (scroggo): Merge with SkEncodedFormat.
|
||||
enum Type {
|
||||
kUnknown_Type,
|
||||
kBMP_Type,
|
||||
kGIF_Type,
|
||||
kICO_Type,
|
||||
kJPEG_Type,
|
||||
kPNG_Type,
|
||||
kWBMP_Type,
|
||||
kWEBP_Type,
|
||||
kKTX_Type,
|
||||
};
|
||||
static SkImageEncoder* Create(Type);
|
||||
|
||||
virtual ~SkImageEncoder();
|
||||
|
||||
/* Quality ranges from 0..100 */
|
||||
enum {
|
||||
kDefaultQuality = 80
|
||||
};
|
||||
|
||||
/**
|
||||
* Encode bitmap 'bm', returning the results in an SkData, at quality level
|
||||
* 'quality' (which can be in range 0-100). If the bitmap cannot be
|
||||
* encoded, return null. On success, the caller is responsible for
|
||||
* calling unref() on the data when they are finished.
|
||||
*/
|
||||
SkData* encodeData(const SkBitmap&, int quality);
|
||||
|
||||
/**
|
||||
* Encode bitmap 'bm' in the desired format, writing results to
|
||||
* file 'file', at quality level 'quality' (which can be in range
|
||||
* 0-100). Returns false on failure.
|
||||
*/
|
||||
bool encodeFile(const char file[], const SkBitmap& bm, int quality);
|
||||
|
||||
/**
|
||||
* Encode bitmap 'bm' in the desired format, writing results to
|
||||
* stream 'stream', at quality level 'quality' (which can be in
|
||||
* range 0-100). Returns false on failure.
|
||||
*/
|
||||
bool encodeStream(SkWStream* stream, const SkBitmap& bm, int quality);
|
||||
|
||||
static SkData* EncodeData(const SkImageInfo&, const void* pixels, size_t rowBytes,
|
||||
Type, int quality);
|
||||
static SkData* EncodeData(const SkBitmap&, Type, int quality);
|
||||
|
||||
static SkData* EncodeData(const SkPixmap&, Type, int quality);
|
||||
|
||||
static bool EncodeFile(const char file[], const SkBitmap&, Type,
|
||||
int quality);
|
||||
static bool EncodeStream(SkWStream*, const SkBitmap&, Type,
|
||||
int quality);
|
||||
|
||||
/** Uses SkImageEncoder to serialize images that are not already
|
||||
encoded as SkImageEncoder::kPNG_Type images. */
|
||||
static SkPixelSerializer* CreatePixelSerializer();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Encode bitmap 'bm' in the desired format, writing results to
|
||||
* stream 'stream', at quality level 'quality' (which can be in
|
||||
* range 0-100).
|
||||
*
|
||||
* This must be overridden by each SkImageEncoder implementation.
|
||||
*/
|
||||
virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) = 0;
|
||||
};
|
||||
|
||||
// This macro declares a global (i.e., non-class owned) creation entry point
|
||||
// for each encoder (e.g., CreateJPEGImageEncoder)
|
||||
#define DECLARE_ENCODER_CREATOR(codec) \
|
||||
SK_API SkImageEncoder *Create ## codec ();
|
||||
|
||||
// This macro defines the global creation entry point for each encoder. Each
|
||||
// encoder implementation that registers with the encoder factory must call it.
|
||||
#define DEFINE_ENCODER_CREATOR(codec) \
|
||||
SkImageEncoder* Create##codec() { return new Sk##codec; }
|
||||
|
||||
// All the encoders known by Skia. Note that, depending on the compiler settings,
|
||||
// not all of these will be available
|
||||
DECLARE_ENCODER_CREATOR(JPEGImageEncoder);
|
||||
DECLARE_ENCODER_CREATOR(PNGImageEncoder);
|
||||
DECLARE_ENCODER_CREATOR(KTXImageEncoder);
|
||||
DECLARE_ENCODER_CREATOR(WEBPImageEncoder);
|
||||
|
||||
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
||||
SkImageEncoder* CreateImageEncoder_CG(SkImageEncoder::Type type);
|
||||
#endif
|
||||
|
||||
#if defined(SK_BUILD_FOR_WIN)
|
||||
SkImageEncoder* CreateImageEncoder_WIC(SkImageEncoder::Type type);
|
||||
#endif
|
||||
|
||||
// Typedef to make registering encoder callback easier
|
||||
// This has to be defined outside SkImageEncoder. :(
|
||||
typedef SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> SkImageEncoder_EncodeReg;
|
||||
#endif
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
class GrContext;
|
||||
class GrFragmentProcessor;
|
||||
class SkColorFilter;
|
||||
class SkColorSpaceXformer;
|
||||
struct SkIPoint;
|
||||
class SkSpecialImage;
|
||||
class SkImageFilterCache;
|
||||
|
@ -224,6 +223,12 @@ public:
|
|||
*/
|
||||
sk_sp<SkImageFilter> makeWithLocalMatrix(const SkMatrix&) const;
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
SkImageFilter* newWithLocalMatrix(const SkMatrix& matrix) const {
|
||||
return this->makeWithLocalMatrix(matrix).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ImageFilters can natively handle scaling and translate components in the CTM. Only some of
|
||||
* them can handle affine (or more complex) matrices. This call returns true iff the filter
|
||||
|
@ -238,6 +243,14 @@ public:
|
|||
SkFilterQuality quality,
|
||||
sk_sp<SkImageFilter> input);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
static SkImageFilter* CreateMatrixFilter(const SkMatrix& matrix,
|
||||
SkFilterQuality filterQuality,
|
||||
SkImageFilter* input = nullptr) {
|
||||
return MakeMatrixFilter(matrix, filterQuality, sk_ref_sp<SkImageFilter>(input)).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
SK_TO_STRING_PUREVIRT()
|
||||
SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter)
|
||||
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
|
||||
|
@ -271,7 +284,7 @@ protected:
|
|||
|
||||
SkImageFilter(sk_sp<SkImageFilter>* inputs, int inputCount, const CropRect* cropRect);
|
||||
|
||||
~SkImageFilter() override;
|
||||
virtual ~SkImageFilter();
|
||||
|
||||
/**
|
||||
* Constructs a new SkImageFilter read from an SkReadBuffer object.
|
||||
|
@ -284,10 +297,6 @@ protected:
|
|||
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
|
||||
const CropRect* getCropRectIfSet() const {
|
||||
return this->cropRectIsSet() ? &fCropRect : nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the virtual which should be overridden by the derived class
|
||||
* to perform image filtering.
|
||||
|
@ -391,46 +400,8 @@ protected:
|
|||
*/
|
||||
Context mapContext(const Context& ctx) const;
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
/**
|
||||
* Returns a version of the passed-in image (possibly the original), that is in a colorspace
|
||||
* with the same gamut as the one from the OutputProperties. This allows filters that do many
|
||||
* texture samples to guarantee that any color space conversion has happened before running.
|
||||
*/
|
||||
static sk_sp<SkSpecialImage> ImageToColorSpace(SkSpecialImage* src, const OutputProperties&);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns an image filter transformed into a new color space via the |xformer|.
|
||||
*/
|
||||
sk_sp<SkImageFilter> makeColorSpace(SkColorSpaceXformer* xformer) const {
|
||||
return this->onMakeColorSpace(xformer);
|
||||
}
|
||||
virtual sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const {
|
||||
return sk_ref_sp(const_cast<SkImageFilter*>(this));
|
||||
}
|
||||
|
||||
private:
|
||||
// For makeColorSpace().
|
||||
friend class ArithmeticImageFilterImpl;
|
||||
friend class SkAlphaThresholdFilterImpl;
|
||||
friend class SkBlurImageFilterImpl;
|
||||
friend class SkColorFilterImageFilter;
|
||||
friend class SkColorSpaceXformer;
|
||||
friend class SkComposeImageFilter;
|
||||
friend class SkDisplacementMapEffect;
|
||||
friend class SkDropShadowImageFilter;
|
||||
friend class SkImageSource;
|
||||
friend class SkMagnifierImageFilter;
|
||||
friend class SkMatrixConvolutionImageFilter;
|
||||
friend class SkMergeImageFilter;
|
||||
friend class SkMorphologyImageFilter;
|
||||
friend class SkOffsetImageFilter;
|
||||
friend class SkTileImageFilter;
|
||||
friend class SkXfermodeImageFilter_Base;
|
||||
|
||||
friend class SkGraphics;
|
||||
|
||||
static void PurgeCache();
|
||||
|
||||
void init(sk_sp<SkImageFilter>* inputs, int inputCount, const CropRect* cropRect);
|
||||
|
|
|
@ -10,20 +10,55 @@
|
|||
|
||||
#include "SkBitmap.h"
|
||||
#include "SkColor.h"
|
||||
#include "SkImage.h"
|
||||
#include "SkImageInfo.h"
|
||||
#include "SkYUVSizeInfo.h"
|
||||
|
||||
class GrContext;
|
||||
class GrContextThreadSafeProxy;
|
||||
class GrTextureProxy;
|
||||
class GrSamplerParams;
|
||||
class GrTexture;
|
||||
class GrTextureParams;
|
||||
class SkBitmap;
|
||||
class SkData;
|
||||
class SkImageGenerator;
|
||||
class SkMatrix;
|
||||
class SkPaint;
|
||||
class SkPicture;
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX
|
||||
#define SK_REFENCODEDDATA_CTXPARAM
|
||||
#else
|
||||
#define SK_REFENCODEDDATA_CTXPARAM GrContext* ctx
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Takes ownership of SkImageGenerator. If this method fails for
|
||||
* whatever reason, it will return false and immediatetely delete
|
||||
* the generator. If it succeeds, it will modify destination
|
||||
* bitmap.
|
||||
*
|
||||
* If generator is NULL, will safely return false.
|
||||
*
|
||||
* If this fails or when the SkDiscardablePixelRef that is
|
||||
* installed into destination is destroyed, it will
|
||||
* delete the generator. Therefore, generator should be
|
||||
* allocated with new.
|
||||
*
|
||||
* @param destination Upon success, this bitmap will be
|
||||
* configured and have a pixelref installed.
|
||||
*
|
||||
* @return true iff successful.
|
||||
*/
|
||||
SK_API bool SkDEPRECATED_InstallDiscardablePixelRef(SkImageGenerator*, SkBitmap* destination);
|
||||
|
||||
/**
|
||||
* On success, installs a discardable pixelref into destination, based on encoded data.
|
||||
* Regardless of success or failure, the caller must still balance their ownership of encoded.
|
||||
*/
|
||||
SK_API bool SkDEPRECATED_InstallDiscardablePixelRef(SkData* encoded, SkBitmap* destination);
|
||||
|
||||
/**
|
||||
* An interface that allows a purgeable PixelRef (such as a
|
||||
* SkDiscardablePixelRef) to decode and re-decode an image as needed.
|
||||
*/
|
||||
class SK_API SkImageGenerator : public SkNoncopyable {
|
||||
public:
|
||||
/**
|
||||
|
@ -44,7 +79,11 @@ public:
|
|||
* unref() on the data when it is finished.
|
||||
*/
|
||||
SkData* refEncodedData(GrContext* ctx = nullptr) {
|
||||
#ifdef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX
|
||||
return this->onRefEncodedData();
|
||||
#else
|
||||
return this->onRefEncodedData(ctx);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,49 +151,104 @@ public:
|
|||
*/
|
||||
bool getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]);
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
/**
|
||||
* If the generator can natively/efficiently return its pixels as a GPU image (backed by a
|
||||
* texture) this will return that image. If not, this will return NULL.
|
||||
*
|
||||
* This routine also supports retrieving only a subset of the pixels. That subset is specified
|
||||
* by the following rectangle:
|
||||
* Regarding the GrContext parameter:
|
||||
*
|
||||
* subset = SkIRect::MakeXYWH(origin.x(), origin.y(), info.width(), info.height())
|
||||
* The caller may pass NULL for the context. In that case the generator may assume that its
|
||||
* internal context is current. If it has no internal context, then it should just return
|
||||
* null.
|
||||
*
|
||||
* If subset is not contained inside the generator's bounds, this returns false.
|
||||
* If the caller passes a non-null context, then the generator should only succeed if:
|
||||
* - it has no intrinsic context, and will use the caller's
|
||||
* - its internal context is the same
|
||||
* - it can somehow convert its texture into one that is valid for the provided context.
|
||||
*
|
||||
* whole = SkIRect::MakeWH(getInfo().width(), getInfo().height())
|
||||
* Regarding the GrTextureParams parameter:
|
||||
*
|
||||
* If the context (the provided one or the generator's intrinsic one) determines that to
|
||||
* support the specified usage, it must return a different sized texture it may,
|
||||
* so the caller must inspect the texture's width/height and compare them to the generator's
|
||||
* getInfo() width/height. For readback usage use GrTextureParams::ClampNoFilter()
|
||||
*/
|
||||
GrTexture* generateTexture(GrContext*, const SkIRect* subset = nullptr);
|
||||
|
||||
struct SupportedSizes {
|
||||
SkISize fSizes[2];
|
||||
};
|
||||
|
||||
/**
|
||||
* Some generators can efficiently scale their contents. If this is supported, the generator
|
||||
* may only support certain scaled dimensions. Call this with the desired scale factor,
|
||||
* and it will return true if scaling is supported, and in supportedSizes[] it will return
|
||||
* the nearest supported dimensions.
|
||||
*
|
||||
* If no native scaling is supported, or scale is invalid (e.g. scale <= 0 || scale > 1)
|
||||
* this will return false, and the supportedsizes will be undefined.
|
||||
*/
|
||||
bool computeScaledDimensions(SkScalar scale, SupportedSizes*);
|
||||
|
||||
/**
|
||||
* Scale the generator's pixels to fit into scaledSize.
|
||||
* This routine also support retrieving only a subset of the pixels. That subset is specified
|
||||
* by the following rectangle (in the scaled space):
|
||||
*
|
||||
* subset = SkIRect::MakeXYWH(subsetOrigin.x(), subsetOrigin.y(),
|
||||
* subsetPixels.width(), subsetPixels.height())
|
||||
*
|
||||
* If subset is not contained inside the scaledSize, this returns false.
|
||||
*
|
||||
* whole = SkIRect::MakeWH(scaledSize.width(), scaledSize.height())
|
||||
* if (!whole.contains(subset)) {
|
||||
* return false;
|
||||
* }
|
||||
*
|
||||
* Regarding the GrContext parameter:
|
||||
*
|
||||
* It must be non-NULL. The generator should only succeed if:
|
||||
* - its internal context is the same
|
||||
* - it can somehow convert its texture into one that is valid for the provided context.
|
||||
* If the requested colortype/alphatype in pixels is not supported,
|
||||
* or the requested scaledSize is not supported, or the generator encounters an error,
|
||||
* this returns false.
|
||||
*/
|
||||
sk_sp<GrTextureProxy> generateTexture(GrContext*, const SkImageInfo& info,
|
||||
const SkIPoint& origin);
|
||||
#endif
|
||||
bool generateScaledPixels(const SkISize& scaledSize, const SkIPoint& subsetOrigin,
|
||||
const SkPixmap& subsetPixels);
|
||||
|
||||
bool generateScaledPixels(const SkPixmap& scaledPixels) {
|
||||
return this->generateScaledPixels(SkISize::Make(scaledPixels.width(),
|
||||
scaledPixels.height()),
|
||||
SkIPoint::Make(0, 0), scaledPixels);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the default image decoder system can interpret the specified (encoded) data, then
|
||||
* this returns a new ImageGenerator for it. Otherwise this returns NULL. Either way
|
||||
* the caller is still responsible for managing their ownership of the data.
|
||||
*/
|
||||
static std::unique_ptr<SkImageGenerator> MakeFromEncoded(sk_sp<SkData>);
|
||||
static SkImageGenerator* NewFromEncoded(SkData*);
|
||||
|
||||
/** Return a new image generator backed by the specified picture. If the size is empty or
|
||||
* the picture is NULL, this returns NULL.
|
||||
* The optional matrix and paint arguments are passed to drawPicture() at rasterization
|
||||
* time.
|
||||
*/
|
||||
static std::unique_ptr<SkImageGenerator> MakeFromPicture(const SkISize&, sk_sp<SkPicture>,
|
||||
const SkMatrix*, const SkPaint*,
|
||||
SkImage::BitDepth,
|
||||
sk_sp<SkColorSpace>);
|
||||
static SkImageGenerator* NewFromPicture(const SkISize&, const SkPicture*, const SkMatrix*,
|
||||
const SkPaint*);
|
||||
|
||||
bool tryGenerateBitmap(SkBitmap* bm) {
|
||||
return this->tryGenerateBitmap(bm, nullptr, nullptr);
|
||||
}
|
||||
bool tryGenerateBitmap(SkBitmap* bm, const SkImageInfo& info, SkBitmap::Allocator* allocator) {
|
||||
return this->tryGenerateBitmap(bm, &info, allocator);
|
||||
}
|
||||
void generateBitmap(SkBitmap* bm) {
|
||||
if (!this->tryGenerateBitmap(bm, nullptr, nullptr)) {
|
||||
sk_throw();
|
||||
}
|
||||
}
|
||||
void generateBitmap(SkBitmap* bm, const SkImageInfo& info) {
|
||||
if (!this->tryGenerateBitmap(bm, &info, nullptr)) {
|
||||
sk_throw();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
enum {
|
||||
|
@ -163,7 +257,7 @@ protected:
|
|||
|
||||
SkImageGenerator(const SkImageInfo& info, uint32_t uniqueId = kNeedNewImageUniqueID);
|
||||
|
||||
virtual SkData* onRefEncodedData(GrContext* ctx);
|
||||
virtual SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM);
|
||||
|
||||
virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
||||
SkPMColor ctable[], int* ctableCount);
|
||||
|
@ -175,38 +269,27 @@ protected:
|
|||
return false;
|
||||
}
|
||||
|
||||
struct Options {
|
||||
Options()
|
||||
: fColorTable(nullptr)
|
||||
, fColorTableCount(nullptr)
|
||||
, fBehavior(SkTransferFunctionBehavior::kRespect)
|
||||
{}
|
||||
|
||||
SkPMColor* fColorTable;
|
||||
int* fColorTableCount;
|
||||
SkTransferFunctionBehavior fBehavior;
|
||||
};
|
||||
bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options* opts);
|
||||
virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
||||
const Options& opts) {
|
||||
return this->onGetPixels(info, pixels, rowBytes, opts.fColorTable, opts.fColorTableCount);
|
||||
virtual GrTexture* onGenerateTexture(GrContext*, const SkIRect*) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
virtual sk_sp<GrTextureProxy> onGenerateTexture(GrContext*, const SkImageInfo&,
|
||||
const SkIPoint&);
|
||||
#endif
|
||||
virtual bool onComputeScaledDimensions(SkScalar, SupportedSizes*) {
|
||||
return false;
|
||||
}
|
||||
virtual bool onGenerateScaledPixels(const SkISize&, const SkIPoint&, const SkPixmap&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool tryGenerateBitmap(SkBitmap* bm, const SkImageInfo* optionalInfo, SkBitmap::Allocator*);
|
||||
|
||||
private:
|
||||
const SkImageInfo fInfo;
|
||||
const uint32_t fUniqueID;
|
||||
|
||||
friend class SkImageCacherator;
|
||||
|
||||
// This is our default impl, which may be different on different platforms.
|
||||
// It is called from NewFromEncoded() after it has checked for any runtime factory.
|
||||
// The SkData will never be NULL, as that will have been checked by NewFromEncoded.
|
||||
static std::unique_ptr<SkImageGenerator> MakeFromEncodedImpl(sk_sp<SkData>);
|
||||
static SkImageGenerator* NewFromEncodedImpl(SkData*);
|
||||
};
|
||||
|
||||
#endif // SkImageGenerator_DEFINED
|
||||
|
|
|
@ -169,9 +169,9 @@ enum SkYUVColorSpace {
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class SkDestinationSurfaceColorMode {
|
||||
kLegacy,
|
||||
kGammaAndColorSpaceAware,
|
||||
enum class SkSourceGammaTreatment {
|
||||
kRespect,
|
||||
kIgnore,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -234,7 +234,6 @@ public:
|
|||
SkColorType colorType() const { return fColorType; }
|
||||
SkAlphaType alphaType() const { return fAlphaType; }
|
||||
SkColorSpace* colorSpace() const { return fColorSpace.get(); }
|
||||
sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; }
|
||||
|
||||
bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
|
||||
|
||||
|
@ -278,11 +277,7 @@ public:
|
|||
}
|
||||
|
||||
size_t minRowBytes() const {
|
||||
uint64_t minRowBytes = this->minRowBytes64();
|
||||
if (!sk_64_isS32(minRowBytes)) {
|
||||
return 0;
|
||||
}
|
||||
return sk_64_asS32(minRowBytes);
|
||||
return (size_t)this->minRowBytes64();
|
||||
}
|
||||
|
||||
size_t computeOffset(int x, int y, size_t rowBytes) const {
|
||||
|
@ -307,7 +302,7 @@ public:
|
|||
if (0 == fHeight) {
|
||||
return 0;
|
||||
}
|
||||
return sk_64_mul(fHeight - 1, rowBytes) + sk_64_mul(fWidth, this->bytesPerPixel());
|
||||
return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel();
|
||||
}
|
||||
|
||||
size_t getSafeSize(size_t rowBytes) const {
|
||||
|
@ -349,4 +344,16 @@ private:
|
|||
{}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static inline bool SkColorAndColorSpaceAreGammaCorrect(SkColorType ct, SkColorSpace* cs) {
|
||||
// Anything with a color-space attached is gamma-correct, as is F16.
|
||||
// To get legacy behavior, you need to ask for non-F16, with a nullptr color space.
|
||||
return (cs != nullptr) || kRGBA_F16_SkColorType == ct;
|
||||
}
|
||||
|
||||
static inline bool SkImageInfoIsGammaCorrect(const SkImageInfo& info) {
|
||||
return SkColorAndColorSpaceAreGammaCorrect(info.colorType(), info.colorSpace());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
#define SkLights_DEFINED
|
||||
|
||||
#include "../private/SkTArray.h"
|
||||
#include "SkImage.h"
|
||||
#include "SkPoint3.h"
|
||||
#include "SkRefCnt.h"
|
||||
|
||||
class SkReadBuffer;
|
||||
class SkWriteBuffer;
|
||||
class SkImage;
|
||||
|
||||
class SK_API SkLights : public SkRefCnt {
|
||||
public:
|
||||
|
|
|
@ -22,10 +22,12 @@ public:
|
|||
* lifetime of the pixel storage buffer, as this pixelref will not try
|
||||
* to delete it.
|
||||
*
|
||||
* The pixelref will ref() the colortable (if not NULL).
|
||||
*
|
||||
* Returns NULL on failure.
|
||||
*/
|
||||
static sk_sp<SkPixelRef> MakeDirect(const SkImageInfo&, void* addr,
|
||||
size_t rowBytes, sk_sp<SkColorTable>);
|
||||
static SkMallocPixelRef* NewDirect(const SkImageInfo&, void* addr,
|
||||
size_t rowBytes, SkColorTable*);
|
||||
|
||||
/**
|
||||
* Return a new SkMallocPixelRef, automatically allocating storage for the
|
||||
|
@ -37,18 +39,22 @@ public:
|
|||
*
|
||||
* Returns NULL on failure.
|
||||
*/
|
||||
static sk_sp<SkPixelRef> MakeAllocate(const SkImageInfo&, size_t rowBytes, sk_sp<SkColorTable>);
|
||||
static SkMallocPixelRef* NewAllocate(const SkImageInfo& info,
|
||||
size_t rowBytes, SkColorTable*);
|
||||
|
||||
/**
|
||||
* Identical to MakeAllocate, except all pixel bytes are zeroed.
|
||||
* Identical to NewAllocate, except all pixel bytes are zeroed.
|
||||
*/
|
||||
static sk_sp<SkPixelRef> MakeZeroed(const SkImageInfo&, size_t rowBytes, sk_sp<SkColorTable>);
|
||||
static SkMallocPixelRef* NewZeroed(const SkImageInfo& info,
|
||||
size_t rowBytes, SkColorTable*);
|
||||
|
||||
/**
|
||||
* Return a new SkMallocPixelRef with the provided pixel storage,
|
||||
* rowBytes, and optional colortable. On destruction, ReleaseProc
|
||||
* will be called.
|
||||
*
|
||||
* This pixelref will ref() the specified colortable (if not NULL).
|
||||
*
|
||||
* If ReleaseProc is NULL, the pixels will never be released. This
|
||||
* can be useful if the pixels were stack allocated. However, such an
|
||||
* SkMallocPixelRef must not live beyond its pixels (e.g. by copying
|
||||
|
@ -57,10 +63,10 @@ public:
|
|||
* Returns NULL on failure.
|
||||
*/
|
||||
typedef void (*ReleaseProc)(void* addr, void* context);
|
||||
static sk_sp<SkPixelRef> MakeWithProc(const SkImageInfo& info,
|
||||
size_t rowBytes, sk_sp<SkColorTable>,
|
||||
void* addr, ReleaseProc proc,
|
||||
void* context);
|
||||
static SkMallocPixelRef* NewWithProc(const SkImageInfo& info,
|
||||
size_t rowBytes, SkColorTable*,
|
||||
void* addr, ReleaseProc proc,
|
||||
void* context);
|
||||
|
||||
/**
|
||||
* Return a new SkMallocPixelRef that will use the provided
|
||||
|
@ -68,56 +74,51 @@ public:
|
|||
* The SkData will be ref()ed and on destruction of the PielRef,
|
||||
* the SkData will be unref()ed.
|
||||
*
|
||||
* This pixelref will ref() the specified colortable (if not NULL).
|
||||
*
|
||||
* Returns NULL on failure.
|
||||
*/
|
||||
static sk_sp<SkPixelRef> MakeWithData(const SkImageInfo& info,
|
||||
size_t rowBytes,
|
||||
sk_sp<SkColorTable>,
|
||||
sk_sp<SkData> data);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PIXELREFFACTORY
|
||||
static SkMallocPixelRef* NewDirect(const SkImageInfo& info, void* addr,
|
||||
size_t rowBytes, SkColorTable* ctable) {
|
||||
return (SkMallocPixelRef*)MakeDirect(info, addr, rowBytes, sk_ref_sp(ctable)).release();
|
||||
}
|
||||
static SkMallocPixelRef* NewAllocate(const SkImageInfo& info, size_t rb, SkColorTable* ct) {
|
||||
return (SkMallocPixelRef*)MakeAllocate(info, rb, sk_ref_sp(ct)).release();
|
||||
}
|
||||
static SkMallocPixelRef* NewZeroed(const SkImageInfo& info, size_t rowBytes, SkColorTable* ct) {
|
||||
return (SkMallocPixelRef*)MakeZeroed(info, rowBytes, sk_ref_sp(ct)).release();
|
||||
}
|
||||
static SkMallocPixelRef* NewWithProc(const SkImageInfo& info,
|
||||
size_t rowBytes, SkColorTable* ctable,
|
||||
void* addr, ReleaseProc proc,
|
||||
void* ctx) {
|
||||
return (SkMallocPixelRef*)MakeWithProc(info, rowBytes, sk_ref_sp(ctable), addr, proc, ctx).release();
|
||||
}
|
||||
static SkMallocPixelRef* NewWithData(const SkImageInfo& info,
|
||||
size_t rowBytes,
|
||||
SkColorTable* ctable,
|
||||
SkData* data);
|
||||
#endif
|
||||
|
||||
void* getAddr() const { return fStorage; }
|
||||
|
||||
class PRFactory : public SkPixelRefFactory {
|
||||
public:
|
||||
SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable*) override;
|
||||
};
|
||||
|
||||
class ZeroedPRFactory : public SkPixelRefFactory {
|
||||
public:
|
||||
SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable*) override;
|
||||
};
|
||||
|
||||
protected:
|
||||
~SkMallocPixelRef() override;
|
||||
// The ownPixels version of this constructor is deprecated.
|
||||
SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
|
||||
bool ownPixels);
|
||||
virtual ~SkMallocPixelRef();
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_NO_ADDR_PIXELREF
|
||||
bool onNewLockPixels(LockRec*) override;
|
||||
void onUnlockPixels() override;
|
||||
#endif
|
||||
size_t getAllocatedSizeInBytes() const override;
|
||||
|
||||
private:
|
||||
// Uses alloc to implement NewAllocate or NewZeroed.
|
||||
static sk_sp<SkPixelRef> MakeUsing(void*(*alloc)(size_t),
|
||||
const SkImageInfo&,
|
||||
size_t rowBytes,
|
||||
sk_sp<SkColorTable>);
|
||||
static SkMallocPixelRef* NewUsing(void*(*alloc)(size_t),
|
||||
const SkImageInfo&,
|
||||
size_t rowBytes,
|
||||
SkColorTable*);
|
||||
|
||||
ReleaseProc fReleaseProc;
|
||||
void* fReleaseProcContext;
|
||||
void* fStorage;
|
||||
SkColorTable* fCTable;
|
||||
size_t fRB;
|
||||
ReleaseProc fReleaseProc;
|
||||
void* fReleaseProcContext;
|
||||
|
||||
SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, sk_sp<SkColorTable>,
|
||||
SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
|
||||
ReleaseProc proc, void* context);
|
||||
|
||||
typedef SkPixelRef INHERITED;
|
||||
|
|
|
@ -18,13 +18,10 @@
|
|||
|
||||
class GrClip;
|
||||
class GrContext;
|
||||
class GrRenderTargetContext;
|
||||
class GrDrawContext;
|
||||
class GrPaint;
|
||||
class GrFragmentProcessor;
|
||||
class GrRenderTarget;
|
||||
class GrResourceProvider;
|
||||
class GrTexture;
|
||||
class GrTextureProxy;
|
||||
class GrTextureProvider;
|
||||
class SkBitmap;
|
||||
class SkBlitter;
|
||||
class SkCachedData;
|
||||
|
@ -112,23 +109,23 @@ public:
|
|||
SkRect* maskRect) const;
|
||||
|
||||
/**
|
||||
* Try to directly render the mask filter into the target. Returns true if drawing was
|
||||
* successful. If false is returned then paint is unmodified.
|
||||
* Try to directly render the mask filter into the target. Returns
|
||||
* true if drawing was successful.
|
||||
*/
|
||||
virtual bool directFilterMaskGPU(GrContext*,
|
||||
GrRenderTargetContext* renderTargetContext,
|
||||
GrPaint&& paint,
|
||||
virtual bool directFilterMaskGPU(GrTextureProvider* texProvider,
|
||||
GrDrawContext* drawContext,
|
||||
GrPaint* grp,
|
||||
const GrClip&,
|
||||
const SkMatrix& viewMatrix,
|
||||
const SkStrokeRec& strokeRec,
|
||||
const SkPath& path) const;
|
||||
/**
|
||||
* Try to directly render a rounded rect mask filter into the target. Returns
|
||||
* true if drawing was successful. If false is returned then paint is unmodified.
|
||||
* true if drawing was successful.
|
||||
*/
|
||||
virtual bool directFilterRRectMaskGPU(GrContext*,
|
||||
GrRenderTargetContext* renderTargetContext,
|
||||
GrPaint&& paint,
|
||||
GrDrawContext* drawContext,
|
||||
GrPaint* grp,
|
||||
const GrClip&,
|
||||
const SkMatrix& viewMatrix,
|
||||
const SkStrokeRec& strokeRec,
|
||||
|
@ -142,10 +139,10 @@ public:
|
|||
* Implementations are free to get the GrContext from the src texture in order to create
|
||||
* additional textures and perform multiple passes.
|
||||
*/
|
||||
virtual sk_sp<GrTextureProxy> filterMaskGPU(GrContext*,
|
||||
sk_sp<GrTextureProxy> srcProxy,
|
||||
const SkMatrix& ctm,
|
||||
const SkIRect& maskRect) const;
|
||||
virtual bool filterMaskGPU(GrTexture* src,
|
||||
const SkMatrix& ctm,
|
||||
const SkIRect& maskRect,
|
||||
GrTexture** result) const;
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,8 +21,6 @@ class SkString;
|
|||
SkMatrix does not have a constructor, so it must be explicitly initialized
|
||||
using either reset() - to construct an identity matrix, or one of the set
|
||||
functions (e.g. setTranslate, setRotate, etc.).
|
||||
|
||||
SkMatrix is not thread safe unless you've first called SkMatrix::getType().
|
||||
*/
|
||||
SK_BEGIN_REQUIRE_DENSE
|
||||
class SK_API SkMatrix {
|
||||
|
@ -463,7 +461,8 @@ public:
|
|||
|
||||
/** Like mapPoints but with custom byte stride between the points.
|
||||
*/
|
||||
void mapPointsWithStride(SkPoint dst[], const SkPoint src[], size_t stride, int count) const {
|
||||
void mapPointsWithStride(SkPoint dst[], SkPoint src[],
|
||||
size_t stride, int count) const {
|
||||
SkASSERT(stride >= sizeof(SkPoint));
|
||||
SkASSERT(0 == stride % sizeof(SkScalar));
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
@ -816,14 +815,6 @@ private:
|
|||
return ((fTypeMask & 0xF) == 0);
|
||||
}
|
||||
|
||||
inline void updateTranslateMask() {
|
||||
if ((fMat[kMTransX] != 0) | (fMat[kMTransY] != 0)) {
|
||||
fTypeMask |= kTranslate_Mask;
|
||||
} else {
|
||||
fTypeMask &= ~kTranslate_Mask;
|
||||
}
|
||||
}
|
||||
|
||||
bool SK_WARN_UNUSED_RESULT invertNonIdentity(SkMatrix* inverse) const;
|
||||
|
||||
static bool Poly2Proc(const SkPoint[], SkMatrix*, const SkPoint& scale);
|
||||
|
|
|
@ -126,12 +126,6 @@ struct SkVector4 {
|
|||
}
|
||||
};
|
||||
|
||||
/** \class SkMatrix44
|
||||
|
||||
The SkMatrix44 class holds a 4x4 matrix.
|
||||
|
||||
SkMatrix44 is not thread safe unless you've first called SkMatrix44::getType().
|
||||
*/
|
||||
class SK_API SkMatrix44 {
|
||||
public:
|
||||
|
||||
|
@ -497,10 +491,7 @@ private:
|
|||
return 0 == fTypeMask;
|
||||
}
|
||||
|
||||
inline const SkMScalar* values() const { return &fMat[0][0]; }
|
||||
|
||||
friend class SkColorSpace;
|
||||
friend class SkColorSpace_XYZ;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,5 +5,5 @@
|
|||
* found in the LICENSE file.
|
||||
*/
|
||||
#ifndef SK_MILESTONE
|
||||
#define SK_MILESTONE 59
|
||||
#define SK_MILESTONE 55
|
||||
#endif
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
|
||||
private:
|
||||
struct DrawData {
|
||||
SkCanvas* fCanvas;
|
||||
SkCanvas* fCanvas; // reffed
|
||||
const SkPicture* fPicture; // reffed
|
||||
SkMatrix fMatrix;
|
||||
SkPaint* fPaint; // owned
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* Copyright 2006 The Android Open Source Project
|
||||
*
|
||||
|
@ -20,16 +21,30 @@ enum SkFILE_Flags {
|
|||
kWrite_SkFILE_Flag = 0x02
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
const static char SkPATH_SEPARATOR = '\\';
|
||||
#else
|
||||
const static char SkPATH_SEPARATOR = '/';
|
||||
#endif
|
||||
|
||||
FILE* sk_fopen(const char path[], SkFILE_Flags);
|
||||
void sk_fclose(FILE*);
|
||||
|
||||
size_t sk_fgetsize(FILE*);
|
||||
/** Return true if the file could seek back to the beginning
|
||||
*/
|
||||
bool sk_frewind(FILE*);
|
||||
|
||||
size_t sk_fread(void* buffer, size_t byteCount, FILE*);
|
||||
size_t sk_fwrite(const void* buffer, size_t byteCount, FILE*);
|
||||
|
||||
char* sk_fgets(char* str, int size, FILE* f);
|
||||
|
||||
void sk_fflush(FILE*);
|
||||
void sk_fsync(FILE*);
|
||||
|
||||
bool sk_fseek(FILE*, size_t);
|
||||
bool sk_fmove(FILE*, long);
|
||||
size_t sk_ftell(FILE*);
|
||||
|
||||
/** Maps a file into memory. Returns the address and length on success, NULL otherwise.
|
||||
|
@ -65,9 +80,8 @@ bool sk_exists(const char *path, SkFILE_Flags = (SkFILE_Flags)0);
|
|||
// Returns true if a directory exists at this path.
|
||||
bool sk_isdir(const char *path);
|
||||
|
||||
// Like pread, but may affect the file position marker.
|
||||
// Returns the number of bytes read or SIZE_MAX if failed.
|
||||
size_t sk_qread(FILE*, void* buffer, size_t count, size_t offset);
|
||||
// Have we reached the end of the file?
|
||||
int sk_feof(FILE *);
|
||||
|
||||
|
||||
// Create a new directory at this path; returns true if successful.
|
||||
|
@ -96,4 +110,40 @@ public:
|
|||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Functions for modifying SkStrings which represent paths on the filesystem.
|
||||
*/
|
||||
class SkOSPath {
|
||||
public:
|
||||
/**
|
||||
* Assembles rootPath and relativePath into a single path, like this:
|
||||
* rootPath/relativePath.
|
||||
* It is okay to call with a NULL rootPath and/or relativePath. A path
|
||||
* separator will still be inserted.
|
||||
*
|
||||
* Uses SkPATH_SEPARATOR, to work on all platforms.
|
||||
*/
|
||||
static SkString Join(const char* rootPath, const char* relativePath);
|
||||
|
||||
/**
|
||||
* Return the name of the file, ignoring the directory structure.
|
||||
* Behaves like python's os.path.basename. If the fullPath is
|
||||
* /dir/subdir/, an empty string is returned.
|
||||
* @param fullPath Full path to the file.
|
||||
* @return SkString The basename of the file - anything beyond the
|
||||
* final slash, or the full name if there is no slash.
|
||||
*/
|
||||
static SkString Basename(const char* fullPath);
|
||||
|
||||
/**
|
||||
* Given a qualified file name returns the directory.
|
||||
* Behaves like python's os.path.dirname. If the fullPath is
|
||||
* /dir/subdir/ the return will be /dir/subdir/
|
||||
* @param fullPath Full path to the file.
|
||||
* @return SkString The dir containing the file - anything preceding the
|
||||
* final slash, or the full name if ending in a slash.
|
||||
*/
|
||||
static SkString Dirname(const char* fullPath);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -12,7 +12,9 @@
|
|||
#include "SkColor.h"
|
||||
#include "SkFilterQuality.h"
|
||||
#include "SkMatrix.h"
|
||||
#include "SkRefCnt.h"
|
||||
#include "SkXfermode.h"
|
||||
|
||||
//#define SK_SUPPORT_LEGACY_XFERMODE_OBJECT
|
||||
|
||||
class SkAutoDescriptor;
|
||||
class SkAutoGlyphCache;
|
||||
|
@ -37,6 +39,8 @@ class SkSurfaceProps;
|
|||
class SkTextBlob;
|
||||
class SkTypeface;
|
||||
|
||||
#define kBicubicFilterBitmap_Flag kHighQualityFilterBitmap_Flag
|
||||
|
||||
/** \class SkPaint
|
||||
|
||||
The SkPaint class holds the style and color information about how to draw
|
||||
|
@ -101,6 +105,8 @@ public:
|
|||
enum Flags {
|
||||
kAntiAlias_Flag = 0x01, //!< mask to enable antialiasing
|
||||
kDither_Flag = 0x04, //!< mask to enable dithering
|
||||
kUnderlineText_Flag = 0x08, //!< mask to enable underline text
|
||||
kStrikeThruText_Flag = 0x10, //!< mask to enable strike-thru text
|
||||
kFakeBoldText_Flag = 0x20, //!< mask to enable fake-bold text
|
||||
kLinearText_Flag = 0x40, //!< mask to enable linear-text
|
||||
kSubpixelText_Flag = 0x80, //!< mask to enable subpixel text positioning
|
||||
|
@ -113,18 +119,9 @@ public:
|
|||
// when adding extra flags, note that the fFlags member is specified
|
||||
// with a bit-width and you'll have to expand it.
|
||||
|
||||
kAllFlags = 0xFFFF,
|
||||
kAllFlags = 0xFFFF
|
||||
};
|
||||
|
||||
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
||||
enum ReserveFlags {
|
||||
// These are not used by paint, but the bits are reserved for private use by the
|
||||
// android framework.
|
||||
kUnderlineText_ReserveFlag = 0x08, //!< mask to enable underline text
|
||||
kStrikeThruText_ReserveFlag = 0x10, //!< mask to enable strike-thru text
|
||||
};
|
||||
#endif
|
||||
|
||||
/** Return the paint's flags. Use the Flag enum to test flag values.
|
||||
@return the paint's flags (see enums ending in _Flag for bit masks)
|
||||
*/
|
||||
|
@ -233,6 +230,32 @@ public:
|
|||
*/
|
||||
void setVerticalText(bool);
|
||||
|
||||
/** Helper for getFlags(), returning true if kUnderlineText_Flag bit is set
|
||||
@return true if the underlineText bit is set in the paint's flags.
|
||||
*/
|
||||
bool isUnderlineText() const {
|
||||
return SkToBool(this->getFlags() & kUnderlineText_Flag);
|
||||
}
|
||||
|
||||
/** Helper for setFlags(), setting or clearing the kUnderlineText_Flag bit
|
||||
@param underlineText true to set the underlineText bit in the paint's
|
||||
flags, false to clear it.
|
||||
*/
|
||||
void setUnderlineText(bool underlineText);
|
||||
|
||||
/** Helper for getFlags(), returns true if kStrikeThruText_Flag bit is set
|
||||
@return true if the strikeThruText bit is set in the paint's flags.
|
||||
*/
|
||||
bool isStrikeThruText() const {
|
||||
return SkToBool(this->getFlags() & kStrikeThruText_Flag);
|
||||
}
|
||||
|
||||
/** Helper for setFlags(), setting or clearing the kStrikeThruText_Flag bit
|
||||
@param strikeThruText true to set the strikeThruText bit in the
|
||||
paint's flags, false to clear it.
|
||||
*/
|
||||
void setStrikeThruText(bool strikeThruText);
|
||||
|
||||
/** Helper for getFlags(), returns true if kFakeBoldText_Flag bit is set
|
||||
@return true if the kFakeBoldText_Flag bit is set in the paint's flags.
|
||||
*/
|
||||
|
@ -460,7 +483,6 @@ public:
|
|||
@return the paint's shader (or NULL)
|
||||
*/
|
||||
SkShader* getShader() const { return fShader.get(); }
|
||||
sk_sp<SkShader> refShader() const;
|
||||
|
||||
/** Set or clear the shader object.
|
||||
* Shaders specify the source color(s) for what is being drawn. If a paint
|
||||
|
@ -481,24 +503,61 @@ public:
|
|||
* If a previous shader exists, its reference count is decremented.
|
||||
* If shader is not NULL, its reference count is incremented.
|
||||
* @param shader May be NULL. The shader to be installed in the paint
|
||||
* @return shader
|
||||
*/
|
||||
void setShader(sk_sp<SkShader>);
|
||||
#ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR
|
||||
SkShader* setShader(SkShader* shader);
|
||||
#endif
|
||||
|
||||
/** Get the paint's colorfilter. If there is a colorfilter, its reference
|
||||
count is not changed.
|
||||
@return the paint's colorfilter (or NULL)
|
||||
*/
|
||||
SkColorFilter* getColorFilter() const { return fColorFilter.get(); }
|
||||
sk_sp<SkColorFilter> refColorFilter() const;
|
||||
|
||||
/** Set or clear the paint's colorfilter.
|
||||
/** Set or clear the paint's colorfilter, returning the parameter.
|
||||
<p />
|
||||
If the paint already has a filter, its reference count is decremented.
|
||||
If filter is not NULL, its reference count is incremented.
|
||||
@param filter May be NULL. The filter to be installed in the paint
|
||||
@return filter
|
||||
*/
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
|
||||
SkColorFilter* setColorFilter(SkColorFilter* filter);
|
||||
#endif
|
||||
void setColorFilter(sk_sp<SkColorFilter>);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_XFERMODE_OBJECT
|
||||
/** Get the paint's xfermode object.
|
||||
<p />
|
||||
The xfermode's reference count is not affected.
|
||||
@return the paint's xfermode (or NULL)
|
||||
*/
|
||||
SkXfermode* getXfermode() const;
|
||||
|
||||
/** Set or clear the xfermode object.
|
||||
<p />
|
||||
Pass NULL to clear any previous xfermode.
|
||||
As a convenience, the parameter passed is also returned.
|
||||
If a previous xfermode exists, its reference count is decremented.
|
||||
If xfermode is not NULL, its reference count is incremented.
|
||||
@param xfermode May be NULL. The new xfermode to be installed in the
|
||||
paint
|
||||
@return xfermode
|
||||
*/
|
||||
void setXfermode(sk_sp<SkXfermode>);
|
||||
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
|
||||
SkXfermode* setXfermode(SkXfermode* xfermode);
|
||||
#endif
|
||||
|
||||
/** Create an xfermode based on the specified Mode, and assign it into the
|
||||
paint, returning the mode that was set. If the Mode is SrcOver, then
|
||||
the paint's xfermode is set to null.
|
||||
*/
|
||||
SkXfermode* setXfermodeMode(SkXfermode::Mode);
|
||||
#endif
|
||||
|
||||
SkBlendMode getBlendMode() const { return (SkBlendMode)fBlendMode; }
|
||||
bool isSrcOver() const { return (SkBlendMode)fBlendMode == SkBlendMode::kSrcOver; }
|
||||
void setBlendMode(SkBlendMode mode) { fBlendMode = (unsigned)mode; }
|
||||
|
@ -509,7 +568,6 @@ public:
|
|||
@return the paint's patheffect (or NULL)
|
||||
*/
|
||||
SkPathEffect* getPathEffect() const { return fPathEffect.get(); }
|
||||
sk_sp<SkPathEffect> refPathEffect() const;
|
||||
|
||||
/** Set or clear the patheffect object.
|
||||
<p />
|
||||
|
@ -522,6 +580,9 @@ public:
|
|||
@return effect
|
||||
*/
|
||||
void setPathEffect(sk_sp<SkPathEffect>);
|
||||
#ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
|
||||
SkPathEffect* setPathEffect(SkPathEffect* effect);
|
||||
#endif
|
||||
|
||||
/** Get the paint's maskfilter object.
|
||||
<p />
|
||||
|
@ -529,7 +590,6 @@ public:
|
|||
@return the paint's maskfilter (or NULL)
|
||||
*/
|
||||
SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); }
|
||||
sk_sp<SkMaskFilter> refMaskFilter() const;
|
||||
|
||||
/** Set or clear the maskfilter object.
|
||||
<p />
|
||||
|
@ -541,6 +601,9 @@ public:
|
|||
the paint
|
||||
@return maskfilter
|
||||
*/
|
||||
#ifdef SK_SUPPORT_LEGACY_MASKFILTER_PTR
|
||||
SkMaskFilter* setMaskFilter(SkMaskFilter* maskfilter);
|
||||
#endif
|
||||
void setMaskFilter(sk_sp<SkMaskFilter>);
|
||||
|
||||
// These attributes are for text/fonts
|
||||
|
@ -552,7 +615,6 @@ public:
|
|||
@return the paint's typeface (or NULL)
|
||||
*/
|
||||
SkTypeface* getTypeface() const { return fTypeface.get(); }
|
||||
sk_sp<SkTypeface> refTypeface() const;
|
||||
|
||||
/** Set or clear the typeface object.
|
||||
<p />
|
||||
|
@ -565,6 +627,9 @@ public:
|
|||
@return typeface
|
||||
*/
|
||||
void setTypeface(sk_sp<SkTypeface>);
|
||||
#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
|
||||
SkTypeface* setTypeface(SkTypeface* typeface);
|
||||
#endif
|
||||
|
||||
/** Get the paint's rasterizer (or NULL).
|
||||
<p />
|
||||
|
@ -572,7 +637,6 @@ public:
|
|||
@return the paint's rasterizer (or NULL)
|
||||
*/
|
||||
SkRasterizer* getRasterizer() const { return fRasterizer.get(); }
|
||||
sk_sp<SkRasterizer> refRasterizer() const;
|
||||
|
||||
/** Set or clear the rasterizer object.
|
||||
<p />
|
||||
|
@ -585,10 +649,13 @@ public:
|
|||
the paint.
|
||||
@return rasterizer
|
||||
*/
|
||||
#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
|
||||
SkRasterizer* setRasterizer(SkRasterizer* rasterizer);
|
||||
#endif
|
||||
void setRasterizer(sk_sp<SkRasterizer>);
|
||||
|
||||
SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
|
||||
sk_sp<SkImageFilter> refImageFilter() const;
|
||||
SkImageFilter* setImageFilter(SkImageFilter*);
|
||||
void setImageFilter(sk_sp<SkImageFilter>);
|
||||
|
||||
/**
|
||||
|
@ -596,8 +663,6 @@ public:
|
|||
* reference count.
|
||||
*/
|
||||
SkDrawLooper* getDrawLooper() const { return fDrawLooper.get(); }
|
||||
sk_sp<SkDrawLooper> refDrawLooper() const;
|
||||
|
||||
SkDrawLooper* getLooper() const { return fDrawLooper.get(); }
|
||||
/**
|
||||
* Set or clear the looper object.
|
||||
|
@ -609,7 +674,9 @@ public:
|
|||
* @param looper May be NULL. The new looper to be installed in the paint.
|
||||
*/
|
||||
void setDrawLooper(sk_sp<SkDrawLooper>);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
|
||||
SkDrawLooper* setLooper(SkDrawLooper* looper);
|
||||
#endif
|
||||
void setLooper(sk_sp<SkDrawLooper>);
|
||||
|
||||
enum Align {
|
||||
|
@ -688,7 +755,7 @@ public:
|
|||
A set flag indicates that the metric may be trusted.
|
||||
*/
|
||||
enum FontMetricsFlags {
|
||||
kUnderlineThicknessIsValid_Flag = 1 << 0,
|
||||
kUnderlineThinknessIsValid_Flag = 1 << 0,
|
||||
kUnderlinePositionIsValid_Flag = 1 << 1,
|
||||
};
|
||||
|
||||
|
@ -714,21 +781,21 @@ public:
|
|||
*/
|
||||
SkScalar fUnderlinePosition; //!< underline position, or 0 if cannot be determined
|
||||
|
||||
/** If the fontmetrics has a valid underline thickness, return true, and set the
|
||||
/** If the fontmetrics has a valid underlinethickness, return true, and set the
|
||||
thickness param to that value. If it doesn't return false and ignore the
|
||||
thickness param.
|
||||
*/
|
||||
bool hasUnderlineThickness(SkScalar* thickness) const {
|
||||
if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
|
||||
if (SkToBool(fFlags & kUnderlineThinknessIsValid_Flag)) {
|
||||
*thickness = fUnderlineThickness;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** If the fontmetrics has a valid underline position, return true, and set the
|
||||
position param to that value. If it doesn't return false and ignore the
|
||||
position param.
|
||||
/** If the fontmetrics has a valid underlineposition, return true, and set the
|
||||
thickness param to that value. If it doesn't return false and ignore the
|
||||
thickness param.
|
||||
*/
|
||||
bool hasUnderlinePosition(SkScalar* position) const {
|
||||
if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
|
||||
|
@ -1044,7 +1111,7 @@ private:
|
|||
SkColor fColor;
|
||||
SkScalar fWidth;
|
||||
SkScalar fMiterLimit;
|
||||
uint32_t fBlendMode; // just need 5-6 bits
|
||||
uint32_t fBlendMode; // just need 5-6 bits for SkXfermode::Mode
|
||||
union {
|
||||
struct {
|
||||
// all of these bitfields should add up to 32
|
||||
|
|
|
@ -23,8 +23,6 @@ class SkWStream;
|
|||
|
||||
The SkPath class encapsulates compound (multiple contour) geometric paths
|
||||
consisting of straight line segments, quadratic curves, and cubic curves.
|
||||
|
||||
SkPath is not thread safe unless you've first called SkPath::updateBoundsCache().
|
||||
*/
|
||||
class SK_API SkPath {
|
||||
public:
|
||||
|
@ -359,19 +357,6 @@ public:
|
|||
this->getBounds();
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a bounds that is conservatively "snug" around the path. This assumes that the
|
||||
* path will be filled. It does not attempt to collapse away contours that are logically
|
||||
* empty (e.g. moveTo(x, y) + lineTo(x, y)) but will include them in the calculation.
|
||||
*
|
||||
* It differs from getBounds() in that it will look at the snug bounds of curves, whereas
|
||||
* getBounds() just returns the bounds of the control-points. Thus computing this may be
|
||||
* slower than just calling getBounds().
|
||||
*
|
||||
* If the path is empty (i.e. no points or verbs), it will return SkRect::MakeEmpty().
|
||||
*/
|
||||
SkRect computeTightBounds() const;
|
||||
|
||||
/**
|
||||
* Does a conservative test to see whether a rectangle is inside a path. Currently it only
|
||||
* will ever return true for single convex contour paths. The empty-status of the rect is not
|
||||
|
@ -1136,12 +1121,12 @@ private:
|
|||
kCurrent_Version = 2
|
||||
};
|
||||
|
||||
sk_sp<SkPathRef> fPathRef;
|
||||
SkAutoTUnref<SkPathRef> fPathRef;
|
||||
int fLastMoveToIndex;
|
||||
uint8_t fFillType;
|
||||
mutable uint8_t fConvexity;
|
||||
mutable SkAtomic<uint8_t, sk_memory_order_relaxed> fFirstDirection;// SkPathPriv::FirstDirection
|
||||
SkBool8 fIsVolatile;
|
||||
mutable SkBool8 fIsVolatile;
|
||||
|
||||
/** Resets all fields other than fPathRef to their initial 'empty' values.
|
||||
* Assumes the caller has already emptied fPathRef.
|
||||
|
@ -1205,8 +1190,6 @@ private:
|
|||
friend class SkAutoPathBoundsUpdate;
|
||||
friend class SkAutoDisableOvalCheck;
|
||||
friend class SkAutoDisableDirectionCheck;
|
||||
friend class SkPathWriter;
|
||||
friend class SkOpBuilder;
|
||||
friend class SkBench_AddPathTest; // perf test reversePathTo
|
||||
friend class PathTest_Private; // unit test reversePathTo
|
||||
friend class ForceIsRRect_Private; // unit test isRRect
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* Copyright 2006 The Android Open Source Project
|
||||
*
|
||||
|
@ -5,6 +6,7 @@
|
|||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SkPathEffect_DEFINED
|
||||
#define SkPathEffect_DEFINED
|
||||
|
||||
|
@ -26,23 +28,6 @@ class SkStrokeRec;
|
|||
*/
|
||||
class SK_API SkPathEffect : public SkFlattenable {
|
||||
public:
|
||||
/**
|
||||
* Returns a patheffect that apples each effect (first and second) to the original path,
|
||||
* and returns a path with the sum of these.
|
||||
*
|
||||
* result = first(path) + second(path)
|
||||
*
|
||||
*/
|
||||
static sk_sp<SkPathEffect> MakeSum(sk_sp<SkPathEffect> first, sk_sp<SkPathEffect> second);
|
||||
|
||||
/**
|
||||
* Returns a patheffect that applies the inner effect to the path, and then applies the
|
||||
* outer effect to the result of the inner's.
|
||||
*
|
||||
* result = outer(inner(path))
|
||||
*/
|
||||
static sk_sp<SkPathEffect> MakeCompose(sk_sp<SkPathEffect> outer, sk_sp<SkPathEffect> inner);
|
||||
|
||||
/**
|
||||
* Given a src path (input) and a stroke-rec (input and output), apply
|
||||
* this effect to the src path, returning the new path in dst, and return
|
||||
|
@ -153,8 +138,6 @@ public:
|
|||
virtual bool exposedInAndroidJavaAPI() const { return false; }
|
||||
#endif
|
||||
|
||||
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
|
||||
|
||||
protected:
|
||||
SkPathEffect() {}
|
||||
|
||||
|
@ -166,4 +149,125 @@ private:
|
|||
typedef SkFlattenable INHERITED;
|
||||
};
|
||||
|
||||
/** \class SkPairPathEffect
|
||||
|
||||
Common baseclass for Compose and Sum. This subclass manages two pathEffects,
|
||||
including flattening them. It does nothing in filterPath, and is only useful
|
||||
for managing the lifetimes of its two arguments.
|
||||
*/
|
||||
class SK_API SkPairPathEffect : public SkPathEffect {
|
||||
protected:
|
||||
SkPairPathEffect(sk_sp<SkPathEffect> pe0, sk_sp<SkPathEffect> pe1);
|
||||
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
|
||||
// these are visible to our subclasses
|
||||
sk_sp<SkPathEffect> fPE0;
|
||||
sk_sp<SkPathEffect> fPE1;
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
|
||||
private:
|
||||
typedef SkPathEffect INHERITED;
|
||||
};
|
||||
|
||||
/** \class SkComposePathEffect
|
||||
|
||||
This subclass of SkPathEffect composes its two arguments, to create
|
||||
a compound pathEffect.
|
||||
*/
|
||||
class SK_API SkComposePathEffect : public SkPairPathEffect {
|
||||
public:
|
||||
/** Construct a pathEffect whose effect is to apply first the inner pathEffect
|
||||
and the the outer pathEffect (e.g. outer(inner(path)))
|
||||
The reference counts for outer and inner are both incremented in the constructor,
|
||||
and decremented in the destructor.
|
||||
*/
|
||||
static sk_sp<SkPathEffect> Make(sk_sp<SkPathEffect> outer, sk_sp<SkPathEffect> inner) {
|
||||
if (!outer) {
|
||||
return inner;
|
||||
}
|
||||
if (!inner) {
|
||||
return outer;
|
||||
}
|
||||
return sk_sp<SkPathEffect>(new SkComposePathEffect(outer, inner));
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
|
||||
static SkPathEffect* Create(SkPathEffect* outer, SkPathEffect* inner) {
|
||||
return Make(sk_ref_sp(outer), sk_ref_sp(inner)).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual bool filterPath(SkPath* dst, const SkPath& src,
|
||||
SkStrokeRec*, const SkRect*) const override;
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect)
|
||||
|
||||
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
||||
bool exposedInAndroidJavaAPI() const override { return true; }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
SkComposePathEffect(sk_sp<SkPathEffect> outer, sk_sp<SkPathEffect> inner)
|
||||
: INHERITED(outer, inner) {}
|
||||
|
||||
private:
|
||||
// illegal
|
||||
SkComposePathEffect(const SkComposePathEffect&);
|
||||
SkComposePathEffect& operator=(const SkComposePathEffect&);
|
||||
|
||||
typedef SkPairPathEffect INHERITED;
|
||||
};
|
||||
|
||||
/** \class SkSumPathEffect
|
||||
|
||||
This subclass of SkPathEffect applies two pathEffects, one after the other.
|
||||
Its filterPath() returns true if either of the effects succeeded.
|
||||
*/
|
||||
class SK_API SkSumPathEffect : public SkPairPathEffect {
|
||||
public:
|
||||
/** Construct a pathEffect whose effect is to apply two effects, in sequence.
|
||||
(e.g. first(path) + second(path))
|
||||
The reference counts for first and second are both incremented in the constructor,
|
||||
and decremented in the destructor.
|
||||
*/
|
||||
static sk_sp<SkPathEffect> Make(sk_sp<SkPathEffect> first, sk_sp<SkPathEffect> second) {
|
||||
if (!first) {
|
||||
return second;
|
||||
}
|
||||
if (!second) {
|
||||
return first;
|
||||
}
|
||||
return sk_sp<SkPathEffect>(new SkSumPathEffect(first, second));
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
|
||||
static SkPathEffect* Create(SkPathEffect* first, SkPathEffect* second) {
|
||||
return Make(sk_ref_sp(first), sk_ref_sp(second)).release();
|
||||
}
|
||||
#endif
|
||||
virtual bool filterPath(SkPath* dst, const SkPath& src,
|
||||
SkStrokeRec*, const SkRect*) const override;
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect)
|
||||
|
||||
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
||||
bool exposedInAndroidJavaAPI() const override { return true; }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
SkSumPathEffect(sk_sp<SkPathEffect> first, sk_sp<SkPathEffect> second)
|
||||
: INHERITED(first, second) {}
|
||||
|
||||
private:
|
||||
// illegal
|
||||
SkSumPathEffect(const SkSumPathEffect&);
|
||||
SkSumPathEffect& operator=(const SkSumPathEffect&);
|
||||
|
||||
typedef SkPairPathEffect INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,8 +26,8 @@ class SkWBuffer;
|
|||
* modify the contents. To modify or append to the verbs/points wrap the SkPathRef in an
|
||||
* SkPathRef::Editor object. Installing the editor resets the generation ID. It also performs
|
||||
* copy-on-write if the SkPathRef is shared by multiple SkPaths. The caller passes the Editor's
|
||||
* constructor a pointer to a sk_sp<SkPathRef>, which may be updated to point to a new SkPathRef
|
||||
* after the editor's constructor returns.
|
||||
* constructor a SkAutoTUnref, which may be updated to point to a new SkPathRef after the editor's
|
||||
* constructor returns.
|
||||
*
|
||||
* The points and verbs are stored in a single allocation. The points are at the begining of the
|
||||
* allocation while the verbs are stored at end of the allocation, in reverse order. Thus the points
|
||||
|
@ -40,7 +40,7 @@ class SK_API SkPathRef final : public SkNVRefCnt<SkPathRef> {
|
|||
public:
|
||||
class Editor {
|
||||
public:
|
||||
Editor(sk_sp<SkPathRef>* pathRef,
|
||||
Editor(SkAutoTUnref<SkPathRef>* pathRef,
|
||||
int incReserveVerbs = 0,
|
||||
int incReservePoints = 0);
|
||||
|
||||
|
@ -230,7 +230,7 @@ public:
|
|||
/**
|
||||
* Transforms a path ref by a matrix, allocating a new one only if necessary.
|
||||
*/
|
||||
static void CreateTransformedCopy(sk_sp<SkPathRef>* dst,
|
||||
static void CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst,
|
||||
const SkPathRef& src,
|
||||
const SkMatrix& matrix);
|
||||
|
||||
|
@ -241,7 +241,7 @@ public:
|
|||
* repopulated with approximately the same number of verbs and points. A new path ref is created
|
||||
* only if necessary.
|
||||
*/
|
||||
static void Rewind(sk_sp<SkPathRef>* pathRef);
|
||||
static void Rewind(SkAutoTUnref<SkPathRef>* pathRef);
|
||||
|
||||
~SkPathRef();
|
||||
int countPoints() const { SkDEBUGCODE(this->validate();) return fPointCnt; }
|
||||
|
|
|
@ -52,6 +52,21 @@ public:
|
|||
*/
|
||||
typedef bool (*InstallPixelRefProc)(const void* src, size_t length, SkBitmap* dst);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PICTUREINSTALLPIXELREF
|
||||
/**
|
||||
* Recreate a picture that was serialized into a stream.
|
||||
* @param SkStream Serialized picture data. Ownership is unchanged by this call.
|
||||
* @param proc Function pointer for installing pixelrefs on SkBitmaps representing the
|
||||
* encoded bitmap data from the stream.
|
||||
* @return A new SkPicture representing the serialized data, or NULL if the stream is
|
||||
* invalid.
|
||||
*/
|
||||
static sk_sp<SkPicture> MakeFromStream(SkStream*, InstallPixelRefProc proc);
|
||||
static sk_sp<SkPicture> MakeFromStream(SkStream* stream, std::nullptr_t) {
|
||||
return MakeFromStream(stream);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Recreate a picture that was serialized into a stream.
|
||||
*
|
||||
|
@ -167,6 +182,18 @@ public:
|
|||
static void SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set);
|
||||
static bool PictureIOSecurityPrecautionsEnabled();
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PICTURE_PTR
|
||||
static SkPicture* CreateFromStream(SkStream* stream, InstallPixelRefProc proc) {
|
||||
return MakeFromStream(stream, proc).release();
|
||||
}
|
||||
static SkPicture* CreateFromStream(SkStream* stream) {
|
||||
return MakeFromStream(stream).release();
|
||||
}
|
||||
static SkPicture* CreateFromBuffer(SkReadBuffer& rbuf) {
|
||||
return MakeFromBuffer(rbuf).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
// Subclass whitelist.
|
||||
SkPicture();
|
||||
|
@ -198,12 +225,10 @@ private:
|
|||
// V48: Read and write extended SkTextBlobs.
|
||||
// V49: Gradients serialized as SkColor4f + SkColorSpace
|
||||
// V50: SkXfermode -> SkBlendMode
|
||||
// V51: more SkXfermode -> SkBlendMode
|
||||
// V52: Remove SkTextBlob::fRunCount
|
||||
|
||||
// Only SKPs within the min/current picture version range (inclusive) can be read.
|
||||
static const uint32_t MIN_PICTURE_VERSION = 35; // Produced by Chrome M39.
|
||||
static const uint32_t CURRENT_PICTURE_VERSION = 52;
|
||||
static const uint32_t CURRENT_PICTURE_VERSION = 50;
|
||||
|
||||
static_assert(MIN_PICTURE_VERSION <= 41,
|
||||
"Remove kFontFileName and related code from SkFontDescriptor.cpp.");
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
/**
|
||||
* Process an explicit clipPath op.
|
||||
*/
|
||||
void analyzeClipPath(const SkPath&, SkClipOp, bool doAntiAlias);
|
||||
void analyzeClipPath(const SkPath&, SkCanvas::ClipOp, bool doAntiAlias);
|
||||
|
||||
/**
|
||||
* Reset all accumulated stats.
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
};
|
||||
|
||||
enum FinishFlags {
|
||||
kReturnNullForEmpty_FinishFlag = 1 << 0, // no draw-ops will return nullptr
|
||||
};
|
||||
|
||||
/** Returns the canvas that records the drawing commands.
|
||||
|
@ -77,7 +78,7 @@ public:
|
|||
/**
|
||||
* Signal that the caller is done recording, and update the cull rect to use for bounding
|
||||
* box hierarchy (BBH) generation. The behavior is the same as calling
|
||||
* finishRecordingAsPicture(), except that this method updates the cull rect initially passed
|
||||
* endRecordingAsPicture(), except that this method updates the cull rect initially passed
|
||||
* into beginRecording.
|
||||
* @param cullRect the new culling rectangle to use as the overall bound for BBH generation
|
||||
* and subsequent culling operations.
|
||||
|
@ -91,13 +92,26 @@ public:
|
|||
* beginRecording/getRecordingCanvas. Ownership of the object is passed to the caller, who
|
||||
* must call unref() when they are done using it.
|
||||
*
|
||||
* Unlike finishRecordingAsPicture(), which returns an immutable picture, the returned drawable
|
||||
* Unlike endRecordingAsPicture(), which returns an immutable picture, the returned drawable
|
||||
* may contain live references to other drawables (if they were added to the recording canvas)
|
||||
* and therefore this drawable will reflect the current state of those nested drawables anytime
|
||||
* it is drawn or a new picture is snapped from it (by calling drawable->newPictureSnapshot()).
|
||||
*/
|
||||
sk_sp<SkDrawable> finishRecordingAsDrawable(uint32_t endFlags = 0);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PICTURE_PTR
|
||||
SkPicture* SK_WARN_UNUSED_RESULT endRecordingAsPicture() {
|
||||
return this->finishRecordingAsPicture().release();
|
||||
}
|
||||
SkPicture* SK_WARN_UNUSED_RESULT endRecordingAsPicture(const SkRect& cullRect) {
|
||||
return this->finishRecordingAsPictureWithCull(cullRect).release();
|
||||
}
|
||||
SkDrawable* SK_WARN_UNUSED_RESULT endRecordingAsDrawable() {
|
||||
return this->finishRecordingAsDrawable().release();
|
||||
}
|
||||
SkPicture* SK_WARN_UNUSED_RESULT endRecording() { return this->endRecordingAsPicture(); }
|
||||
#endif
|
||||
|
||||
private:
|
||||
void reset();
|
||||
|
||||
|
@ -110,13 +124,13 @@ private:
|
|||
friend class SkPictureRecorderReplayTester; // for unit testing
|
||||
void partialReplay(SkCanvas* canvas) const;
|
||||
|
||||
bool fActivelyRecording;
|
||||
uint32_t fFlags;
|
||||
SkRect fCullRect;
|
||||
sk_sp<SkBBoxHierarchy> fBBH;
|
||||
std::unique_ptr<SkRecorder> fRecorder;
|
||||
sk_sp<SkRecord> fRecord;
|
||||
SkMiniRecorder fMiniRecorder;
|
||||
bool fActivelyRecording;
|
||||
uint32_t fFlags;
|
||||
SkRect fCullRect;
|
||||
SkAutoTUnref<SkBBoxHierarchy> fBBH;
|
||||
SkAutoTUnref<SkRecorder> fRecorder;
|
||||
SkAutoTUnref<SkRecord> fRecord;
|
||||
SkMiniRecorder fMiniRecorder;
|
||||
|
||||
typedef SkNoncopyable INHERITED;
|
||||
};
|
||||
|
|
|
@ -18,8 +18,10 @@
|
|||
#include "SkRefCnt.h"
|
||||
#include "SkSize.h"
|
||||
#include "SkString.h"
|
||||
#include "SkYUVSizeInfo.h"
|
||||
|
||||
class SkColorTable;
|
||||
class SkData;
|
||||
struct SkIRect;
|
||||
|
||||
class GrTexture;
|
||||
|
@ -35,11 +37,7 @@ class SkDiscardableMemory;
|
|||
*/
|
||||
class SK_API SkPixelRef : public SkRefCnt {
|
||||
public:
|
||||
#ifdef SK_SUPPORT_LEGACY_NO_ADDR_PIXELREF
|
||||
explicit SkPixelRef(const SkImageInfo&);
|
||||
#endif
|
||||
explicit SkPixelRef(const SkImageInfo&, void* addr, size_t rowBytes,
|
||||
sk_sp<SkColorTable> = nullptr);
|
||||
virtual ~SkPixelRef();
|
||||
|
||||
const SkImageInfo& info() const {
|
||||
|
@ -98,6 +96,14 @@ public:
|
|||
*/
|
||||
void unlockPixels();
|
||||
|
||||
/**
|
||||
* Some bitmaps can return a copy of their pixels for lockPixels(), but
|
||||
* that copy, if modified, will not be pushed back. These bitmaps should
|
||||
* not be used as targets for a raster device/canvas (since all pixels
|
||||
* modifications will be lost when unlockPixels() is called.)
|
||||
*/
|
||||
bool lockPixelsAreWritable() const;
|
||||
|
||||
/** Returns a non-zero, unique value corresponding to the pixels in this
|
||||
pixelref. Each time the pixels are changed (and notifyPixelsChanged is
|
||||
called), a different generation ID will be returned.
|
||||
|
@ -141,6 +147,39 @@ public:
|
|||
*/
|
||||
void setImmutable();
|
||||
|
||||
/** Return the optional URI string associated with this pixelref. May be
|
||||
null.
|
||||
*/
|
||||
const char* getURI() const { return fURI.size() ? fURI.c_str() : NULL; }
|
||||
|
||||
/** Copy a URI string to this pixelref, or clear the URI if the uri is null
|
||||
*/
|
||||
void setURI(const char uri[]) {
|
||||
fURI.set(uri);
|
||||
}
|
||||
|
||||
/** Copy a URI string to this pixelref
|
||||
*/
|
||||
void setURI(const char uri[], size_t len) {
|
||||
fURI.set(uri, len);
|
||||
}
|
||||
|
||||
/** Assign a URI string to this pixelref.
|
||||
*/
|
||||
void setURI(const SkString& uri) { fURI = uri; }
|
||||
|
||||
/**
|
||||
* If the pixelRef has an encoded (i.e. compressed) representation,
|
||||
* return a ref to its data. If the pixelRef
|
||||
* is uncompressed or otherwise does not have this form, return NULL.
|
||||
*
|
||||
* If non-null is returned, the caller is responsible for calling unref()
|
||||
* on the data when it is finished.
|
||||
*/
|
||||
SkData* refEncodedData() {
|
||||
return this->onRefEncodedData();
|
||||
}
|
||||
|
||||
struct LockRequest {
|
||||
SkISize fSize;
|
||||
SkFilterQuality fQuality;
|
||||
|
@ -167,6 +206,34 @@ public:
|
|||
|
||||
bool requestLock(const LockRequest&, LockResult*);
|
||||
|
||||
/**
|
||||
* If this can efficiently return YUV data, this should return true.
|
||||
* Otherwise this returns false and does not modify any of the parameters.
|
||||
*
|
||||
* @param sizeInfo Output parameter indicating the sizes and required
|
||||
* allocation widths of the Y, U, and V planes.
|
||||
* @param colorSpace Output parameter.
|
||||
*/
|
||||
bool queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const {
|
||||
return this->onQueryYUV8(sizeInfo, colorSpace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true on success and false on failure.
|
||||
* Copies YUV data into the provided YUV planes.
|
||||
*
|
||||
* @param sizeInfo Needs to exactly match the values returned by the
|
||||
* query, except the WidthBytes may be larger than the
|
||||
* recommendation (but not smaller).
|
||||
* @param planes Memory for each of the Y, U, and V planes.
|
||||
*/
|
||||
bool getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) {
|
||||
return this->onGetYUV8Planes(sizeInfo, planes);
|
||||
}
|
||||
|
||||
/** Populates dst with the pixels of this pixelRef, converting them to colorType. */
|
||||
bool readPixels(SkBitmap* dst, SkColorType colorType, const SkIRect* subset = NULL);
|
||||
|
||||
// Register a listener that may be called the next time our generation ID changes.
|
||||
//
|
||||
// We'll only call the listener if we're confident that we are the only SkPixelRef with this
|
||||
|
@ -191,10 +258,12 @@ public:
|
|||
|
||||
virtual SkDiscardableMemory* diagnostic_only_getDiscardable() const { return NULL; }
|
||||
|
||||
/**
|
||||
* Returns true if the pixels are generated on-the-fly (when required).
|
||||
*/
|
||||
bool isLazyGenerated() const { return this->onIsLazyGenerated(); }
|
||||
|
||||
protected:
|
||||
#ifdef SK_SUPPORT_LEGACY_NO_ADDR_PIXELREF
|
||||
virtual
|
||||
#endif
|
||||
/**
|
||||
* On success, returns true and fills out the LockRec for the pixels. On
|
||||
* failure returns false and ignores the LockRec parameter.
|
||||
|
@ -202,14 +271,8 @@ protected:
|
|||
* The caller will have already acquired a mutex for thread safety, so this
|
||||
* method need not do that.
|
||||
*/
|
||||
bool onNewLockPixels(LockRec*) {
|
||||
SkASSERT(false); // should never be called
|
||||
return true;
|
||||
}
|
||||
virtual bool onNewLockPixels(LockRec*) = 0;
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_NO_ADDR_PIXELREF
|
||||
virtual
|
||||
#endif
|
||||
/**
|
||||
* Balancing the previous successful call to onNewLockPixels. The locked
|
||||
* pixel address will no longer be referenced, so the subclass is free to
|
||||
|
@ -218,13 +281,32 @@ protected:
|
|||
* The caller will have already acquired a mutex for thread safety, so this
|
||||
* method need not do that.
|
||||
*/
|
||||
void onUnlockPixels() {
|
||||
SkASSERT(false); // should never be called
|
||||
}
|
||||
virtual void onUnlockPixels() = 0;
|
||||
|
||||
/** Default impl returns true */
|
||||
virtual bool onLockPixelsAreWritable() const;
|
||||
|
||||
/**
|
||||
* For pixelrefs that don't have access to their raw pixels, they may be
|
||||
* able to make a copy of them (e.g. if the pixels are on the GPU).
|
||||
*
|
||||
* The base class implementation returns false;
|
||||
*/
|
||||
virtual bool onReadPixels(SkBitmap* dst, SkColorType colorType, const SkIRect* subsetOrNull);
|
||||
|
||||
// default impl returns NULL.
|
||||
virtual SkData* onRefEncodedData();
|
||||
|
||||
// default impl does nothing.
|
||||
virtual void onNotifyPixelsChanged();
|
||||
|
||||
virtual bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const {
|
||||
return false;
|
||||
}
|
||||
virtual bool onGetYUV8Planes(const SkYUVSizeInfo&, void*[3] /*planes*/) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size (in bytes) of the internally allocated memory.
|
||||
* This should be implemented in all serializable SkPixelRef derived classes.
|
||||
|
@ -235,36 +317,31 @@ protected:
|
|||
*/
|
||||
virtual size_t getAllocatedSizeInBytes() const;
|
||||
|
||||
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
||||
// This is undefined if there are clients in-flight trying to use us
|
||||
void android_only_reset(const SkImageInfo&, size_t rowBytes, sk_sp<SkColorTable>);
|
||||
#endif
|
||||
virtual bool onRequestLock(const LockRequest&, LockResult*);
|
||||
|
||||
virtual bool onIsLazyGenerated() const { return false; }
|
||||
|
||||
/** Return the mutex associated with this pixelref. This value is assigned
|
||||
in the constructor, and cannot change during the lifetime of the object.
|
||||
*/
|
||||
SkBaseMutex* mutex() const { return &fMutex; }
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_NO_ADDR_PIXELREF
|
||||
// only call from constructor. Flags this to always be locked, removing
|
||||
// the need to grab the mutex and call onLockPixels/onUnlockPixels.
|
||||
// Performance tweak to avoid those calls (esp. in multi-thread use case).
|
||||
void setPreLocked(void*, size_t rowBytes, SkColorTable*);
|
||||
#endif
|
||||
|
||||
private:
|
||||
mutable SkMutex fMutex;
|
||||
|
||||
// mostly const. fInfo.fAlpahType can be changed at runtime.
|
||||
const SkImageInfo fInfo;
|
||||
sk_sp<SkColorTable> fCTable; // duplicated in LockRec, will unify later
|
||||
|
||||
// LockRec is only valid if we're in a locked state (isLocked())
|
||||
LockRec fRec;
|
||||
int fLockCount;
|
||||
|
||||
bool lockPixelsInsideMutex();
|
||||
bool internalRequestLock(const LockRequest&, LockResult*);
|
||||
|
||||
// Bottom bit indicates the Gen ID is unique.
|
||||
bool genIDIsUnique() const { return SkToBool(fTaggedGenID.load() & 1); }
|
||||
|
@ -276,6 +353,8 @@ private:
|
|||
|
||||
SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owned
|
||||
|
||||
SkString fURI;
|
||||
|
||||
// Set true by caches when they cache content that's derived from the current pixels.
|
||||
SkAtomic<bool> fAddedToCache;
|
||||
|
||||
|
@ -308,9 +387,19 @@ private:
|
|||
friend class SkImage_Gpu;
|
||||
friend class SkImageCacherator;
|
||||
friend class SkSpecialImage_Gpu;
|
||||
friend void SkBitmapCache_setImmutableWithID(SkPixelRef*, uint32_t);
|
||||
|
||||
typedef SkRefCnt INHERITED;
|
||||
};
|
||||
|
||||
class SkPixelRefFactory : public SkRefCnt {
|
||||
public:
|
||||
/**
|
||||
* Allocate a new pixelref matching the specified ImageInfo, allocating
|
||||
* the memory for the pixels. If the ImageInfo requires a ColorTable,
|
||||
* the pixelref will ref() the colortable.
|
||||
* On failure return NULL.
|
||||
*/
|
||||
virtual SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable*) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -70,7 +70,6 @@ public:
|
|||
int height() const { return fInfo.height(); }
|
||||
SkColorType colorType() const { return fInfo.colorType(); }
|
||||
SkAlphaType alphaType() const { return fInfo.alphaType(); }
|
||||
SkColorSpace* colorSpace() const { return fInfo.colorSpace(); }
|
||||
bool isOpaque() const { return fInfo.isOpaque(); }
|
||||
|
||||
SkIRect bounds() const { return SkIRect::MakeWH(this->width(), this->height()); }
|
||||
|
@ -90,22 +89,6 @@ public:
|
|||
uint64_t getSafeSize64() const { return fInfo.getSafeSize64(fRowBytes); }
|
||||
size_t getSafeSize() const { return fInfo.getSafeSize(fRowBytes); }
|
||||
|
||||
/**
|
||||
* This will brute-force return true if all of the pixels in the pixmap
|
||||
* are opaque. If there are no pixels, or encounters an error, returns false.
|
||||
*/
|
||||
bool computeIsOpaque() const;
|
||||
|
||||
/**
|
||||
* Converts the pixel at the specified coordinate to an unpremultiplied
|
||||
* SkColor. Note: this ignores any SkColorSpace information, and may return
|
||||
* lower precision data than is actually in the pixel. Alpha only
|
||||
* colortypes (e.g. kAlpha_8_SkColorType) return black with the appropriate
|
||||
* alpha set. The value is undefined for kUnknown_SkColorType or if x or y
|
||||
* are out of bounds, or if the pixtap does not have any pixels.
|
||||
*/
|
||||
SkColor getColor(int x, int y) const;
|
||||
|
||||
const void* addr(int x, int y) const {
|
||||
return (const char*)fPixels + fInfo.computeOffset(x, y, fRowBytes);
|
||||
}
|
||||
|
|
|
@ -77,6 +77,15 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
// As usual, there are two ways to increase alignment... the MSVC way and the everyone-else way.
|
||||
#ifndef SK_STRUCT_ALIGN
|
||||
#ifdef _MSC_VER
|
||||
#define SK_STRUCT_ALIGN(N) __declspec(align(N))
|
||||
#else
|
||||
#define SK_STRUCT_ALIGN(N) __attribute__((aligned(N)))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
|
||||
#define SK_VECTORCALL __vectorcall
|
||||
#elif defined(SK_CPU_ARM32) && defined(SK_ARM_HAS_NEON)
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
defined(__s390__) || \
|
||||
(defined(__sh__) && defined(__BIG_ENDIAN__)) || \
|
||||
(defined(__ia64) && defined(__BIG_ENDIAN__))
|
||||
#define SK_CPU_BENDIAN
|
||||
#define SK_CPU_BENDIAN
|
||||
#else
|
||||
#define SK_CPU_LENDIAN
|
||||
#endif
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
#ifndef SkRSXform_DEFINED
|
||||
#define SkRSXform_DEFINED
|
||||
|
||||
#include "SkPoint.h"
|
||||
#include "SkSize.h"
|
||||
#include "SkScalar.h"
|
||||
|
||||
/**
|
||||
* A compressed form of a rotation+scale matrix.
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* Copyright 2016 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkRasterHandleAllocator_DEFINED
|
||||
#define SkRasterHandleAllocator_DEFINED
|
||||
|
||||
#include "SkImageInfo.h"
|
||||
|
||||
class SkBitmap;
|
||||
class SkCanvas;
|
||||
class SkMatrix;
|
||||
|
||||
/**
|
||||
* If a client wants to control the allocation of raster layers in a canvas, it should subclass
|
||||
* SkRasterHandleAllocator. This allocator performs two tasks:
|
||||
* 1. controls how the memory for the pixels is allocated
|
||||
* 2. associates a "handle" to a private object that can track the matrix/clip of the SkCanvas
|
||||
*
|
||||
* This example allocates a canvas, and defers to the allocator to create the base layer.
|
||||
*
|
||||
* std::unique_ptr<SkCanvas> canvas = SkRasterHandleAllocator::MakeCanvas(
|
||||
* SkImageInfo::Make(...),
|
||||
* skstd::make_unique<MySubclassRasterHandleAllocator>(...),
|
||||
* nullptr);
|
||||
*
|
||||
* If you have already allocated the base layer (and its handle, release-proc etc.) then you
|
||||
* can pass those in using the last parameter to MakeCanvas().
|
||||
*
|
||||
* Regardless of how the base layer is allocated, each time canvas->saveLayer() is called,
|
||||
* your allocator's allocHandle() will be called.
|
||||
*/
|
||||
class SK_API SkRasterHandleAllocator {
|
||||
public:
|
||||
virtual ~SkRasterHandleAllocator() {}
|
||||
|
||||
// The value that is returned to clients of the canvas that has this allocator installed.
|
||||
typedef void* Handle;
|
||||
|
||||
struct Rec {
|
||||
// When the allocation goes out of scope, this proc is called to free everything associated
|
||||
// with it: the pixels, the "handle", etc. This is passed the pixel address and fReleaseCtx.
|
||||
void (*fReleaseProc)(void* pixels, void* ctx);
|
||||
void* fReleaseCtx; // context passed to fReleaseProc
|
||||
void* fPixels; // pixels for this allocation
|
||||
size_t fRowBytes; // rowbytes for these pixels
|
||||
Handle fHandle; // public handle returned by SkCanvas::accessTopRasterHandle()
|
||||
};
|
||||
|
||||
/**
|
||||
* Given a requested info, allocate the corresponding pixels/rowbytes, and whatever handle
|
||||
* is desired to give clients access to those pixels. The rec also contains a proc and context
|
||||
* which will be called when this allocation goes out of scope.
|
||||
*
|
||||
* e.g.
|
||||
* when canvas->saveLayer() is called, the allocator will be called to allocate the pixels
|
||||
* for the layer. When canvas->restore() is called, the fReleaseProc will be called.
|
||||
*/
|
||||
virtual bool allocHandle(const SkImageInfo&, Rec*) = 0;
|
||||
|
||||
/**
|
||||
* Clients access the handle for a given layer by calling SkCanvas::accessTopRasterHandle().
|
||||
* To allow the handle to reflect the current matrix/clip in the canvs, updateHandle() is
|
||||
* is called. The subclass is responsible to update the handle as it sees fit.
|
||||
*/
|
||||
virtual void updateHandle(Handle, const SkMatrix&, const SkIRect&) = 0;
|
||||
|
||||
/**
|
||||
* This creates a canvas which will use the allocator to manage pixel allocations, including
|
||||
* all calls to saveLayer().
|
||||
*
|
||||
* If rec is non-null, then it will be used as the base-layer of pixels/handle.
|
||||
* If rec is null, then the allocator will be called for the base-layer as well.
|
||||
*/
|
||||
static std::unique_ptr<SkCanvas> MakeCanvas(std::unique_ptr<SkRasterHandleAllocator>,
|
||||
const SkImageInfo&, const Rec* rec = nullptr);
|
||||
|
||||
private:
|
||||
friend class SkBitmapDevice;
|
||||
|
||||
Handle allocBitmap(const SkImageInfo&, SkBitmap*);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -280,7 +280,7 @@ struct SK_API SkIRect {
|
|||
intersection, otherwise return false and do not change this rectangle.
|
||||
If either rectangle is empty, do nothing and return false.
|
||||
*/
|
||||
bool intersect(const SkIRect& r) {
|
||||
bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& r) {
|
||||
return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom);
|
||||
}
|
||||
|
||||
|
@ -327,7 +327,8 @@ struct SK_API SkIRect {
|
|||
otherwise return false and do not change this rectangle.
|
||||
If either rectangle is empty, do nothing and return false.
|
||||
*/
|
||||
bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom) {
|
||||
bool SK_WARN_UNUSED_RESULT intersect(int32_t left, int32_t top,
|
||||
int32_t right, int32_t bottom) {
|
||||
if (left < right && top < bottom && !this->isEmpty() &&
|
||||
fLeft < right && left < fRight && fTop < bottom && top < fBottom) {
|
||||
if (fLeft < left) fLeft = left;
|
||||
|
@ -675,14 +676,15 @@ struct SK_API SkRect {
|
|||
intersection, otherwise return false and do not change this rectangle.
|
||||
If either rectangle is empty, do nothing and return false.
|
||||
*/
|
||||
bool intersect(const SkRect& r);
|
||||
bool SK_WARN_UNUSED_RESULT intersect(const SkRect& r);
|
||||
|
||||
/** If this rectangle intersects the rectangle specified by left, top, right, bottom,
|
||||
return true and set this rectangle to that intersection, otherwise return false
|
||||
and do not change this rectangle.
|
||||
If either rectangle is empty, do nothing and return false.
|
||||
*/
|
||||
bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom);
|
||||
bool SK_WARN_UNUSED_RESULT intersect(SkScalar left, SkScalar top,
|
||||
SkScalar right, SkScalar bottom);
|
||||
|
||||
/**
|
||||
* If rectangles a and b intersect, return true and set this rectangle to
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#define SK_SUPPORT_TRANSITION_TO_SP_INTERFACES
|
||||
|
||||
/** \class SkRefCntBase
|
||||
|
||||
SkRefCntBase is the base class for objects that may be shared by multiple
|
||||
|
@ -69,7 +71,15 @@ public:
|
|||
/** Increment the reference count. Must be balanced by a call to unref().
|
||||
*/
|
||||
void ref() const {
|
||||
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
||||
// Android employs some special subclasses that enable the fRefCnt to
|
||||
// go to zero, but not below, prior to reusing the object. This breaks
|
||||
// the use of unique() on such objects and as such should be removed
|
||||
// once the Android code is fixed.
|
||||
SkASSERT(getRefCnt() >= 0);
|
||||
#else
|
||||
SkASSERT(getRefCnt() > 0);
|
||||
#endif
|
||||
// No barrier required.
|
||||
(void)fRefCnt.fetch_add(+1, std::memory_order_relaxed);
|
||||
}
|
||||
|
@ -137,28 +147,6 @@ class SK_API SkRefCnt : public SkRefCntBase {
|
|||
null in on each side of the assignment, and ensuring that ref() is called
|
||||
before unref(), in case the two pointers point to the same object.
|
||||
*/
|
||||
|
||||
#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
|
||||
// This version heuristically detects data races, since those otherwise result
|
||||
// in redundant reference count decrements, which are exceedingly
|
||||
// difficult to debug.
|
||||
|
||||
#define SkRefCnt_SafeAssign(dst, src) \
|
||||
do { \
|
||||
typedef typename std::remove_reference<decltype(dst)>::type \
|
||||
SkRefCntPtrT; \
|
||||
SkRefCntPtrT old_dst = *const_cast<SkRefCntPtrT volatile *>(&dst); \
|
||||
if (src) src->ref(); \
|
||||
if (old_dst) old_dst->unref(); \
|
||||
if (old_dst != *const_cast<SkRefCntPtrT volatile *>(&dst)) { \
|
||||
SkDebugf("Detected racing Skia calls at %s:%d\n", \
|
||||
__FILE__, __LINE__); \
|
||||
} \
|
||||
dst = src; \
|
||||
} while (0)
|
||||
|
||||
#else /* !SK_BUILD_FOR_ANDROID_FRAMEWORK */
|
||||
|
||||
#define SkRefCnt_SafeAssign(dst, src) \
|
||||
do { \
|
||||
if (src) src->ref(); \
|
||||
|
@ -166,8 +154,6 @@ class SK_API SkRefCnt : public SkRefCntBase {
|
|||
dst = src; \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/** Call obj->ref() and return obj. The obj must not be nullptr.
|
||||
*/
|
||||
|
@ -203,6 +189,32 @@ template<typename T> static inline void SkSafeSetNull(T*& obj) {
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <typename T> struct SkTUnref {
|
||||
void operator()(T* t) { t->unref(); }
|
||||
};
|
||||
|
||||
/**
|
||||
* Utility class that simply unref's its argument in the destructor.
|
||||
*/
|
||||
template <typename T> class SkAutoTUnref : public std::unique_ptr<T, SkTUnref<T>> {
|
||||
public:
|
||||
explicit SkAutoTUnref(T* obj = nullptr) : std::unique_ptr<T, SkTUnref<T>>(obj) {}
|
||||
|
||||
operator T*() const { return this->get(); }
|
||||
|
||||
#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
|
||||
// Need to update graphics/Shader.cpp.
|
||||
T* detach() { return this->release(); }
|
||||
#endif
|
||||
};
|
||||
// Can't use the #define trick below to guard a bare SkAutoTUnref(...) because it's templated. :(
|
||||
|
||||
class SkAutoUnref : public SkAutoTUnref<SkRefCnt> {
|
||||
public:
|
||||
SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {}
|
||||
};
|
||||
#define SkAutoUnref(...) SK_REQUIRE_LOCAL_VAR(SkAutoUnref)
|
||||
|
||||
// This is a variant of SkRefCnt that's Not Virtual, so weighs 4 bytes instead of 8 or 16.
|
||||
// There's only benefit to using this if the deriving class does not otherwise need a vtable.
|
||||
template <typename Derived>
|
||||
|
@ -435,14 +447,20 @@ sk_sp<T> sk_make_sp(Args&&... args) {
|
|||
return sk_sp<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_TRANSITION_TO_SP_INTERFACES
|
||||
|
||||
/*
|
||||
* Returns a sk_sp wrapping the provided ptr AND calls ref on it (if not null).
|
||||
*
|
||||
* This is different than the semantics of the constructor for sk_sp, which just wraps the ptr,
|
||||
* effectively "adopting" it.
|
||||
*
|
||||
* This function may be helpful while we convert callers from ptr-based to sk_sp-based parameters.
|
||||
*/
|
||||
template <typename T> sk_sp<T> sk_ref_sp(T* obj) {
|
||||
return sk_sp<T>(SkSafeRef(obj));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -436,8 +436,6 @@ private:
|
|||
|
||||
int count_runtype_values(int* itop, int* ibot) const;
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
static void BuildRectRuns(const SkIRect& bounds,
|
||||
RunType runs[kRectRegionRuns]);
|
||||
|
||||
|
|
|
@ -10,9 +10,14 @@
|
|||
|
||||
#include "../private/SkFloatingPoint.h"
|
||||
|
||||
// TODO: move this sort of check into SkPostConfig.h
|
||||
#define SK_SCALAR_IS_DOUBLE 0
|
||||
#undef SK_SCALAR_IS_FLOAT
|
||||
#define SK_SCALAR_IS_FLOAT 1
|
||||
|
||||
|
||||
#if SK_SCALAR_IS_FLOAT
|
||||
|
||||
typedef float SkScalar;
|
||||
|
||||
#define SK_Scalar1 1.0f
|
||||
|
@ -51,6 +56,48 @@ typedef float SkScalar;
|
|||
#define SkScalarLog(x) (float)sk_float_log(x)
|
||||
#define SkScalarLog2(x) (float)sk_float_log2(x)
|
||||
|
||||
#else // SK_SCALAR_IS_DOUBLE
|
||||
|
||||
typedef double SkScalar;
|
||||
|
||||
#define SK_Scalar1 1.0
|
||||
#define SK_ScalarHalf 0.5
|
||||
#define SK_ScalarSqrt2 1.414213562373095
|
||||
#define SK_ScalarPI 3.141592653589793
|
||||
#define SK_ScalarTanPIOver8 0.4142135623731
|
||||
#define SK_ScalarRoot2Over2 0.70710678118655
|
||||
#define SK_ScalarMax 1.7976931348623157+308
|
||||
#define SK_ScalarInfinity SK_DoubleInfinity
|
||||
#define SK_ScalarNegativeInfinity SK_DoubleNegativeInfinity
|
||||
#define SK_ScalarNaN SK_DoubleNaN
|
||||
|
||||
#define SkScalarFloorToScalar(x) floor(x)
|
||||
#define SkScalarCeilToScalar(x) ceil(x)
|
||||
#define SkScalarRoundToScalar(x) floor((x) + 0.5)
|
||||
#define SkScalarTruncToScalar(x) trunc(x)
|
||||
|
||||
#define SkScalarFloorToInt(x) (int)floor(x)
|
||||
#define SkScalarCeilToInt(x) (int)ceil(x)
|
||||
#define SkScalarRoundToInt(x) (int)floor((x) + 0.5)
|
||||
|
||||
#define SkScalarAbs(x) abs(x)
|
||||
#define SkScalarCopySign(x, y) copysign(x, y)
|
||||
#define SkScalarMod(x, y) fmod(x,y)
|
||||
#define SkScalarSqrt(x) sqrt(x)
|
||||
#define SkScalarPow(b, e) pow(b, e)
|
||||
|
||||
#define SkScalarSin(radians) sin(radians)
|
||||
#define SkScalarCos(radians) cos(radians)
|
||||
#define SkScalarTan(radians) tan(radians)
|
||||
#define SkScalarASin(val) asin(val)
|
||||
#define SkScalarACos(val) acos(val)
|
||||
#define SkScalarATan2(y, x) atan2(y,x)
|
||||
#define SkScalarExp(x) exp(x)
|
||||
#define SkScalarLog(x) log(x)
|
||||
#define SkScalarLog2(x) log2(x)
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define SkIntToScalar(x) static_cast<SkScalar>(x)
|
||||
|
@ -134,6 +181,9 @@ SkScalar SkScalarSinCos(SkScalar radians, SkScalar* cosValue);
|
|||
|
||||
static inline SkScalar SkScalarSquare(SkScalar x) { return x * x; }
|
||||
|
||||
#define SkScalarMul(a, b) ((SkScalar)(a) * (b))
|
||||
#define SkScalarMulAdd(a, b, c) ((SkScalar)(a) * (b) + (c))
|
||||
#define SkScalarMulDiv(a, b, c) ((SkScalar)(a) * (b) / (c))
|
||||
#define SkScalarInvert(x) (SK_Scalar1 / (x))
|
||||
#define SkScalarFastInvert(x) (SK_Scalar1 / (x))
|
||||
#define SkScalarAve(a, b) (((a) + (b)) * SK_ScalarHalf)
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#define SkShader_DEFINED
|
||||
|
||||
#include "SkBitmap.h"
|
||||
#include "SkFilterQuality.h"
|
||||
#include "SkFlattenable.h"
|
||||
#include "SkImageInfo.h"
|
||||
#include "SkMask.h"
|
||||
|
@ -17,13 +16,12 @@
|
|||
#include "SkPaint.h"
|
||||
#include "../gpu/GrColor.h"
|
||||
|
||||
class SkArenaAlloc;
|
||||
class SkColorFilter;
|
||||
class SkColorSpace;
|
||||
class SkImage;
|
||||
class SkPath;
|
||||
class SkPicture;
|
||||
class SkRasterPipeline;
|
||||
class SkXfermode;
|
||||
class GrContext;
|
||||
class GrFragmentProcessor;
|
||||
|
||||
|
@ -40,7 +38,7 @@ class GrFragmentProcessor;
|
|||
class SK_API SkShader : public SkFlattenable {
|
||||
public:
|
||||
SkShader(const SkMatrix* localMatrix = NULL);
|
||||
~SkShader() override;
|
||||
virtual ~SkShader();
|
||||
|
||||
/**
|
||||
* Returns the local matrix.
|
||||
|
@ -100,12 +98,6 @@ public:
|
|||
*/
|
||||
virtual bool isOpaque() const { return false; }
|
||||
|
||||
/**
|
||||
* Returns true if the shader is guaranteed to produce only a single color.
|
||||
* Subclasses can override this to allow loop-hoisting optimization.
|
||||
*/
|
||||
virtual bool isConstant() const { return false; }
|
||||
|
||||
/**
|
||||
* ContextRec acts as a parameter bundle for creating Contexts.
|
||||
*/
|
||||
|
@ -116,18 +108,16 @@ public:
|
|||
};
|
||||
|
||||
ContextRec(const SkPaint& paint, const SkMatrix& matrix, const SkMatrix* localM,
|
||||
DstType dstType, SkColorSpace* dstColorSpace)
|
||||
DstType dstType)
|
||||
: fPaint(&paint)
|
||||
, fMatrix(&matrix)
|
||||
, fLocalMatrix(localM)
|
||||
, fPreferredDstType(dstType)
|
||||
, fDstColorSpace(dstColorSpace) {}
|
||||
, fPreferredDstType(dstType) {}
|
||||
|
||||
const SkPaint* fPaint; // the current paint associated with the draw
|
||||
const SkMatrix* fMatrix; // the current matrix in the canvas
|
||||
const SkMatrix* fLocalMatrix; // optional local matrix
|
||||
const DstType fPreferredDstType; // the "natural" client dest type
|
||||
SkColorSpace* fDstColorSpace; // the color space of the dest surface (if any)
|
||||
};
|
||||
|
||||
class Context : public ::SkNoncopyable {
|
||||
|
@ -163,7 +153,7 @@ public:
|
|||
struct BlitState {
|
||||
// inputs
|
||||
Context* fCtx;
|
||||
SkBlendMode fMode;
|
||||
SkXfermode* fXfer;
|
||||
|
||||
// outputs
|
||||
enum { N = 2 };
|
||||
|
@ -229,11 +219,15 @@ public:
|
|||
};
|
||||
|
||||
/**
|
||||
* Make a context using the memory provided by the arena.
|
||||
*
|
||||
* @return pointer to context or nullptr if can't be created
|
||||
* Create the actual object that does the shading.
|
||||
* Size of storage must be >= contextSize.
|
||||
*/
|
||||
Context* makeContext(const ContextRec&, SkArenaAlloc*) const;
|
||||
Context* createContext(const ContextRec&, void* storage) const;
|
||||
|
||||
/**
|
||||
* Return the size of a Context returned by createContext.
|
||||
*/
|
||||
size_t contextSize(const ContextRec&) const;
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_SHADER_ISABITMAP
|
||||
/**
|
||||
|
@ -326,30 +320,32 @@ public:
|
|||
struct ComposeRec {
|
||||
const SkShader* fShaderA;
|
||||
const SkShader* fShaderB;
|
||||
SkBlendMode fBlendMode;
|
||||
const SkXfermode* fMode;
|
||||
};
|
||||
|
||||
virtual bool asACompose(ComposeRec*) const { return false; }
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
struct AsFPArgs {
|
||||
AsFPArgs() {}
|
||||
AsFPArgs(GrContext* context,
|
||||
const SkMatrix* viewMatrix,
|
||||
const SkMatrix* localMatrix,
|
||||
SkFilterQuality filterQuality,
|
||||
SkColorSpace* dstColorSpace)
|
||||
SkColorSpace* dstColorSpace,
|
||||
SkSourceGammaTreatment gammaTreatment)
|
||||
: fContext(context)
|
||||
, fViewMatrix(viewMatrix)
|
||||
, fLocalMatrix(localMatrix)
|
||||
, fFilterQuality(filterQuality)
|
||||
, fDstColorSpace(dstColorSpace) {}
|
||||
, fDstColorSpace(dstColorSpace)
|
||||
, fGammaTreatment(gammaTreatment) {}
|
||||
|
||||
GrContext* fContext;
|
||||
const SkMatrix* fViewMatrix;
|
||||
const SkMatrix* fLocalMatrix;
|
||||
SkFilterQuality fFilterQuality;
|
||||
SkColorSpace* fDstColorSpace;
|
||||
GrContext* fContext;
|
||||
const SkMatrix* fViewMatrix;
|
||||
const SkMatrix* fLocalMatrix;
|
||||
SkFilterQuality fFilterQuality;
|
||||
SkColorSpace* fDstColorSpace;
|
||||
SkSourceGammaTreatment fGammaTreatment;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -378,6 +374,14 @@ public:
|
|||
*/
|
||||
bool asLuminanceColor(SkColor*) const;
|
||||
|
||||
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
||||
/**
|
||||
* If the shader is a custom shader which has data the caller might want, call this function
|
||||
* to get that data.
|
||||
*/
|
||||
virtual bool asACustomShader(void** /* customData */) const { return false; }
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Methods to create combinations or variants of shaders
|
||||
|
||||
|
@ -395,7 +399,7 @@ public:
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Factory methods for stock shaders
|
||||
|
||||
|
||||
/**
|
||||
* Call this to create a new "empty" shader, that will not draw anything.
|
||||
*/
|
||||
|
@ -415,7 +419,40 @@ public:
|
|||
*/
|
||||
static sk_sp<SkShader> MakeColorShader(const SkColor4f&, sk_sp<SkColorSpace>);
|
||||
|
||||
static sk_sp<SkShader> MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader> src, SkBlendMode);
|
||||
static sk_sp<SkShader> MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader> src,
|
||||
SkXfermode::Mode);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR
|
||||
static SkShader* CreateEmptyShader() { return MakeEmptyShader().release(); }
|
||||
static SkShader* CreateColorShader(SkColor c) { return MakeColorShader(c).release(); }
|
||||
static SkShader* CreateBitmapShader(const SkBitmap& src, TileMode tmx, TileMode tmy,
|
||||
const SkMatrix* localMatrix = nullptr) {
|
||||
return MakeBitmapShader(src, tmx, tmy, localMatrix).release();
|
||||
}
|
||||
static SkShader* CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode::Mode mode);
|
||||
static SkShader* CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode* xfer);
|
||||
static SkShader* CreatePictureShader(const SkPicture* src, TileMode tmx, TileMode tmy,
|
||||
const SkMatrix* localMatrix, const SkRect* tile);
|
||||
|
||||
SkShader* newWithLocalMatrix(const SkMatrix& matrix) const {
|
||||
return this->makeWithLocalMatrix(matrix).release();
|
||||
}
|
||||
SkShader* newWithColorFilter(SkColorFilter* filter) const;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Create a new compose shader, given shaders dst, src, and a combining xfermode mode.
|
||||
* The xfermode is called with the output of the two shaders, and its output is returned.
|
||||
* If xfer is null, SkXfermode::kSrcOver_Mode is assumed.
|
||||
*
|
||||
* The caller is responsible for managing its reference-count for the xfer (if not null).
|
||||
*/
|
||||
static sk_sp<SkShader> MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader> src,
|
||||
sk_sp<SkXfermode> xfer);
|
||||
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
|
||||
static sk_sp<SkShader> MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader> src,
|
||||
SkXfermode* xfer);
|
||||
#endif
|
||||
|
||||
/** Call this to create a new shader that will draw with the specified bitmap.
|
||||
*
|
||||
|
@ -454,30 +491,34 @@ public:
|
|||
const SkMatrix* localMatrix, const SkRect* tile);
|
||||
|
||||
/**
|
||||
* If this shader can be represented by another shader + a localMatrix, return that shader and
|
||||
* the localMatrix. If not, return nullptr and ignore the localMatrix parameter.
|
||||
* If this shader can be represented by another shader + a localMatrix, return that shader
|
||||
* and, if not NULL, the localMatrix. If not, return NULL and ignore the localMatrix parameter.
|
||||
*
|
||||
* Note: the returned shader (if not NULL) will have been ref'd, and it is the responsibility
|
||||
* of the caller to balance that with unref() when they are done.
|
||||
*/
|
||||
virtual sk_sp<SkShader> makeAsALocalMatrixShader(SkMatrix* localMatrix) const;
|
||||
virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const;
|
||||
|
||||
SK_TO_STRING_VIRT()
|
||||
SK_DEFINE_FLATTENABLE_TYPE(SkShader)
|
||||
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
|
||||
|
||||
bool appendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
|
||||
const SkMatrix& ctm, const SkPaint&) const;
|
||||
|
||||
protected:
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
|
||||
bool computeTotalInverse(const ContextRec&, SkMatrix* totalInverse) const;
|
||||
|
||||
/**
|
||||
* Specialize creating a SkShader context using the supplied allocator.
|
||||
* @return pointer to context owned by the arena allocator.
|
||||
* Your subclass must also override contextSize() if it overrides onCreateContext().
|
||||
* Base class impl returns NULL.
|
||||
*/
|
||||
virtual Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const {
|
||||
return nullptr;
|
||||
}
|
||||
virtual Context* onCreateContext(const ContextRec&, void* storage) const;
|
||||
|
||||
/**
|
||||
* Override this if your subclass overrides createContext, to return the correct size of
|
||||
* your subclass' context.
|
||||
*/
|
||||
virtual size_t onContextSize(const ContextRec&) const;
|
||||
|
||||
virtual bool onAsLuminanceColor(SkColor*) const {
|
||||
return false;
|
||||
|
@ -493,10 +534,6 @@ protected:
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
virtual bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
|
||||
const SkMatrix&, const SkPaint&,
|
||||
const SkMatrix* /*local matrix*/) const;
|
||||
|
||||
private:
|
||||
// This is essentially const, but not officially so it can be modified in
|
||||
// constructors.
|
||||
|
|
|
@ -10,83 +10,101 @@
|
|||
|
||||
#include "SkScalar.h"
|
||||
|
||||
struct SkISize {
|
||||
int32_t fWidth;
|
||||
int32_t fHeight;
|
||||
template <typename T> struct SkTSize {
|
||||
T fWidth;
|
||||
T fHeight;
|
||||
|
||||
static SkISize Make(int32_t w, int32_t h) { return {w, h}; }
|
||||
static SkTSize Make(T w, T h) {
|
||||
SkTSize s;
|
||||
s.fWidth = w;
|
||||
s.fHeight = h;
|
||||
return s;
|
||||
}
|
||||
|
||||
static SkISize MakeEmpty() { return {0, 0}; }
|
||||
|
||||
void set(int32_t w, int32_t h) { *this = SkISize{w, h}; }
|
||||
void set(T w, T h) {
|
||||
fWidth = w;
|
||||
fHeight = h;
|
||||
}
|
||||
|
||||
/** Returns true iff fWidth == 0 && fHeight == 0
|
||||
*/
|
||||
bool isZero() const { return 0 == fWidth && 0 == fHeight; }
|
||||
bool isZero() const {
|
||||
return 0 == fWidth && 0 == fHeight;
|
||||
}
|
||||
|
||||
/** Returns true if either widht or height are <= 0 */
|
||||
bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
|
||||
bool isEmpty() const {
|
||||
return fWidth <= 0 || fHeight <= 0;
|
||||
}
|
||||
|
||||
/** Set the width and height to 0 */
|
||||
void setEmpty() { fWidth = fHeight = 0; }
|
||||
void setEmpty() {
|
||||
fWidth = fHeight = 0;
|
||||
}
|
||||
|
||||
int32_t width() const { return fWidth; }
|
||||
int32_t height() const { return fHeight; }
|
||||
T width() const { return fWidth; }
|
||||
T height() const { return fHeight; }
|
||||
|
||||
bool equals(int32_t w, int32_t h) const { return fWidth == w && fHeight == h; }
|
||||
/** If width or height is < 0, it is set to 0 */
|
||||
void clampNegToZero() {
|
||||
if (fWidth < 0) {
|
||||
fWidth = 0;
|
||||
}
|
||||
if (fHeight < 0) {
|
||||
fHeight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool equals(T w, T h) const {
|
||||
return fWidth == w && fHeight == h;
|
||||
}
|
||||
};
|
||||
|
||||
static inline bool operator==(const SkISize& a, const SkISize& b) {
|
||||
template <typename T>
|
||||
static inline bool operator==(const SkTSize<T>& a, const SkTSize<T>& b) {
|
||||
return a.fWidth == b.fWidth && a.fHeight == b.fHeight;
|
||||
}
|
||||
|
||||
static inline bool operator!=(const SkISize& a, const SkISize& b) { return !(a == b); }
|
||||
template <typename T>
|
||||
static inline bool operator!=(const SkTSize<T>& a, const SkTSize<T>& b) {
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct SkSize {
|
||||
SkScalar fWidth;
|
||||
SkScalar fHeight;
|
||||
typedef SkTSize<int32_t> SkISize;
|
||||
|
||||
static SkSize Make(SkScalar w, SkScalar h) { return {w, h}; }
|
||||
|
||||
static SkSize Make(const SkISize& src) {
|
||||
return {SkIntToScalar(src.width()), SkIntToScalar(src.height())};
|
||||
struct SkSize : public SkTSize<SkScalar> {
|
||||
static SkSize Make(SkScalar w, SkScalar h) {
|
||||
SkSize s;
|
||||
s.fWidth = w;
|
||||
s.fHeight = h;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
SkSize& operator=(const SkISize& src) {
|
||||
return *this = SkSize{SkIntToScalar(src.fWidth), SkIntToScalar(src.fHeight)};
|
||||
this->set(SkIntToScalar(src.fWidth), SkIntToScalar(src.fHeight));
|
||||
return *this;
|
||||
}
|
||||
|
||||
static SkSize MakeEmpty() { return {0, 0}; }
|
||||
SkISize toRound() const {
|
||||
SkISize s;
|
||||
s.set(SkScalarRoundToInt(fWidth), SkScalarRoundToInt(fHeight));
|
||||
return s;
|
||||
}
|
||||
|
||||
void set(SkScalar w, SkScalar h) { *this = SkSize{w, h}; }
|
||||
SkISize toCeil() const {
|
||||
SkISize s;
|
||||
s.set(SkScalarCeilToInt(fWidth), SkScalarCeilToInt(fHeight));
|
||||
return s;
|
||||
}
|
||||
|
||||
/** Returns true iff fWidth == 0 && fHeight == 0
|
||||
*/
|
||||
bool isZero() const { return 0 == fWidth && 0 == fHeight; }
|
||||
|
||||
/** Returns true if either widht or height are <= 0 */
|
||||
bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
|
||||
|
||||
/** Set the width and height to 0 */
|
||||
void setEmpty() { *this = SkSize{0, 0}; }
|
||||
|
||||
SkScalar width() const { return fWidth; }
|
||||
SkScalar height() const { return fHeight; }
|
||||
|
||||
bool equals(SkScalar w, SkScalar h) const { return fWidth == w && fHeight == h; }
|
||||
|
||||
SkISize toRound() const { return {SkScalarRoundToInt(fWidth), SkScalarRoundToInt(fHeight)}; }
|
||||
|
||||
SkISize toCeil() const { return {SkScalarCeilToInt(fWidth), SkScalarCeilToInt(fHeight)}; }
|
||||
|
||||
SkISize toFloor() const { return {SkScalarFloorToInt(fWidth), SkScalarFloorToInt(fHeight)}; }
|
||||
SkISize toFloor() const {
|
||||
SkISize s;
|
||||
s.set(SkScalarFloorToInt(fWidth), SkScalarFloorToInt(fHeight));
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
static inline bool operator==(const SkSize& a, const SkSize& b) {
|
||||
return a.fWidth == b.fWidth && a.fHeight == b.fHeight;
|
||||
}
|
||||
|
||||
static inline bool operator!=(const SkSize& a, const SkSize& b) { return !(a == b); }
|
||||
#endif
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
#include "SkRefCnt.h"
|
||||
#include "SkScalar.h"
|
||||
|
||||
#include <memory.h>
|
||||
|
||||
class SkStream;
|
||||
class SkStreamRewindable;
|
||||
class SkStreamSeekable;
|
||||
|
@ -189,31 +187,21 @@ public:
|
|||
@return true on success
|
||||
*/
|
||||
virtual bool write(const void* buffer, size_t size) = 0;
|
||||
virtual void newline();
|
||||
virtual void flush();
|
||||
|
||||
virtual size_t bytesWritten() const = 0;
|
||||
|
||||
// helpers
|
||||
|
||||
bool write8(U8CPU value) {
|
||||
uint8_t v = SkToU8(value);
|
||||
return this->write(&v, 1);
|
||||
}
|
||||
bool write16(U16CPU value) {
|
||||
uint16_t v = SkToU16(value);
|
||||
return this->write(&v, 2);
|
||||
}
|
||||
bool write32(uint32_t v) {
|
||||
return this->write(&v, 4);
|
||||
}
|
||||
bool write8(U8CPU);
|
||||
bool write16(U16CPU);
|
||||
bool write32(uint32_t);
|
||||
|
||||
bool writeText(const char text[]) {
|
||||
bool writeText(const char text[]) {
|
||||
SkASSERT(text);
|
||||
return this->write(text, strlen(text));
|
||||
}
|
||||
|
||||
bool newline() { return this->write("\n", strlen("\n")); }
|
||||
|
||||
bool writeDecAsText(int32_t);
|
||||
bool writeBigDecAsText(int64_t, int minDigits = 0);
|
||||
bool writeHexAsText(uint32_t, int minDigits = 0);
|
||||
|
@ -232,20 +220,9 @@ public:
|
|||
static int SizeOfPackedUInt(size_t value);
|
||||
};
|
||||
|
||||
class SK_API SkNullWStream : public SkWStream {
|
||||
public:
|
||||
SkNullWStream() : fBytesWritten(0) {}
|
||||
|
||||
bool write(const void*, size_t n) override { fBytesWritten += n; return true; }
|
||||
void flush() override {}
|
||||
size_t bytesWritten() const override { return fBytesWritten; }
|
||||
|
||||
private:
|
||||
size_t fBytesWritten;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SkString.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/** A stream that wraps a C FILE* file stream. */
|
||||
|
@ -254,20 +231,28 @@ public:
|
|||
/** Initialize the stream by calling sk_fopen on the specified path.
|
||||
* This internal stream will be closed in the destructor.
|
||||
*/
|
||||
explicit SkFILEStream(const char path[] = nullptr);
|
||||
explicit SkFILEStream(const char path[] = NULL);
|
||||
|
||||
enum Ownership {
|
||||
kCallerPasses_Ownership,
|
||||
kCallerRetains_Ownership
|
||||
};
|
||||
/** Initialize the stream with an existing C file stream.
|
||||
* The C file stream will be closed in the destructor.
|
||||
* While this stream exists, it assumes exclusive access to the C file stream.
|
||||
* The C file stream will be closed in the destructor unless the caller specifies
|
||||
* kCallerRetains_Ownership.
|
||||
*/
|
||||
explicit SkFILEStream(FILE* file);
|
||||
explicit SkFILEStream(FILE* file, Ownership ownership = kCallerPasses_Ownership);
|
||||
|
||||
~SkFILEStream() override;
|
||||
virtual ~SkFILEStream();
|
||||
|
||||
/** Returns true if the current path could be opened. */
|
||||
bool isValid() const { return fFILE != nullptr; }
|
||||
bool isValid() const { return fFILE != NULL; }
|
||||
|
||||
/** Close this SkFILEStream. */
|
||||
void close();
|
||||
/** Close the current file, and open a new file with the specified path.
|
||||
* If path is NULL, just close the current file.
|
||||
*/
|
||||
void setPath(const char path[]);
|
||||
|
||||
size_t read(void* buffer, size_t size) override;
|
||||
bool isAtEnd() const override;
|
||||
|
@ -285,14 +270,11 @@ public:
|
|||
const void* getMemoryBase() override;
|
||||
|
||||
private:
|
||||
explicit SkFILEStream(std::shared_ptr<FILE>, size_t size, size_t offset);
|
||||
explicit SkFILEStream(std::shared_ptr<FILE>, size_t size, size_t offset, size_t originalOffset);
|
||||
|
||||
std::shared_ptr<FILE> fFILE;
|
||||
// My own council will I keep on sizes and offsets.
|
||||
size_t fSize;
|
||||
size_t fOffset;
|
||||
size_t fOriginalOffset;
|
||||
FILE* fFILE;
|
||||
SkString fName;
|
||||
Ownership fOwnership;
|
||||
// fData is lazilly initialized when needed.
|
||||
mutable sk_sp<SkData> fData;
|
||||
|
||||
typedef SkStreamAsset INHERITED;
|
||||
};
|
||||
|
@ -307,6 +289,14 @@ public:
|
|||
/** If copyData is true, the stream makes a private copy of the data. */
|
||||
SkMemoryStream(const void* data, size_t length, bool copyData = false);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_STREAM_DATA
|
||||
/** Use the specified data as the memory for this stream.
|
||||
* The stream will call ref() on the data (assuming it is not NULL).
|
||||
* DEPRECATED
|
||||
*/
|
||||
SkMemoryStream(SkData*);
|
||||
#endif
|
||||
|
||||
/** Creates the stream to read from the specified data */
|
||||
SkMemoryStream(sk_sp<SkData>);
|
||||
|
||||
|
@ -324,6 +314,22 @@ public:
|
|||
|
||||
sk_sp<SkData> asData() const { return fData; }
|
||||
void setData(sk_sp<SkData>);
|
||||
#ifdef SK_SUPPORT_LEGACY_STREAM_DATA
|
||||
/** Return the stream's data in a SkData.
|
||||
* The caller must call unref() when it is finished using the data.
|
||||
*/
|
||||
SkData* copyToData() const { return asData().release(); }
|
||||
|
||||
/**
|
||||
* Use the specified data as the memory for this stream.
|
||||
* The stream will call ref() on the data (assuming it is not NULL).
|
||||
* The function returns the data parameter as a convenience.
|
||||
*/
|
||||
SkData* setData(SkData* data) {
|
||||
this->setData(sk_ref_sp(data));
|
||||
return data;
|
||||
}
|
||||
#endif
|
||||
|
||||
void skipToAlign4();
|
||||
const void* getAtPos();
|
||||
|
@ -357,7 +363,7 @@ private:
|
|||
class SK_API SkFILEWStream : public SkWStream {
|
||||
public:
|
||||
SkFILEWStream(const char path[]);
|
||||
~SkFILEWStream() override;
|
||||
virtual ~SkFILEWStream();
|
||||
|
||||
/** Returns true if the current path could be opened.
|
||||
*/
|
||||
|
@ -374,28 +380,52 @@ private:
|
|||
typedef SkWStream INHERITED;
|
||||
};
|
||||
|
||||
class SK_API SkMemoryWStream : public SkWStream {
|
||||
public:
|
||||
SkMemoryWStream(void* buffer, size_t size);
|
||||
bool write(const void* buffer, size_t size) override;
|
||||
size_t bytesWritten() const override { return fBytesWritten; }
|
||||
|
||||
private:
|
||||
char* fBuffer;
|
||||
size_t fMaxLength;
|
||||
size_t fBytesWritten;
|
||||
|
||||
typedef SkWStream INHERITED;
|
||||
};
|
||||
|
||||
class SK_API SkDynamicMemoryWStream : public SkWStream {
|
||||
public:
|
||||
SkDynamicMemoryWStream();
|
||||
~SkDynamicMemoryWStream() override;
|
||||
virtual ~SkDynamicMemoryWStream();
|
||||
|
||||
bool write(const void* buffer, size_t size) override;
|
||||
size_t bytesWritten() const override;
|
||||
|
||||
size_t bytesWritten() const override { return fBytesWritten; }
|
||||
// random access write
|
||||
// modifies stream and returns true if offset + size is less than or equal to getOffset()
|
||||
bool write(const void* buffer, size_t offset, size_t size);
|
||||
bool read(void* buffer, size_t offset, size_t size);
|
||||
size_t getOffset() const { return fBytesWritten; }
|
||||
|
||||
/** More efficient version of read(dst, 0, bytesWritten()). */
|
||||
// copy what has been written to the stream into dst
|
||||
void copyTo(void* dst) const;
|
||||
void writeToStream(SkWStream* dst) const;
|
||||
|
||||
/** Equivalent to copyTo() followed by reset(), but may save memory use. */
|
||||
void copyToAndReset(void* dst);
|
||||
|
||||
/** Return the contents as SkData, and then reset the stream. */
|
||||
sk_sp<SkData> snapshotAsData() const;
|
||||
// Return the contents as SkData, and then reset the stream.
|
||||
sk_sp<SkData> detachAsData();
|
||||
#ifdef SK_SUPPORT_LEGACY_STREAM_DATA
|
||||
/**
|
||||
* Return a copy of the data written so far. This call is responsible for
|
||||
* calling unref() when they are finished with the data.
|
||||
*/
|
||||
SkData* copyToData() const {
|
||||
return snapshotAsData().release();
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Reset, returning a reader stream with the current content. */
|
||||
std::unique_ptr<SkStreamAsset> detachAsStream();
|
||||
SkStreamAsset* detachAsStream();
|
||||
|
||||
/** Reset the stream to its original, empty, state. */
|
||||
void reset();
|
||||
|
@ -404,13 +434,10 @@ private:
|
|||
struct Block;
|
||||
Block* fHead;
|
||||
Block* fTail;
|
||||
size_t fBytesWrittenBeforeTail;
|
||||
size_t fBytesWritten;
|
||||
mutable sk_sp<SkData> fCopy; // is invalidated if we write after it is created
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
void validate() const;
|
||||
#else
|
||||
void validate() const {}
|
||||
#endif
|
||||
void invalidateCopy();
|
||||
|
||||
// For access to the Block type.
|
||||
friend class SkBlockMemoryStream;
|
||||
|
@ -419,4 +446,22 @@ private:
|
|||
typedef SkWStream INHERITED;
|
||||
};
|
||||
|
||||
|
||||
class SK_API SkDebugWStream : public SkWStream {
|
||||
public:
|
||||
SkDebugWStream() : fBytesWritten(0) {}
|
||||
|
||||
// overrides
|
||||
bool write(const void* buffer, size_t size) override;
|
||||
void newline() override;
|
||||
size_t bytesWritten() const override { return fBytesWritten; }
|
||||
|
||||
private:
|
||||
size_t fBytesWritten;
|
||||
typedef SkWStream INHERITED;
|
||||
};
|
||||
|
||||
// for now
|
||||
typedef SkFILEStream SkURLStream;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,11 +18,12 @@ class GrContext;
|
|||
class GrRenderTarget;
|
||||
|
||||
/**
|
||||
* SkSurface is responsible for managing the pixels that a canvas draws into. The pixels can be
|
||||
* allocated either in CPU memory (a Raster surface) or on the GPU (a RenderTarget surface).
|
||||
* SkSurface represents the backend/results of drawing to a canvas. For raster
|
||||
* drawing, the surface will be pixels, but (for example) when drawing into
|
||||
* a PDF or Picture canvas, the surface stores the recorded commands.
|
||||
*
|
||||
* SkSurface takes care of allocating a SkCanvas that will draw into the surface. Call
|
||||
* surface->getCanvas() to use that canvas (but don't delete it, it is owned by the surface).
|
||||
* To draw into a canvas, first create the appropriate type of Surface, and
|
||||
* then request the canvas from the surface.
|
||||
*
|
||||
* SkSurface always has non-zero dimensions. If there is a request for a new surface, and either
|
||||
* of the requested dimensions are zero, then NULL will be returned.
|
||||
|
@ -50,10 +51,14 @@ public:
|
|||
void* context, const SkSurfaceProps* = nullptr);
|
||||
|
||||
/**
|
||||
* Return a new surface, with the memory for the pixels automatically allocated and
|
||||
* zero-initialized, but respecting the specified rowBytes. If rowBytes==0, then a default
|
||||
* value will be chosen. If a non-zero rowBytes is specified, then any images snapped off of
|
||||
* this surface (via makeImageSnapshot()) are guaranteed to have the same rowBytes.
|
||||
* Return a new surface, with the memory for the pixels automatically allocated but respecting
|
||||
* the specified rowBytes. If rowBytes==0, then a default value will be chosen. If a non-zero
|
||||
* rowBytes is specified, then any images snapped off of this surface (via makeImageSnapshot())
|
||||
* are guaranteed to have the same rowBytes.
|
||||
*
|
||||
* If the requested alpha type is not opaque, then the surface's pixel memory will be
|
||||
* zero-initialized. If it is opaque, then it will be left uninitialized, and the caller is
|
||||
* responsible for initially clearing the surface.
|
||||
*
|
||||
* If the requested surface cannot be created, or the request is not a
|
||||
* supported configuration, NULL will be returned.
|
||||
|
@ -145,12 +150,60 @@ public:
|
|||
}
|
||||
|
||||
static sk_sp<SkSurface> MakeRenderTarget(GrContext* gr, SkBudgeted b, const SkImageInfo& info) {
|
||||
if (!info.width() || !info.height()) {
|
||||
return nullptr;
|
||||
}
|
||||
return MakeRenderTarget(gr, b, info, 0, kBottomLeft_GrSurfaceOrigin, nullptr);
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API
|
||||
static SkSurface* NewRasterDirect(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
||||
const SkSurfaceProps* props = NULL) {
|
||||
return MakeRasterDirect(info, pixels, rowBytes, props).release();
|
||||
}
|
||||
static SkSurface* NewRasterDirectReleaseProc(const SkImageInfo& info, void* pixels,
|
||||
size_t rowBytes,
|
||||
void (*releaseProc)(void* pixels, void* context),
|
||||
void* context, const SkSurfaceProps* props = NULL){
|
||||
return MakeRasterDirectReleaseProc(info, pixels, rowBytes, releaseProc, context,
|
||||
props).release();
|
||||
}
|
||||
static SkSurface* NewRaster(const SkImageInfo& info, size_t rowBytes,
|
||||
const SkSurfaceProps* props) {
|
||||
return MakeRaster(info, rowBytes, props).release();
|
||||
}
|
||||
static SkSurface* NewRaster(const SkImageInfo& info, const SkSurfaceProps* props = NULL) {
|
||||
return MakeRaster(info, props).release();
|
||||
}
|
||||
static SkSurface* NewRasterN32Premul(int width, int height,
|
||||
const SkSurfaceProps* props = NULL) {
|
||||
return NewRaster(SkImageInfo::MakeN32Premul(width, height), props);
|
||||
}
|
||||
static SkSurface* NewFromBackendTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
|
||||
const SkSurfaceProps* props) {
|
||||
return MakeFromBackendTexture(ctx, desc, props).release();
|
||||
}
|
||||
// Legacy alias
|
||||
static SkSurface* NewWrappedRenderTarget(GrContext* ctx, const GrBackendTextureDesc& desc,
|
||||
const SkSurfaceProps* props) {
|
||||
return NewFromBackendTexture(ctx, desc, props);
|
||||
}
|
||||
static SkSurface* NewFromBackendRenderTarget(GrContext* ctx, const GrBackendRenderTargetDesc& d,
|
||||
const SkSurfaceProps* props) {
|
||||
return MakeFromBackendRenderTarget(ctx, d, props).release();
|
||||
}
|
||||
static SkSurface* NewFromBackendTextureAsRenderTarget(GrContext* ctx,
|
||||
const GrBackendTextureDesc& desc,
|
||||
const SkSurfaceProps* props) {
|
||||
return MakeFromBackendTextureAsRenderTarget(ctx, desc, props).release();
|
||||
}
|
||||
static SkSurface* NewRenderTarget(GrContext* ctx, SkBudgeted b, const SkImageInfo& info,
|
||||
int sampleCount, const SkSurfaceProps* props = NULL) {
|
||||
return MakeRenderTarget(ctx, b, info, sampleCount, props).release();
|
||||
}
|
||||
static SkSurface* NewRenderTarget(GrContext* gr, SkBudgeted b, const SkImageInfo& info) {
|
||||
return NewRenderTarget(gr, b, info, 0);
|
||||
}
|
||||
SkSurface* newSurface(const SkImageInfo& info) { return this->makeSurface(info).release(); }
|
||||
#endif
|
||||
|
||||
int width() const { return fWidth; }
|
||||
int height() const { return fHeight; }
|
||||
|
||||
|
@ -249,10 +302,32 @@ public:
|
|||
/**
|
||||
* Returns an image of the current state of the surface pixels up to this
|
||||
* point. Subsequent changes to the surface (by drawing into its canvas)
|
||||
* will not be reflected in this image. For the GPU-backend, the budgeting
|
||||
* decision for the snapped image will match that of the surface.
|
||||
* will not be reflected in this image. If a copy must be made the Budgeted
|
||||
* parameter controls whether it counts against the resource budget
|
||||
* (currently for the gpu backend only).
|
||||
*/
|
||||
sk_sp<SkImage> makeImageSnapshot();
|
||||
sk_sp<SkImage> makeImageSnapshot(SkBudgeted = SkBudgeted::kYes);
|
||||
|
||||
/**
|
||||
* In rare instances a client may want a unique copy of the SkSurface's contents in an image
|
||||
* snapshot. This enum can be used to enforce that the image snapshot's backing store is not
|
||||
* shared with another image snapshot or the surface's backing store. This is generally more
|
||||
* expensive. This was added for Chromium bug 585250.
|
||||
*/
|
||||
enum ForceUnique {
|
||||
kNo_ForceUnique,
|
||||
kYes_ForceUnique
|
||||
};
|
||||
sk_sp<SkImage> makeImageSnapshot(SkBudgeted, ForceUnique);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFACTORY
|
||||
SkImage* newImageSnapshot(SkBudgeted budgeted = SkBudgeted::kYes) {
|
||||
return this->makeImageSnapshot(budgeted).release();
|
||||
}
|
||||
SkImage* newImageSnapshot(SkBudgeted budgeted, ForceUnique force) {
|
||||
return this->makeImageSnapshot(budgeted, force).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Though the caller could get a snapshot image explicitly, and draw that,
|
||||
|
@ -274,6 +349,10 @@ public:
|
|||
*/
|
||||
bool peekPixels(SkPixmap*);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PEEKPIXELS_PARMS
|
||||
const void* peekPixels(SkImageInfo* info, size_t* rowBytes);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Copy the pixels from the surface into the specified buffer (pixels + rowBytes),
|
||||
* converting them into the requested format (dstInfo). The surface pixels are read
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
|
||||
/*
|
||||
* Copyright 2009 The Android Open Source Project
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SkTRegistry_DEFINED
|
||||
#define SkTRegistry_DEFINED
|
||||
|
||||
#include "SkTypes.h"
|
||||
|
||||
/** Template class that registers itself (in the constructor) into a linked-list
|
||||
and provides a function-pointer. This can be used to auto-register a set of
|
||||
services, e.g. a set of image codecs.
|
||||
*/
|
||||
template <typename T> class SkTRegistry : SkNoncopyable {
|
||||
public:
|
||||
typedef T Factory;
|
||||
|
||||
explicit SkTRegistry(T fact) : fFact(fact) {
|
||||
#ifdef SK_BUILD_FOR_ANDROID
|
||||
// work-around for double-initialization bug
|
||||
{
|
||||
SkTRegistry* reg = gHead;
|
||||
while (reg) {
|
||||
if (reg == this) {
|
||||
return;
|
||||
}
|
||||
reg = reg->fChain;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
fChain = gHead;
|
||||
gHead = this;
|
||||
}
|
||||
|
||||
static const SkTRegistry* Head() { return gHead; }
|
||||
|
||||
const SkTRegistry* next() const { return fChain; }
|
||||
const Factory& factory() const { return fFact; }
|
||||
|
||||
private:
|
||||
Factory fFact;
|
||||
SkTRegistry* fChain;
|
||||
|
||||
static SkTRegistry* gHead;
|
||||
};
|
||||
|
||||
// The caller still needs to declare an instance of this somewhere
|
||||
template <typename T> SkTRegistry<T>* SkTRegistry<T>::gHead;
|
||||
|
||||
#endif
|
|
@ -9,7 +9,6 @@
|
|||
#define SkTextBlob_DEFINED
|
||||
|
||||
#include "../private/SkTemplates.h"
|
||||
#include "../private/SkAtomics.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkString.h"
|
||||
#include "SkRefCnt.h"
|
||||
|
@ -61,7 +60,7 @@ private:
|
|||
friend class SkNVRefCnt<SkTextBlob>;
|
||||
class RunRecord;
|
||||
|
||||
explicit SkTextBlob(const SkRect& bounds);
|
||||
SkTextBlob(int runCount, const SkRect& bounds);
|
||||
|
||||
~SkTextBlob();
|
||||
|
||||
|
@ -76,19 +75,12 @@ private:
|
|||
|
||||
static unsigned ScalarsPerGlyph(GlyphPositioning pos);
|
||||
|
||||
// Call when this blob is part of the key to a cache entry. This allows the cache
|
||||
// to know automatically those entries can be purged when this SkTextBlob is deleted.
|
||||
void notifyAddedToCache() const {
|
||||
fAddedToCache.store(true);
|
||||
}
|
||||
|
||||
friend class GrTextBlobCache;
|
||||
friend class SkTextBlobBuilder;
|
||||
friend class SkTextBlobRunIterator;
|
||||
|
||||
const SkRect fBounds;
|
||||
const uint32_t fUniqueID;
|
||||
mutable SkAtomic<bool> fAddedToCache;
|
||||
const int fRunCount;
|
||||
const SkRect fBounds;
|
||||
const uint32_t fUniqueID;
|
||||
|
||||
SkDEBUGCODE(size_t fStorageSize;)
|
||||
|
||||
|
@ -109,13 +101,17 @@ public:
|
|||
~SkTextBlobBuilder();
|
||||
|
||||
/**
|
||||
* Returns an immutable SkTextBlob for the current runs/glyphs,
|
||||
* or nullptr if no runs were allocated.
|
||||
*
|
||||
* The builder is reset and can be reused.
|
||||
* Returns an immutable SkTextBlob for the current runs/glyphs. The builder is reset and
|
||||
* can be reused.
|
||||
*/
|
||||
sk_sp<SkTextBlob> make();
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_TEXTBLOB_BUILDER
|
||||
const SkTextBlob* build() {
|
||||
return this->make().release();
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Glyph and position buffers associated with a run.
|
||||
*
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "../private/SkBitmaskEnum.h"
|
||||
#include "../private/SkOnce.h"
|
||||
#include "../private/SkWeakRefCnt.h"
|
||||
#include "SkFontArguments.h"
|
||||
#include "SkFontStyle.h"
|
||||
#include "SkRect.h"
|
||||
#include "SkString.h"
|
||||
|
@ -78,20 +77,6 @@ public:
|
|||
*/
|
||||
bool isFixedPitch() const { return fIsFixedPitch; }
|
||||
|
||||
/** Copy into 'coordinates' (allocated by the caller) the design variation coordinates.
|
||||
*
|
||||
* @param coordinates the buffer into which to write the design variation coordinates.
|
||||
* @param coordinateCount the number of entries available through 'coordinates'.
|
||||
*
|
||||
* @return The number of axes, or -1 if there is an error.
|
||||
* If 'coordinates != nullptr' and 'coordinateCount >= numAxes' then 'coordinates' will be
|
||||
* filled with the variation coordinates describing the position of this typeface in design
|
||||
* variation space. It is possible the number of axes can be retrieved but actual position
|
||||
* cannot.
|
||||
*/
|
||||
int getVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
|
||||
int coordinateCount) const;
|
||||
|
||||
/** Return a 32bit value for this typeface, unique for the underlying font
|
||||
data. Will never return 0.
|
||||
*/
|
||||
|
@ -110,17 +95,28 @@ public:
|
|||
|
||||
/** Returns the default typeface, which is never nullptr. */
|
||||
static sk_sp<SkTypeface> MakeDefault(Style style = SkTypeface::kNormal);
|
||||
#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
|
||||
static SkTypeface* RefDefault(Style style = SkTypeface::kNormal) {
|
||||
return MakeDefault(style).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Creates a new reference to the typeface that most closely matches the
|
||||
requested familyName and fontStyle. This method allows extended font
|
||||
face specifiers as in the SkFontStyle type. Will never return null.
|
||||
/** Creates a new reference to the typeface that most closely matches the
|
||||
requested familyName and fontStyle. This method allows extended font
|
||||
face specifiers as in the SkFontStyle type. Will never return null.
|
||||
|
||||
@param familyName May be NULL. The name of the font family.
|
||||
@param fontStyle The style of the typeface.
|
||||
@return reference to the closest-matching typeface. Call must call
|
||||
@param familyName May be NULL. The name of the font family.
|
||||
@param fontStyle The style of the typeface.
|
||||
@return reference to the closest-matching typeface. Call must call
|
||||
unref() when they are done.
|
||||
*/
|
||||
static sk_sp<SkTypeface> MakeFromName(const char familyName[], SkFontStyle fontStyle);
|
||||
static sk_sp<SkTypeface> MakeFromName(const char familyName[], SkFontStyle fontStyle);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
|
||||
static SkTypeface* CreateFromName(const char familyName[], Style style) {
|
||||
return MakeFromName(familyName, SkFontStyle::FromOldStyle(style)).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Return the typeface that most closely matches the requested typeface and style.
|
||||
Use this to pick a new style from the same family of the existing typeface.
|
||||
|
@ -136,12 +132,22 @@ public:
|
|||
not a valid font file, returns nullptr.
|
||||
*/
|
||||
static sk_sp<SkTypeface> MakeFromFile(const char path[], int index = 0);
|
||||
#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
|
||||
static SkTypeface* CreateFromFile(const char path[], int index = 0) {
|
||||
return MakeFromFile(path, index).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Return a new typeface given a stream. If the stream is
|
||||
not a valid font file, returns nullptr. Ownership of the stream is
|
||||
transferred, so the caller must not reference it again.
|
||||
*/
|
||||
static sk_sp<SkTypeface> MakeFromStream(SkStreamAsset* stream, int index = 0);
|
||||
#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
|
||||
static SkTypeface* CreateFromStream(SkStreamAsset* stream, int index = 0) {
|
||||
return MakeFromStream(stream, index).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Return a new typeface given font data and configuration. If the data
|
||||
is not valid font data, returns nullptr.
|
||||
|
@ -302,9 +308,8 @@ public:
|
|||
* if allowFailure is true, this returns NULL, else it returns a
|
||||
* dummy scalercontext that will not crash, but will draw nothing.
|
||||
*/
|
||||
std::unique_ptr<SkScalerContext> createScalerContext(const SkScalerContextEffects&,
|
||||
const SkDescriptor*,
|
||||
bool allowFailure = false) const;
|
||||
SkScalerContext* createScalerContext(const SkScalerContextEffects&, const SkDescriptor*,
|
||||
bool allowFailure = false) const;
|
||||
|
||||
/**
|
||||
* Return a rectangle (scaled to 1-pt) that represents the union of the bounds of all
|
||||
|
@ -362,10 +367,6 @@ protected:
|
|||
// TODO: make pure virtual.
|
||||
virtual std::unique_ptr<SkFontData> onMakeFontData() const;
|
||||
|
||||
virtual int onGetVariationDesignPosition(
|
||||
SkFontArguments::VariationPosition::Coordinate coordinates[],
|
||||
int coordinateCount) const = 0;
|
||||
|
||||
virtual void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const = 0;
|
||||
|
||||
virtual int onCharsToGlyphs(const void* chars, Encoding, SkGlyphID glyphs[],
|
||||
|
|
|
@ -34,12 +34,28 @@
|
|||
// IWYU pragma: end_exports
|
||||
|
||||
#include <string.h>
|
||||
// TODO(herb): remove after chromuim skia/ext/SkMemory_new_handler.cpp
|
||||
// has been updated to point to private/SkMalloc.h
|
||||
#include "../private/SkMalloc.h"
|
||||
|
||||
// enable to test new device-base clipping
|
||||
//#define SK_USE_DEVICE_CLIPPING
|
||||
/**
|
||||
* sk_careful_memcpy() is just like memcpy(), but guards against undefined behavior.
|
||||
*
|
||||
* It is undefined behavior to call memcpy() with null dst or src, even if len is 0.
|
||||
* If an optimizer is "smart" enough, it can exploit this to do unexpected things.
|
||||
* memcpy(dst, src, 0);
|
||||
* if (src) {
|
||||
* printf("%x\n", *src);
|
||||
* }
|
||||
* In this code the compiler can assume src is not null and omit the if (src) {...} check,
|
||||
* unconditionally running the printf, crashing the program if src really is null.
|
||||
* Of the compilers we pay attention to only GCC performs this optimization in practice.
|
||||
*/
|
||||
static inline void* sk_careful_memcpy(void* dst, const void* src, size_t len) {
|
||||
// When we pass >0 len we had better already be passing valid pointers.
|
||||
// So we just need to skip calling memcpy when len == 0.
|
||||
if (len) {
|
||||
memcpy(dst,src,len);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
/** \file SkTypes.h
|
||||
*/
|
||||
|
@ -50,13 +66,57 @@
|
|||
#define SKIA_VERSION_MINOR 0
|
||||
#define SKIA_VERSION_PATCH 0
|
||||
|
||||
/*
|
||||
memory wrappers to be implemented by the porting layer (platform)
|
||||
*/
|
||||
|
||||
/** Called internally if we run out of memory. The platform implementation must
|
||||
not return, but should either throw an exception or otherwise exit.
|
||||
*/
|
||||
SK_API extern void sk_out_of_memory(void);
|
||||
/** Called internally if we hit an unrecoverable error.
|
||||
The platform implementation must not return, but should either throw
|
||||
an exception or otherwise exit.
|
||||
*/
|
||||
SK_API extern void sk_abort_no_print(void);
|
||||
|
||||
enum {
|
||||
SK_MALLOC_TEMP = 0x01, //!< hint to sk_malloc that the requested memory will be freed in the scope of the stack frame
|
||||
SK_MALLOC_THROW = 0x02 //!< instructs sk_malloc to call sk_throw if the memory cannot be allocated.
|
||||
};
|
||||
/** Return a block of memory (at least 4-byte aligned) of at least the
|
||||
specified size. If the requested memory cannot be returned, either
|
||||
return null (if SK_MALLOC_TEMP bit is clear) or throw an exception
|
||||
(if SK_MALLOC_TEMP bit is set). To free the memory, call sk_free().
|
||||
*/
|
||||
SK_API extern void* sk_malloc_flags(size_t size, unsigned flags);
|
||||
/** Same as sk_malloc(), but hard coded to pass SK_MALLOC_THROW as the flag
|
||||
*/
|
||||
SK_API extern void* sk_malloc_throw(size_t size);
|
||||
/** Same as standard realloc(), but this one never returns null on failure. It will throw
|
||||
an exception if it fails.
|
||||
*/
|
||||
SK_API extern void* sk_realloc_throw(void* buffer, size_t size);
|
||||
/** Free memory returned by sk_malloc(). It is safe to pass null.
|
||||
*/
|
||||
SK_API extern void sk_free(void*);
|
||||
|
||||
/** Much like calloc: returns a pointer to at least size zero bytes, or NULL on failure.
|
||||
*/
|
||||
SK_API extern void* sk_calloc(size_t size);
|
||||
|
||||
/** Same as sk_calloc, but throws an exception instead of returning NULL on failure.
|
||||
*/
|
||||
SK_API extern void* sk_calloc_throw(size_t size);
|
||||
|
||||
// bzero is safer than memset, but we can't rely on it, so... sk_bzero()
|
||||
static inline void sk_bzero(void* buffer, size_t size) {
|
||||
// Please c.f. sk_careful_memcpy. It's undefined behavior to call memset(null, 0, 0).
|
||||
if (size) {
|
||||
memset(buffer, 0, size);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef override_GLOBAL_NEW
|
||||
|
@ -335,10 +395,10 @@ static inline constexpr int Sk32ToBool(uint32_t n) {
|
|||
|
||||
/** Generic swap function. Classes with efficient swaps should specialize this function to take
|
||||
their fast path. This function is used by SkTSort. */
|
||||
template <typename T> static inline void SkTSwap(T& a, T& b) {
|
||||
T c(std::move(a));
|
||||
a = std::move(b);
|
||||
b = std::move(c);
|
||||
template <typename T> inline void SkTSwap(T& a, T& b) {
|
||||
T c(a);
|
||||
a = b;
|
||||
b = c;
|
||||
}
|
||||
|
||||
static inline int32_t SkAbs32(int32_t value) {
|
||||
|
@ -349,7 +409,7 @@ static inline int32_t SkAbs32(int32_t value) {
|
|||
return value;
|
||||
}
|
||||
|
||||
template <typename T> static inline T SkTAbs(T value) {
|
||||
template <typename T> inline T SkTAbs(T value) {
|
||||
if (value < 0) {
|
||||
value = -value;
|
||||
}
|
||||
|
@ -449,6 +509,222 @@ private:
|
|||
SkNoncopyable& operator=(const SkNoncopyable&);
|
||||
};
|
||||
|
||||
class SkAutoFree : SkNoncopyable {
|
||||
public:
|
||||
SkAutoFree() : fPtr(NULL) {}
|
||||
explicit SkAutoFree(void* ptr) : fPtr(ptr) {}
|
||||
~SkAutoFree() { sk_free(fPtr); }
|
||||
|
||||
/** Return the currently allocate buffer, or null
|
||||
*/
|
||||
void* get() const { return fPtr; }
|
||||
|
||||
/** Assign a new ptr allocated with sk_malloc (or null), and return the
|
||||
previous ptr. Note it is the caller's responsibility to sk_free the
|
||||
returned ptr.
|
||||
*/
|
||||
void* set(void* ptr) {
|
||||
void* prev = fPtr;
|
||||
fPtr = ptr;
|
||||
return prev;
|
||||
}
|
||||
|
||||
/** Transfer ownership of the current ptr to the caller, setting the
|
||||
internal reference to null. Note the caller is reponsible for calling
|
||||
sk_free on the returned address.
|
||||
*/
|
||||
void* release() { return this->set(NULL); }
|
||||
|
||||
/** Free the current buffer, and set the internal reference to NULL. Same
|
||||
as calling sk_free(release())
|
||||
*/
|
||||
void reset() {
|
||||
sk_free(fPtr);
|
||||
fPtr = NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
void* fPtr;
|
||||
// illegal
|
||||
SkAutoFree(const SkAutoFree&);
|
||||
SkAutoFree& operator=(const SkAutoFree&);
|
||||
};
|
||||
#define SkAutoFree(...) SK_REQUIRE_LOCAL_VAR(SkAutoFree)
|
||||
|
||||
/**
|
||||
* Manage an allocated block of heap memory. This object is the sole manager of
|
||||
* the lifetime of the block, so the caller must not call sk_free() or delete
|
||||
* on the block, unless release() was called.
|
||||
*/
|
||||
class SkAutoMalloc : SkNoncopyable {
|
||||
public:
|
||||
explicit SkAutoMalloc(size_t size = 0) {
|
||||
fPtr = size ? sk_malloc_throw(size) : NULL;
|
||||
fSize = size;
|
||||
}
|
||||
|
||||
~SkAutoMalloc() {
|
||||
sk_free(fPtr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passed to reset to specify what happens if the requested size is smaller
|
||||
* than the current size (and the current block was dynamically allocated).
|
||||
*/
|
||||
enum OnShrink {
|
||||
/**
|
||||
* If the requested size is smaller than the current size, and the
|
||||
* current block is dynamically allocated, free the old block and
|
||||
* malloc a new block of the smaller size.
|
||||
*/
|
||||
kAlloc_OnShrink,
|
||||
|
||||
/**
|
||||
* If the requested size is smaller than the current size, and the
|
||||
* current block is dynamically allocated, just return the old
|
||||
* block.
|
||||
*/
|
||||
kReuse_OnShrink
|
||||
};
|
||||
|
||||
/**
|
||||
* Reallocates the block to a new size. The ptr may or may not change.
|
||||
*/
|
||||
void* reset(size_t size = 0, OnShrink shrink = kAlloc_OnShrink, bool* didChangeAlloc = NULL) {
|
||||
if (size == fSize || (kReuse_OnShrink == shrink && size < fSize)) {
|
||||
if (didChangeAlloc) {
|
||||
*didChangeAlloc = false;
|
||||
}
|
||||
return fPtr;
|
||||
}
|
||||
|
||||
sk_free(fPtr);
|
||||
fPtr = size ? sk_malloc_throw(size) : NULL;
|
||||
fSize = size;
|
||||
if (didChangeAlloc) {
|
||||
*didChangeAlloc = true;
|
||||
}
|
||||
|
||||
return fPtr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the allocated block.
|
||||
*/
|
||||
void* get() { return fPtr; }
|
||||
const void* get() const { return fPtr; }
|
||||
|
||||
/** Transfer ownership of the current ptr to the caller, setting the
|
||||
internal reference to null. Note the caller is reponsible for calling
|
||||
sk_free on the returned address.
|
||||
*/
|
||||
void* release() {
|
||||
void* ptr = fPtr;
|
||||
fPtr = NULL;
|
||||
fSize = 0;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
void* fPtr;
|
||||
size_t fSize; // can be larger than the requested size (see kReuse)
|
||||
};
|
||||
#define SkAutoMalloc(...) SK_REQUIRE_LOCAL_VAR(SkAutoMalloc)
|
||||
|
||||
/**
|
||||
* Manage an allocated block of memory. If the requested size is <= kSizeRequested (or slightly
|
||||
* more), then the allocation will come from the stack rather than the heap. This object is the
|
||||
* sole manager of the lifetime of the block, so the caller must not call sk_free() or delete on
|
||||
* the block.
|
||||
*/
|
||||
template <size_t kSizeRequested> class SkAutoSMalloc : SkNoncopyable {
|
||||
public:
|
||||
/**
|
||||
* Creates initially empty storage. get() returns a ptr, but it is to a zero-byte allocation.
|
||||
* Must call reset(size) to return an allocated block.
|
||||
*/
|
||||
SkAutoSMalloc() {
|
||||
fPtr = fStorage;
|
||||
fSize = kSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a block of the specified size. If size <= kSizeRequested (or slightly more), then
|
||||
* the allocation will come from the stack, otherwise it will be dynamically allocated.
|
||||
*/
|
||||
explicit SkAutoSMalloc(size_t size) {
|
||||
fPtr = fStorage;
|
||||
fSize = kSize;
|
||||
this->reset(size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the allocated block (if any). If the block was small enough to have been allocated on
|
||||
* the stack, then this does nothing.
|
||||
*/
|
||||
~SkAutoSMalloc() {
|
||||
if (fPtr != (void*)fStorage) {
|
||||
sk_free(fPtr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the allocated block. May return non-null even if the block is of zero size. Since
|
||||
* this may be on the stack or dynamically allocated, the caller must not call sk_free() on it,
|
||||
* but must rely on SkAutoSMalloc to manage it.
|
||||
*/
|
||||
void* get() const { return fPtr; }
|
||||
|
||||
/**
|
||||
* Return a new block of the requested size, freeing (as necessary) any previously allocated
|
||||
* block. As with the constructor, if size <= kSizeRequested (or slightly more) then the return
|
||||
* block may be allocated locally, rather than from the heap.
|
||||
*/
|
||||
void* reset(size_t size,
|
||||
SkAutoMalloc::OnShrink shrink = SkAutoMalloc::kAlloc_OnShrink,
|
||||
bool* didChangeAlloc = NULL) {
|
||||
size = (size < kSize) ? kSize : size;
|
||||
bool alloc = size != fSize && (SkAutoMalloc::kAlloc_OnShrink == shrink || size > fSize);
|
||||
if (didChangeAlloc) {
|
||||
*didChangeAlloc = alloc;
|
||||
}
|
||||
if (alloc) {
|
||||
if (fPtr != (void*)fStorage) {
|
||||
sk_free(fPtr);
|
||||
}
|
||||
|
||||
if (size == kSize) {
|
||||
SkASSERT(fPtr != fStorage); // otherwise we lied when setting didChangeAlloc.
|
||||
fPtr = fStorage;
|
||||
} else {
|
||||
fPtr = sk_malloc_flags(size, SK_MALLOC_THROW | SK_MALLOC_TEMP);
|
||||
}
|
||||
|
||||
fSize = size;
|
||||
}
|
||||
SkASSERT(fSize >= size && fSize >= kSize);
|
||||
SkASSERT((fPtr == fStorage) || fSize > kSize);
|
||||
return fPtr;
|
||||
}
|
||||
|
||||
private:
|
||||
// Align up to 32 bits.
|
||||
static const size_t kSizeAlign4 = SkAlign4(kSizeRequested);
|
||||
#if defined(GOOGLE3)
|
||||
// Stack frame size is limited for GOOGLE3. 4k is less than the actual max, but some functions
|
||||
// have multiple large stack allocations.
|
||||
static const size_t kMaxBytes = 4 * 1024;
|
||||
static const size_t kSize = kSizeRequested > kMaxBytes ? kMaxBytes : kSizeAlign4;
|
||||
#else
|
||||
static const size_t kSize = kSizeAlign4;
|
||||
#endif
|
||||
|
||||
void* fPtr;
|
||||
size_t fSize; // can be larger than the requested size (see kReuse)
|
||||
uint32_t fStorage[kSize >> 2];
|
||||
};
|
||||
// Can't guard the constructor because it's a template class.
|
||||
|
||||
#endif /* C++ */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
/*
|
||||
* Copyright 2017 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkVertices_DEFINED
|
||||
#define SkVertices_DEFINED
|
||||
|
||||
#include "SkColor.h"
|
||||
#include "SkData.h"
|
||||
#include "SkPoint.h"
|
||||
#include "SkRect.h"
|
||||
#include "SkRefCnt.h"
|
||||
|
||||
/**
|
||||
* An immutable set of vertex data that can be used with SkCanvas::drawVertices.
|
||||
*/
|
||||
class SkVertices : public SkNVRefCnt<SkVertices> {
|
||||
public:
|
||||
enum VertexMode {
|
||||
kTriangles_VertexMode,
|
||||
kTriangleStrip_VertexMode,
|
||||
kTriangleFan_VertexMode,
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a vertices by copying the specified arrays. texs and colors may be nullptr,
|
||||
* and indices is ignored if indexCount == 0.
|
||||
*/
|
||||
static sk_sp<SkVertices> MakeCopy(VertexMode mode, int vertexCount,
|
||||
const SkPoint positions[],
|
||||
const SkPoint texs[],
|
||||
const SkColor colors[],
|
||||
int indexCount,
|
||||
const uint16_t indices[]);
|
||||
|
||||
static sk_sp<SkVertices> MakeCopy(VertexMode mode, int vertexCount,
|
||||
const SkPoint positions[],
|
||||
const SkPoint texs[],
|
||||
const SkColor colors[]) {
|
||||
return MakeCopy(mode, vertexCount, positions, texs, colors, 0, nullptr);
|
||||
}
|
||||
|
||||
struct Sizes;
|
||||
|
||||
enum BuilderFlags {
|
||||
kHasTexCoords_BuilderFlag = 1 << 0,
|
||||
kHasColors_BuilderFlag = 1 << 1,
|
||||
};
|
||||
class Builder {
|
||||
public:
|
||||
Builder(VertexMode mode, int vertexCount, int indexCount, uint32_t flags);
|
||||
|
||||
bool isValid() const { return fVertices != nullptr; }
|
||||
|
||||
// if the builder is invalid, these will return 0
|
||||
int vertexCount() const;
|
||||
int indexCount() const;
|
||||
SkPoint* positions();
|
||||
SkPoint* texCoords(); // returns null if there are no texCoords
|
||||
SkColor* colors(); // returns null if there are no colors
|
||||
uint16_t* indices(); // returns null if there are no indices
|
||||
|
||||
// Detach the built vertices object. After the first call, this will always return null.
|
||||
sk_sp<SkVertices> detach();
|
||||
|
||||
private:
|
||||
Builder(VertexMode mode, int vertexCount, int indexCount, const Sizes&);
|
||||
|
||||
void init(VertexMode mode, int vertexCount, int indexCount, const Sizes&);
|
||||
|
||||
// holds a partially complete object. only completed in detach()
|
||||
sk_sp<SkVertices> fVertices;
|
||||
|
||||
friend class SkVertices;
|
||||
};
|
||||
|
||||
uint32_t uniqueID() const { return fUniqueID; }
|
||||
VertexMode mode() const { return fMode; }
|
||||
const SkRect& bounds() const { return fBounds; }
|
||||
|
||||
bool hasColors() const { return SkToBool(this->colors()); }
|
||||
bool hasTexCoords() const { return SkToBool(this->texCoords()); }
|
||||
bool hasIndices() const { return SkToBool(this->indices()); }
|
||||
|
||||
int vertexCount() const { return fVertexCnt; }
|
||||
const SkPoint* positions() const { return fPositions; }
|
||||
const SkPoint* texCoords() const { return fTexs; }
|
||||
const SkColor* colors() const { return fColors; }
|
||||
|
||||
int indexCount() const { return fIndexCnt; }
|
||||
const uint16_t* indices() const { return fIndices; }
|
||||
|
||||
// returns approximate byte size of the vertices object
|
||||
size_t approximateSize() const;
|
||||
|
||||
/**
|
||||
* Recreate a vertices from a buffer previously created by calling encode().
|
||||
* Returns null if the data is corrupt or the length is incorrect for the contents.
|
||||
*/
|
||||
static sk_sp<SkVertices> Decode(const void* buffer, size_t length);
|
||||
|
||||
/**
|
||||
* Pack the vertices object into a byte buffer. This can be used to recreate the vertices
|
||||
* by calling Decode() with the buffer.
|
||||
*/
|
||||
sk_sp<SkData> encode() const;
|
||||
|
||||
private:
|
||||
SkVertices() {}
|
||||
|
||||
// these are needed since we've manually sized our allocation (see Builder::init)
|
||||
friend class SkNVRefCnt<SkVertices>;
|
||||
void operator delete(void* p) { ::operator delete(p); }
|
||||
|
||||
static sk_sp<SkVertices> Alloc(int vCount, int iCount, uint32_t builderFlags,
|
||||
size_t* arraySize);
|
||||
|
||||
// we store this first, to pair with the refcnt in our base-class, so we don't have an
|
||||
// unnecessary pad between it and the (possibly 8-byte aligned) ptrs.
|
||||
uint32_t fUniqueID;
|
||||
|
||||
// these point inside our allocation, so none of these can be "freed"
|
||||
SkPoint* fPositions;
|
||||
SkPoint* fTexs;
|
||||
SkColor* fColors;
|
||||
uint16_t* fIndices;
|
||||
|
||||
SkRect fBounds; // computed to be the union of the fPositions[]
|
||||
int fVertexCnt;
|
||||
int fIndexCnt;
|
||||
|
||||
VertexMode fMode;
|
||||
// below here is where the actual array data is stored.
|
||||
};
|
||||
|
||||
#endif
|
|
@ -81,7 +81,7 @@ public:
|
|||
|
||||
SkBinaryWriteBuffer(uint32_t flags = 0);
|
||||
SkBinaryWriteBuffer(void* initialStorage, size_t storageSize, uint32_t flags = 0);
|
||||
~SkBinaryWriteBuffer() override;
|
||||
~SkBinaryWriteBuffer();
|
||||
|
||||
bool isCrossProcess() const override {
|
||||
return SkToBool(fFlags & kCrossProcess_Flag);
|
||||
|
@ -134,10 +134,12 @@ public:
|
|||
* Set an SkPixelSerializer to store an encoded representation of pixels,
|
||||
* e.g. SkBitmaps.
|
||||
*
|
||||
* Calls ref() on the serializer.
|
||||
*
|
||||
* TODO: Encode SkImage pixels as well.
|
||||
*/
|
||||
void setPixelSerializer(sk_sp<SkPixelSerializer>);
|
||||
SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer.get(); }
|
||||
void setPixelSerializer(SkPixelSerializer*);
|
||||
SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer; }
|
||||
|
||||
private:
|
||||
const uint32_t fFlags;
|
||||
|
@ -146,7 +148,7 @@ private:
|
|||
|
||||
SkRefCntSet* fTFSet;
|
||||
|
||||
sk_sp<SkPixelSerializer> fPixelSerializer;
|
||||
SkAutoTUnref<SkPixelSerializer> fPixelSerializer;
|
||||
|
||||
// Only used if we do not have an fFactorySet
|
||||
SkTHashMap<SkString, uint32_t> fFlattenableDict;
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkXfermodePriv_DEFINED
|
||||
#define SkXfermodePriv_DEFINED
|
||||
#ifndef SkXfermode_DEFINED
|
||||
#define SkXfermode_DEFINED
|
||||
|
||||
#include "SkBlendMode.h"
|
||||
#include "SkColor.h"
|
||||
|
@ -152,8 +152,16 @@ public:
|
|||
|
||||
/** Return an SkXfermode object for the specified mode.
|
||||
*/
|
||||
static sk_sp<SkXfermode> Make(SkBlendMode);
|
||||
static sk_sp<SkXfermode> Make(Mode m) { return Make((SkBlendMode)m); }
|
||||
static sk_sp<SkXfermode> Make(Mode);
|
||||
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
|
||||
static SkXfermode* Create(Mode mode) {
|
||||
return Make(mode).release();
|
||||
}
|
||||
SK_ATTR_DEPRECATED("use AsMode(...)")
|
||||
static bool IsMode(const SkXfermode* xfer, Mode* mode) {
|
||||
return AsMode(xfer, mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Skia maintains global xfermode objects corresponding to each BlendMode. This returns a
|
||||
|
@ -170,14 +178,25 @@ public:
|
|||
return xfer.get();
|
||||
}
|
||||
|
||||
static sk_sp<SkXfermode> Make(SkBlendMode bm) {
|
||||
return Make((Mode)bm);
|
||||
}
|
||||
|
||||
SkBlendMode blend() const {
|
||||
Mode mode;
|
||||
SkAssertResult(this->asMode(&mode));
|
||||
return (SkBlendMode)mode;
|
||||
}
|
||||
|
||||
static SkXfermodeProc GetProc(SkBlendMode);
|
||||
static SkXfermodeProc4f GetProc4f(SkBlendMode);
|
||||
/** Return a function pointer to a routine that applies the specified
|
||||
porter-duff transfer mode.
|
||||
*/
|
||||
static SkXfermodeProc GetProc(Mode mode);
|
||||
static SkXfermodeProc4f GetProc4f(Mode);
|
||||
|
||||
virtual SkXfermodeProc4f getProc4f() const;
|
||||
|
||||
bool appendStages(SkRasterPipeline*) const;
|
||||
|
||||
/**
|
||||
* If the specified mode can be represented by a pair of Coeff, then return
|
||||
|
@ -186,9 +205,6 @@ public:
|
|||
* src and dst parameters.
|
||||
*/
|
||||
static bool ModeAsCoeff(Mode mode, Coeff* src, Coeff* dst);
|
||||
static bool ModeAsCoeff(SkBlendMode mode, Coeff* src, Coeff* dst) {
|
||||
return ModeAsCoeff((Mode)mode, src, dst);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the xfer mode can support treating coverage as alpha
|
||||
|
@ -246,7 +262,7 @@ public:
|
|||
The xfermode will return a factory for which the caller will get a ref. It is up
|
||||
to the caller to install it. XferProcessors cannot use a background texture.
|
||||
*/
|
||||
virtual const GrXPFactory* asXPFactory() const;
|
||||
virtual sk_sp<GrXPFactory> asXPFactory() const;
|
||||
#endif
|
||||
|
||||
SK_TO_STRING_PUREVIRT()
|
||||
|
@ -258,17 +274,23 @@ public:
|
|||
kSrcIsSingle_D32Flag = 1 << 1,
|
||||
kDstIsSRGB_D32Flag = 1 << 2,
|
||||
};
|
||||
typedef void (*D32Proc)(SkBlendMode, uint32_t dst[], const SkPM4f src[],
|
||||
typedef void (*D32Proc)(const SkXfermode*, uint32_t dst[], const SkPM4f src[],
|
||||
int count, const SkAlpha coverage[]);
|
||||
static D32Proc GetD32Proc(SkBlendMode, uint32_t flags);
|
||||
static D32Proc GetD32Proc(SkXfermode*, uint32_t flags);
|
||||
static D32Proc GetD32Proc(const sk_sp<SkXfermode>& xfer, uint32_t flags) {
|
||||
return GetD32Proc(xfer.get(), flags);
|
||||
}
|
||||
|
||||
enum F16Flags {
|
||||
kSrcIsOpaque_F16Flag = 1 << 0,
|
||||
kSrcIsSingle_F16Flag = 1 << 1,
|
||||
};
|
||||
typedef void (*F16Proc)(SkBlendMode, uint64_t dst[], const SkPM4f src[], int count,
|
||||
typedef void (*F16Proc)(const SkXfermode*, uint64_t dst[], const SkPM4f src[], int count,
|
||||
const SkAlpha coverage[]);
|
||||
static F16Proc GetF16Proc(SkBlendMode, uint32_t flags);
|
||||
static F16Proc GetF16Proc(SkXfermode*, uint32_t flags);
|
||||
static F16Proc GetF16Proc(const sk_sp<SkXfermode>& xfer, uint32_t flags) {
|
||||
return GetF16Proc(xfer.get(), flags);
|
||||
}
|
||||
|
||||
enum LCDFlags {
|
||||
kSrcIsOpaque_LCDFlag = 1 << 0, // else src(s) may have alpha < 1
|
||||
|
@ -294,6 +316,10 @@ protected:
|
|||
*/
|
||||
virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst) const;
|
||||
|
||||
virtual D32Proc onGetD32Proc(uint32_t flags) const;
|
||||
virtual F16Proc onGetF16Proc(uint32_t flags) const;
|
||||
virtual bool onAppendStages(SkRasterPipeline*) const;
|
||||
|
||||
private:
|
||||
enum {
|
||||
kModeCount = kLastMode + 1
|
|
@ -8,8 +8,6 @@
|
|||
#ifndef SkYUVSizeInfo_DEFINED
|
||||
#define SkYUVSizeInfo_DEFINED
|
||||
|
||||
#include "SkSize.h"
|
||||
|
||||
struct SkYUVSizeInfo {
|
||||
enum {
|
||||
kY = 0,
|
||||
|
|
|
@ -58,6 +58,12 @@ public:
|
|||
*/
|
||||
static sk_sp<SkPathEffect> Make(const SkPath& path, SkScalar advance, SkScalar phase, Style);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
|
||||
static SkPathEffect* Create(const SkPath& path, SkScalar advance, SkScalar phase, Style s) {
|
||||
return Make(path, advance, phase, s).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual bool filterPath(SkPath*, const SkPath&,
|
||||
SkStrokeRec*, const SkRect*) const override;
|
||||
|
||||
|
|
|
@ -26,6 +26,13 @@ public:
|
|||
const SkImageFilter::CropRect* cropRect = nullptr);
|
||||
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
static SkImageFilter* Create(const SkRegion& region, SkScalar innerMin,
|
||||
SkScalar outerMax, SkImageFilter* input = nullptr) {
|
||||
return Make(region, innerMin, outerMax, sk_ref_sp<SkImageFilter>(input)).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP();
|
||||
};
|
||||
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Copyright 2016 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkArithmeticImageFilter_DEFINED
|
||||
#define SkArithmeticImageFilter_DEFINED
|
||||
|
||||
#include "SkImageFilter.h"
|
||||
|
||||
class SK_API SkArithmeticImageFilter {
|
||||
public:
|
||||
static sk_sp<SkImageFilter> Make(float k1, float k2, float k3, float k4, bool enforcePMColor,
|
||||
sk_sp<SkImageFilter> background,
|
||||
sk_sp<SkImageFilter> foreground,
|
||||
const SkImageFilter::CropRect* cropRect);
|
||||
static sk_sp<SkImageFilter> Make(float k1, float k2, float k3, float k4, bool enforcePMColor,
|
||||
sk_sp<SkImageFilter> background) {
|
||||
return Make(k1, k2, k3, k4, enforcePMColor, std::move(background), nullptr, nullptr);
|
||||
}
|
||||
|
||||
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP();
|
||||
|
||||
private:
|
||||
SkArithmeticImageFilter(); // can't instantiate
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkArithmeticMode_DEFINED
|
||||
#define SkArithmeticMode_DEFINED
|
||||
|
||||
#include "SkFlattenable.h"
|
||||
#include "SkScalar.h"
|
||||
#include "SkXfermode.h"
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_ARITHMETICMODE
|
||||
|
||||
class SK_API SkArithmeticMode {
|
||||
public:
|
||||
/**
|
||||
* result = clamp[k1 * src * dst + k2 * src + k3 * dst + k4]
|
||||
*
|
||||
* k1=k2=k3=0, k4=1.0 results in returning opaque white
|
||||
* k1=k3=k4=0, k2=1.0 results in returning the src
|
||||
* k1=k2=k4=0, k3=1.0 results in returning the dst
|
||||
*/
|
||||
static sk_sp<SkXfermode> Make(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4,
|
||||
bool enforcePMColor = true);
|
||||
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
|
||||
static SkXfermode* Create(SkScalar k1, SkScalar k2,
|
||||
SkScalar k3, SkScalar k4,
|
||||
bool enforcePMColor = true) {
|
||||
return Make(k1, k2, k3, k4, enforcePMColor).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP();
|
||||
|
||||
private:
|
||||
SkArithmeticMode(); // can't be instantiated
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -10,13 +10,85 @@
|
|||
#define SkBlurDrawLooper_DEFINED
|
||||
|
||||
#include "SkDrawLooper.h"
|
||||
#include "SkColor.h"
|
||||
|
||||
/**
|
||||
* Draws a shadow of the object (possibly offset), and then draws the original object in
|
||||
* its original position.
|
||||
*/
|
||||
namespace SkBlurDrawLooper {
|
||||
sk_sp<SkDrawLooper> Make(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy);
|
||||
class SkMaskFilter;
|
||||
class SkColorFilter;
|
||||
|
||||
/** \class SkBlurDrawLooper
|
||||
This class draws a shadow of the object (possibly offset), and then draws
|
||||
the original object in its original position.
|
||||
should there be an option to just draw the shadow/blur layer? webkit?
|
||||
*/
|
||||
class SK_API SkBlurDrawLooper : public SkDrawLooper {
|
||||
public:
|
||||
enum BlurFlags {
|
||||
kNone_BlurFlag = 0x00,
|
||||
/**
|
||||
The blur layer's dx/dy/radius aren't affected by the canvas
|
||||
transform.
|
||||
*/
|
||||
kIgnoreTransform_BlurFlag = 0x01,
|
||||
kOverrideColor_BlurFlag = 0x02,
|
||||
kHighQuality_BlurFlag = 0x04,
|
||||
/** mask for all blur flags */
|
||||
kAll_BlurFlag = 0x07
|
||||
};
|
||||
|
||||
static sk_sp<SkDrawLooper> Make(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
|
||||
uint32_t flags = kNone_BlurFlag) {
|
||||
return sk_sp<SkDrawLooper>(new SkBlurDrawLooper(color, sigma, dx, dy, flags));
|
||||
}
|
||||
#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
|
||||
static SkDrawLooper* Create(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
|
||||
uint32_t flags = kNone_BlurFlag) {
|
||||
return Make(color, sigma, dx, dy, flags).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const override;
|
||||
|
||||
size_t contextSize() const override { return sizeof(BlurDrawLooperContext); }
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurDrawLooper)
|
||||
|
||||
protected:
|
||||
SkBlurDrawLooper(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
|
||||
uint32_t flags);
|
||||
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
|
||||
bool asABlurShadow(BlurShadowRec*) const override;
|
||||
|
||||
private:
|
||||
sk_sp<SkMaskFilter> fBlur;
|
||||
sk_sp<SkColorFilter> fColorFilter;
|
||||
SkScalar fDx, fDy, fSigma;
|
||||
SkColor fBlurColor;
|
||||
uint32_t fBlurFlags;
|
||||
|
||||
enum State {
|
||||
kBeforeEdge,
|
||||
kAfterEdge,
|
||||
kDone
|
||||
};
|
||||
|
||||
class BlurDrawLooperContext : public SkDrawLooper::Context {
|
||||
public:
|
||||
explicit BlurDrawLooperContext(const SkBlurDrawLooper* looper);
|
||||
|
||||
bool next(SkCanvas* canvas, SkPaint* paint) override;
|
||||
|
||||
private:
|
||||
const SkBlurDrawLooper* fLooper;
|
||||
State fState;
|
||||
};
|
||||
|
||||
void init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color, uint32_t flags);
|
||||
void initEffects();
|
||||
|
||||
typedef SkDrawLooper INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,6 +17,15 @@ public:
|
|||
const SkImageFilter::CropRect* cropRect = nullptr) {
|
||||
return SkImageFilter::MakeBlur(sigmaX, sigmaY, input, cropRect);
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
static SkImageFilter* Create(SkScalar sigmaX, SkScalar sigmaY,
|
||||
SkImageFilter * input = nullptr,
|
||||
const SkImageFilter::CropRect* cropRect = nullptr) {
|
||||
return SkImageFilter::MakeBlur(sigmaX, sigmaY, sk_ref_sp<SkImageFilter>(input),
|
||||
cropRect).release();
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -22,13 +22,13 @@ public:
|
|||
static SkScalar ConvertRadiusToSigma(SkScalar radius);
|
||||
|
||||
enum BlurFlags {
|
||||
kNone_BlurFlag = 0x00,
|
||||
kNone_BlurFlag = 0x00,
|
||||
/** The blur layer's radius is not affected by transforms */
|
||||
kIgnoreTransform_BlurFlag = 0x01,
|
||||
/** Use a smother, higher qulity blur algorithm */
|
||||
kHighQuality_BlurFlag = 0x02,
|
||||
/** mask for all blur flags */
|
||||
kAll_BlurFlag = 0x03
|
||||
kAll_BlurFlag = 0x03
|
||||
};
|
||||
|
||||
/** Create a blur maskfilter.
|
||||
|
@ -48,7 +48,6 @@ public:
|
|||
return Make(style, sigma, SkRect::MakeEmpty(), flags);
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_EMBOSSMASKFILTER
|
||||
/** Create an emboss maskfilter
|
||||
@param blurSigma standard deviation of the Gaussian blur to apply
|
||||
before applying lighting (e.g. 3)
|
||||
|
@ -59,6 +58,19 @@ public:
|
|||
*/
|
||||
static sk_sp<SkMaskFilter> MakeEmboss(SkScalar blurSigma, const SkScalar direction[3],
|
||||
SkScalar ambient, SkScalar specular);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_MASKFILTER_PTR
|
||||
static SkMaskFilter* Create(SkBlurStyle style, SkScalar sigma, uint32_t flags = kNone_BlurFlag){
|
||||
return Make(style, sigma, flags).release();
|
||||
}
|
||||
static SkMaskFilter* CreateEmboss(SkScalar blurSigma, const SkScalar direction[3],
|
||||
SkScalar ambient, SkScalar specular) {
|
||||
return MakeEmboss(blurSigma, direction, ambient, specular).release();
|
||||
}
|
||||
SK_ATTR_DEPRECATED("use sigma version")
|
||||
static SkMaskFilter* CreateEmboss(const SkScalar direction[3],
|
||||
SkScalar ambient, SkScalar specular,
|
||||
SkScalar blurRadius);
|
||||
#endif
|
||||
|
||||
static const int kMaxDivisions = 6;
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright 2014 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkColorCubeFilter_DEFINED
|
||||
#define SkColorCubeFilter_DEFINED
|
||||
|
||||
#include "SkColorFilter.h"
|
||||
#include "SkData.h"
|
||||
#include "../private/SkOnce.h"
|
||||
#include "../private/SkTemplates.h"
|
||||
|
||||
class SK_API SkColorCubeFilter : public SkColorFilter {
|
||||
public:
|
||||
/** cubeData must containt a 3D data in the form of cube of the size:
|
||||
* cubeDimension * cubeDimension * cubeDimension * sizeof(SkColor)
|
||||
* This cube contains a transform where (x,y,z) maps to the (r,g,b).
|
||||
* The alpha components of the colors must be 0xFF.
|
||||
*/
|
||||
static sk_sp<SkColorFilter> Make(sk_sp<SkData> cubeData, int cubeDimension);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
|
||||
static SkColorFilter* Create(SkData* cubeData, int cubeDimension);
|
||||
#endif
|
||||
|
||||
void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override;
|
||||
uint32_t getFlags() const override;
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*) const override;
|
||||
#endif
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorCubeFilter)
|
||||
|
||||
protected:
|
||||
SkColorCubeFilter(sk_sp<SkData> cubeData, int cubeDimension);
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
|
||||
private:
|
||||
/** The cache is initialized on-demand when getProcessingLuts is called.
|
||||
*/
|
||||
class ColorCubeProcesingCache {
|
||||
public:
|
||||
ColorCubeProcesingCache(int cubeDimension);
|
||||
|
||||
void getProcessingLuts(const int* (*colorToIndex)[2],
|
||||
const SkScalar* (*colorToFactors)[2],
|
||||
const SkScalar** colorToScalar);
|
||||
|
||||
int cubeDimension() const { return fCubeDimension; }
|
||||
|
||||
private:
|
||||
// Working pointers. If any of these is NULL,
|
||||
// we need to recompute the corresponding cache values.
|
||||
int* fColorToIndex[2];
|
||||
SkScalar* fColorToFactors[2];
|
||||
SkScalar* fColorToScalar;
|
||||
|
||||
SkAutoTMalloc<uint8_t> fLutStorage;
|
||||
|
||||
const int fCubeDimension;
|
||||
|
||||
// Make sure we only initialize the caches once.
|
||||
SkOnce fLutsInitOnce;
|
||||
|
||||
static void initProcessingLuts(ColorCubeProcesingCache* cache);
|
||||
};
|
||||
|
||||
sk_sp<SkData> fCubeData;
|
||||
int32_t fUniqueID;
|
||||
|
||||
mutable ColorCubeProcesingCache fCache;
|
||||
|
||||
typedef SkColorFilter INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -21,11 +21,20 @@ public:
|
|||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorFilterImageFilter)
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
static SkImageFilter* Create(SkColorFilter* cf,
|
||||
SkImageFilter* input = NULL,
|
||||
const CropRect* cropRect = NULL) {
|
||||
return Make(sk_ref_sp<SkColorFilter>(cf),
|
||||
sk_ref_sp<SkImageFilter>(input),
|
||||
cropRect).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
|
||||
SkIPoint* offset) const override;
|
||||
sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const override;
|
||||
bool onIsColorFilterNode(SkColorFilter**) const override;
|
||||
bool onCanHandleComplexCTM() const override { return true; }
|
||||
bool affectsTransparentBlack() const override;
|
||||
|
|
|
@ -20,6 +20,18 @@ public:
|
|||
* are ignored.
|
||||
*/
|
||||
static sk_sp<SkColorFilter> MakeLightingFilter(SkColor mul, SkColor add);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
|
||||
static SkColorFilter* Create(const SkColorMatrix& cm) {
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat).release();
|
||||
}
|
||||
static SkColorFilter* Create(const SkScalar array[20]) {
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(array).release();
|
||||
}
|
||||
static SkColorFilter* CreateLightingFilter(SkColor mul, SkColor add) {
|
||||
return MakeLightingFilter(mul, add).release();
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,6 +19,13 @@ public:
|
|||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeImageFilter)
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
static SkImageFilter* Create(SkImageFilter* outer, SkImageFilter* inner) {
|
||||
return Make(sk_ref_sp<SkImageFilter>(outer),
|
||||
sk_ref_sp<SkImageFilter>(inner)).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
explicit SkComposeImageFilter(sk_sp<SkImageFilter> inputs[2]) : INHERITED(inputs, 2, nullptr) {
|
||||
SkASSERT(inputs[0].get());
|
||||
|
@ -26,7 +33,6 @@ protected:
|
|||
}
|
||||
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
|
||||
SkIPoint* offset) const override;
|
||||
sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const override;
|
||||
SkIRect onFilterBounds(const SkIRect&, const SkMatrix&, MapDirection) const override;
|
||||
bool onCanHandleComplexCTM() const override { return true; }
|
||||
|
||||
|
|
|
@ -24,6 +24,12 @@ public:
|
|||
return sk_sp<SkPathEffect>(new SkCornerPathEffect(radius));
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
|
||||
static SkPathEffect* Create(SkScalar radius) {
|
||||
return Make(radius).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual bool filterPath(SkPath* dst, const SkPath& src,
|
||||
SkStrokeRec*, const SkRect*) const override;
|
||||
|
||||
|
@ -35,7 +41,7 @@ public:
|
|||
#endif
|
||||
|
||||
protected:
|
||||
~SkCornerPathEffect() override;
|
||||
virtual ~SkCornerPathEffect();
|
||||
|
||||
explicit SkCornerPathEffect(SkScalar radius);
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
|
|
|
@ -38,6 +38,12 @@ public:
|
|||
*/
|
||||
static sk_sp<SkPathEffect> Make(const SkScalar intervals[], int count, SkScalar phase);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
|
||||
static SkPathEffect* Create(const SkScalar intervals[], int count, SkScalar phase) {
|
||||
return Make(intervals, count, phase).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual bool filterPath(SkPath* dst, const SkPath& src,
|
||||
SkStrokeRec*, const SkRect*) const override;
|
||||
|
||||
|
@ -55,7 +61,7 @@ public:
|
|||
#endif
|
||||
|
||||
protected:
|
||||
~SkDashPathEffect() override;
|
||||
virtual ~SkDashPathEffect();
|
||||
SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase);
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
|
||||
|
|
|
@ -31,6 +31,12 @@ public:
|
|||
*/
|
||||
static sk_sp<SkPathEffect> Make(SkScalar segLength, SkScalar dev, uint32_t seedAssist = 0);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
|
||||
static SkPathEffect* Create(SkScalar segLength, SkScalar deviation, uint32_t seedAssist = 0) {
|
||||
return Make(segLength, deviation, seedAssist).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual bool filterPath(SkPath* dst, const SkPath& src,
|
||||
SkStrokeRec*, const SkRect*) const override;
|
||||
|
||||
|
|
|
@ -35,11 +35,23 @@ public:
|
|||
|
||||
virtual SkIRect onFilterBounds(const SkIRect& src, const SkMatrix&,
|
||||
MapDirection) const override;
|
||||
sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const override;
|
||||
SkIRect onFilterNodeBounds(const SkIRect&, const SkMatrix&, MapDirection) const override;
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
static SkImageFilter* Create(ChannelSelectorType xChannelSelector,
|
||||
ChannelSelectorType yChannelSelector,
|
||||
SkScalar scale, SkImageFilter* displacement,
|
||||
SkImageFilter* color = nullptr,
|
||||
const CropRect* cropRect = nullptr) {
|
||||
return Make(xChannelSelector, yChannelSelector, scale,
|
||||
sk_ref_sp<SkImageFilter>(displacement),
|
||||
sk_ref_sp<SkImageFilter>(color),
|
||||
cropRect).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
|
||||
SkIPoint* offset) const override;
|
||||
|
|
|
@ -32,11 +32,20 @@ public:
|
|||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDropShadowImageFilter)
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
static SkImageFilter* Create(SkScalar dx, SkScalar dy, SkScalar sigmaX, SkScalar sigmaY,
|
||||
SkColor color, ShadowMode shadowMode,
|
||||
SkImageFilter* input = nullptr,
|
||||
const CropRect* cropRect = nullptr) {
|
||||
return Make(dx, dy, sigmaX, sigmaY, color, shadowMode,
|
||||
sk_ref_sp<SkImageFilter>(input), cropRect).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
|
||||
SkIPoint* offset) const override;
|
||||
sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const override;
|
||||
SkIRect onFilterNodeBounds(const SkIRect& src, const SkMatrix&, MapDirection) const override;
|
||||
|
||||
private:
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче