Bug 1340627 - part 1 - update Skia source to m59. r=mchang

--HG--
rename : gfx/skia/skia/src/gpu/glsl/GrGLSL_impl.h => gfx/skia/skia/include/private/GrGLSL_impl.h
rename : gfx/skia/skia/src/core/SkMessageBus.h => gfx/skia/skia/include/private/SkMessageBus.h
rename : gfx/skia/skia/include/core/SkBlitRow.h => gfx/skia/skia/src/core/SkBlitRow.h
rename : gfx/skia/skia/include/effects/SkGaussianEdgeShader.h => gfx/skia/skia/src/effects/SkGaussianEdgeShader.h
rename : gfx/skia/skia/src/gpu/batches/GrAAConvexPathRenderer.h => gfx/skia/skia/src/gpu/ops/GrAAConvexPathRenderer.h
rename : gfx/skia/skia/src/gpu/batches/GrAAConvexTessellator.h => gfx/skia/skia/src/gpu/ops/GrAAConvexTessellator.h
rename : gfx/skia/skia/src/gpu/batches/GrAAHairLinePathRenderer.h => gfx/skia/skia/src/gpu/ops/GrAAHairLinePathRenderer.h
rename : gfx/skia/skia/src/gpu/batches/GrAALinearizingConvexPathRenderer.h => gfx/skia/skia/src/gpu/ops/GrAALinearizingConvexPathRenderer.h
rename : gfx/skia/skia/src/gpu/batches/GrPathStencilSettings.h => gfx/skia/skia/src/gpu/ops/GrPathStencilSettings.h
rename : gfx/skia/skia/src/gpu/batches/GrStencilAndCoverPathRenderer.h => gfx/skia/skia/src/gpu/ops/GrStencilAndCoverPathRenderer.h
rename : gfx/skia/skia/include/xml/SkXMLParser.h => gfx/skia/skia/src/xml/SkXMLParser.h
This commit is contained in:
Lee Salzman 2017-05-09 22:30:58 -04:00
Родитель a2d1a04aa1
Коммит e83e20fa0f
1665 изменённых файлов: 124250 добавлений и 96668 удалений

Просмотреть файл

@ -10,7 +10,7 @@
#include "SkBitmap.h"
#include "SkBRDAllocator.h"
#include "SkEncodedFormat.h"
#include "SkEncodedImageFormat.h"
#include "SkStream.h"
/*
@ -55,18 +55,21 @@ 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) = 0;
SkColorType colorType, bool requireUnpremul,
sk_sp<SkColorSpace> prefColorSpace = nullptr) = 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 SkEncodedFormat getEncodedFormat() = 0;
virtual SkEncodedImageFormat getEncodedFormat() = 0;
int width() const { return fWidth; }
int height() const { return fHeight; }

Просмотреть файл

@ -1,501 +0,0 @@
/*
* 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

Просмотреть файл

@ -1,39 +0,0 @@
/*
* 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();
SK_API sk_data_t* sk_data_new_empty(void);
/**
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();
SK_API sk_paint_t* sk_paint_new(void);
/**
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();
SK_API sk_path_t* sk_path_new(void);
/** 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();
sk_picture_recorder_t* sk_picture_recorder_new(void);
/**
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();
SK_API sk_colortype_t sk_colortype_get_default_8888(void);
typedef struct {
int32_t width;
@ -113,6 +113,59 @@ 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 "SkEncodedFormat.h"
#include "SkEncodedImageFormat.h"
#include "SkStream.h"
#include "SkTypes.h"
@ -51,14 +51,18 @@ public:
/**
* Format of the encoded data.
*/
SkEncodedFormat getEncodedFormat() const { return fCodec->getEncodedFormat(); }
SkEncodedImageFormat getEncodedFormat() const { return fCodec->getEncodedFormat(); }
/**
* @param requestedColorType Color type requested by the client
*
* 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.
* |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.
*/
SkColorType computeOutputColorType(SkColorType requestedColorType);
@ -71,6 +75,19 @@ 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.
@ -154,7 +171,7 @@ public:
*
* Must be within the bounds returned by getInfo().
*
* If the EncodedFormat is kWEBP_SkEncodedFormat, the top and left
* If the EncodedFormat is SkEncodedImageFormat::kWEBP, the top and left
* values must be even.
*
* The default is NULL, meaning a decode of the entire image.
@ -260,6 +277,6 @@ private:
// embedded SkCodec.
const SkImageInfo& fInfo;
SkAutoTDelete<SkCodec> fCodec;
std::unique_ptr<SkCodec> fCodec;
};
#endif // SkAndroidCodec_DEFINED

Просмотреть файл

@ -10,7 +10,7 @@
#include "../private/SkTemplates.h"
#include "SkColor.h"
#include "SkEncodedFormat.h"
#include "SkEncodedImageFormat.h"
#include "SkEncodedInfo.h"
#include "SkImageInfo.h"
#include "SkSize.h"
@ -18,7 +18,10 @@
#include "SkTypes.h"
#include "SkYUVSizeInfo.h"
#include <vector>
class SkColorSpace;
class SkColorSpaceXform;
class SkData;
class SkPngChunkReader;
class SkSampler;
@ -32,7 +35,7 @@ class ColorCodecBench;
/**
* Abstraction layer directly on top of an image codec.
*/
class SkCodec : SkNoncopyable {
class SK_API SkCodec : SkNoncopyable {
public:
/**
* Minimum number of bytes that must be buffered in SkStream input.
@ -173,7 +176,7 @@ public:
/**
* Format of the encoded data.
*/
SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat(); }
SkEncodedImageFormat getEncodedFormat() const { return this->onGetEncodedFormat(); }
/**
* Used to describe the result of a call to getPixels().
@ -243,14 +246,17 @@ public:
struct Options {
Options()
: fZeroInitialized(kNo_ZeroInitialized)
, fSubset(NULL)
, fSubset(nullptr)
, fFrameIndex(0)
, fHasPriorFrame(false)
, fPremulBehavior(SkTransferFunctionBehavior::kRespect)
{}
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 kWEBP_SkEncodedFormat (the only one which
* If the EncodedFormat is SkEncodedImageFormat::kWEBP (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
@ -264,7 +270,41 @@ public:
* subset left and subset width to decode partial scanlines on calls
* to getScanlines().
*/
SkIRect* fSubset;
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;
};
/**
@ -522,19 +562,6 @@ 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,
};
/**
@ -550,7 +577,7 @@ public:
* decoder.
*
* This will equal fCurrScanline, except in the case of strangely
* encoded image types (bottom-up bmps, interlaced gifs).
* encoded image types (bottom-up bmps).
*
* Results are undefined when not in scanline decoding mode.
*/
@ -566,6 +593,87 @@ 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*
@ -574,7 +682,7 @@ protected:
int height,
const SkEncodedInfo&,
SkStream*,
sk_sp<SkColorSpace> = nullptr,
sk_sp<SkColorSpace>,
Origin = kTopLeft_Origin);
/**
@ -600,7 +708,7 @@ protected:
return false;
}
virtual SkEncodedFormat onGetEncodedFormat() const = 0;
virtual SkEncodedImageFormat onGetEncodedFormat() const = 0;
/**
* @param rowsDecoded When the encoded image stream is incomplete, this function
@ -706,25 +814,42 @@ protected:
virtual int onOutputScanline(int inputScanline) const;
/**
* 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;
SkAutoTDelete<SkStream> fStream;
bool fNeedsRewind;
const Origin fOrigin;
bool initializeColorXform(const SkImageInfo& dstInfo,
SkTransferFunctionBehavior premulBehavior);
SkColorSpaceXform* colorXform() const { return fColorXform.get(); }
SkImageInfo fDstInfo;
SkCodec::Options fOptions;
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); }
private:
const SkEncodedInfo fEncodedInfo;
const SkImageInfo fSrcInfo;
std::unique_ptr<SkStream> fStream;
bool fNeedsRewind;
const Origin fOrigin;
SkImageInfo fDstInfo;
SkCodec::Options fOptions;
std::unique_ptr<SkColorSpaceXform> fColorXform;
// Only meaningful during scanline decodes.
int fCurrScanline;
int fCurrScanline;
bool fStartedIncrementalDecode;
bool fStartedIncrementalDecode;
#ifdef SK_DEBUG
bool fUnsupportedICC = false;
#endif
/**
* Return whether these dimensions are supported as a scale.
@ -782,17 +907,14 @@ private:
* May create a sampler, if one is not currently being used. Otherwise, does
* not affect ownership.
*
* Only valid during scanline decoding.
* Only valid during scanline decoding or incremental 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

Просмотреть файл

@ -1,28 +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 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,10 +93,6 @@
*/
//#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
@ -161,8 +157,6 @@
#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")))
@ -171,4 +165,6 @@
# endif
#endif
#define MOZ_SKIA
#endif

Просмотреть файл

@ -20,8 +20,6 @@ struct SkIRect;
struct SkRect;
class SkPaint;
class SkPixelRef;
class SkPixelRefFactory;
class SkRegion;
class SkString;
/** \class SkBitmap
@ -33,6 +31,8 @@ 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,6 +85,7 @@ 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
@ -117,7 +118,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 NULL == fPixelRef; }
bool isNull() const { return nullptr == fPixelRef; }
/** Return true iff drawing this bitmap has no effect.
*/
@ -215,7 +216,10 @@ public:
* this (isOpaque). Only call this if you need to compute this value from
* "unknown" pixels.
*/
static bool ComputeIsOpaque(const SkBitmap&);
static bool ComputeIsOpaque(const SkBitmap& bm) {
SkAutoPixmapUnlock result;
return bm.requestLock(&result) && result.pixmap().computeIsOpaque();
}
/**
* Return the bitmap's bounds [0, 0, width, height] as an SkRect
@ -233,16 +237,20 @@ 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, and will be ref'd.
* a colortable, then ColorTable must be non-null.
*
* On failure, the bitmap will be set to empty and return false.
*/
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)) {
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)) {
sk_throw();
}
}
@ -283,6 +291,11 @@ 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
@ -332,27 +345,6 @@ 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
@ -404,7 +396,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; }
SkPixelRef* pixelRef() const { return fPixelRef.get(); }
/**
* A bitmap can reference a subset of a pixelref's pixels. That means the
@ -420,21 +412,12 @@ public:
SkIPoint pixelRefOrigin() const { return fPixelRefOrigin; }
/**
* 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).
* 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).
*/
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);
}
void setPixelRef(sk_sp<SkPixelRef>, int dx, int dy);
/** 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
@ -448,15 +431,6 @@ 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.
@ -525,13 +499,19 @@ public:
}
/**
* 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()).
* 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())..
*/
SkColor getColor(int x, int y) const;
SkColor getColor(int x, int y) const {
SkPixmap pixmap;
SkAssertResult(this->peekPixels(&pixmap));
return pixmap.getColor(x, y);
}
/** 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
@ -586,6 +566,7 @@ 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
@ -598,11 +579,26 @@ public:
* will be used.
* @return true if the copy was made.
*/
bool copyTo(SkBitmap* dst, SkColorType ct, Allocator* = NULL) const;
bool copyTo(SkBitmap* dst, SkColorType ct, Allocator*) const;
bool copyTo(SkBitmap* dst, Allocator* allocator = NULL) const {
bool copyTo(SkBitmap* dst, Allocator* allocator) 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),
@ -625,6 +621,23 @@ 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
@ -715,37 +728,16 @@ 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 SkPixelRef* fPixelRef;
mutable int fPixelLockCount;
mutable sk_sp<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,
@ -758,9 +750,13 @@ private:
#endif
};
SkImageInfo fInfo;
uint32_t fRowBytes;
uint8_t fFlags;
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;
/* Unreference any pixelrefs or colortables
*/
@ -770,6 +766,7 @@ 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;

Просмотреть файл

@ -8,6 +8,8 @@
#ifndef SkBlendMode_DEFINED
#define SkBlendMode_DEFINED
#include "SkTypes.h"
enum class SkBlendMode {
kClear, //!< [0, 0]
kSrc, //!< [Sa, Sc]
@ -48,4 +50,9 @@ enum class SkBlendMode {
kLastMode = kLuminosity
};
/**
* Return the (c-string) name of the blendmode.
*/
SK_API const char* SkBlendMode_Name(SkBlendMode);
#endif

Просмотреть файл

@ -8,42 +8,41 @@
#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 "SkRefCnt.h"
#include "SkRegion.h"
#include "SkRasterHandleAllocator.h"
#include "SkSurfaceProps.h"
#include "SkXfermode.h"
#include "SkLights.h"
#include "../private/SkShadowParams.h"
class GrContext;
class GrDrawContext;
class GrRenderTargetContext;
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;
//#define SK_SUPPORT_LEGACY_CLIP_REGIONOPS
class SkVertices;
/** \class SkCanvas
@ -60,31 +59,12 @@ class SkTextBlob;
color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns),
etc.
*/
class SK_API SkCanvas : public SkRefCnt {
class SK_API SkCanvas : SkNoncopyable {
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
@ -100,10 +80,11 @@ public:
* Note: it is valid to request a supported ImageInfo, but with zero
* dimensions.
*/
static SkCanvas* NewRasterDirect(const SkImageInfo&, void*, size_t);
static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo&, void*, size_t);
static SkCanvas* NewRasterDirectN32(int width, int height, SkPMColor* pixels, size_t rowBytes) {
return NewRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels,
size_t rowBytes) {
return MakeRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
}
/**
@ -131,6 +112,19 @@ 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.
@ -171,45 +165,6 @@ 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,
@ -220,9 +175,6 @@ 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.
@ -245,6 +197,8 @@ 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
@ -258,10 +212,6 @@ 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
@ -379,6 +329,9 @@ 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
@ -500,26 +453,37 @@ 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, ClipOp, bool doAntiAlias);
void clipRect(const SkRect& rect, ClipOp op) {
void clipRect(const SkRect& rect, SkClipOp, bool doAntiAlias);
void clipRect(const SkRect& rect, SkClipOp op) {
this->clipRect(rect, op, false);
}
void clipRect(const SkRect& rect, bool doAntiAlias = false) {
this->clipRect(rect, kIntersect_Op, doAntiAlias);
this->clipRect(rect, SkClipOp::kIntersect, 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, ClipOp op, bool doAntiAlias);
void clipRRect(const SkRRect& rrect, ClipOp op) {
void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias);
void clipRRect(const SkRRect& rrect, SkClipOp op) {
this->clipRRect(rrect, op, false);
}
void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) {
this->clipRRect(rrect, kIntersect_Op, doAntiAlias);
this->clipRRect(rrect, SkClipOp::kIntersect, doAntiAlias);
}
/**
@ -528,12 +492,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, ClipOp op, bool doAntiAlias);
void clipPath(const SkPath& path, ClipOp op) {
void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias);
void clipPath(const SkPath& path, SkClipOp op) {
this->clipPath(path, op, false);
}
void clipPath(const SkPath& path, bool doAntiAlias = false) {
this->clipPath(path, kIntersect_Op, doAntiAlias);
this->clipPath(path, SkClipOp::kIntersect, doAntiAlias);
}
/** EXPERIMENTAL -- only used for testing
@ -550,7 +514,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, ClipOp op = kIntersect_Op);
void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect);
/** Return true if the specified rectangle, after being transformed by the
current matrix, would lie completely outside of the current clip. Call
@ -574,34 +538,33 @@ public:
*/
bool quickReject(const SkPath& path) const;
/** 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;
/**
* 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 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);
/**
* 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();
}
#endif
/** Fill the entire canvas' bitmap (restricted to the current clip) with the
specified color and mode.
@ -609,11 +572,6 @@ 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
@ -676,18 +634,10 @@ public:
*/
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint);
/** Helper method for drawing a single point. See drawPoints() for a more
details.
*/
/** Helper method for drawing a single point. See drawPoints() for 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.
@ -697,8 +647,7 @@ 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.
@ -718,17 +667,6 @@ 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
@ -765,8 +703,7 @@ 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
@ -792,8 +729,7 @@ 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.
@ -1176,48 +1112,16 @@ public:
}
#endif
enum VertexMode {
kTriangles_VertexMode,
kTriangleStrip_VertexMode,
kTriangleFan_VertexMode
};
/** Draw vertices from an immutable SkVertices object.
/** 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 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.
@param paint Specifies the shader/texture if present.
*/
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);
}
*/
void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint);
void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint);
/**
Draw a cubic coons patch
@ -1228,15 +1132,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 xmode specifies how are the colors and the textures combined if both of them are
@param mode 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], 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);
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);
}
/**
@ -1247,32 +1151,30 @@ 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 SkXfermode::Mode).
* corresponding quad (via the specified SkBlendMode).
*
* 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 xfermode are used to affect each of the quads.
* and blendmode are used to affect each of the quads.
*/
void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
const SkColor colors[], int count, SkXfermode::Mode, const SkRect* cullRect,
const SkColor colors[], int count, SkBlendMode, 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, 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);
this->drawAtlas(atlas, xform, tex, nullptr, count, SkBlendMode::kDst, cullRect, 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, SkXfermode::kDst_Mode,
this->drawAtlas(atlas.get(), xform, tex, nullptr, count, SkBlendMode::kDst,
cullRect, paint);
}
@ -1351,15 +1253,7 @@ public:
*/
const SkMatrix& getTotalMatrix() const;
/** 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;
}
#ifdef SK_SUPPORT_OBSOLETE_REPLAYCLIP
typedef SkCanvasClipVisitor ClipVisitor;
/**
* Replays the clip operations, back to front, that have been applied to
@ -1367,11 +1261,12 @@ public:
* clip. All clips have already been transformed into device space.
*/
void replayClips(ClipVisitor*) const;
#endif
///////////////////////////////////////////////////////////////////////////
// don't call
GrDrawContext* internal_private_accessTopLayerDrawContext();
GrRenderTargetContext* internal_private_accessTopLayerRenderTargetContext();
// don't call
static void Internal_Private_SetIgnoreSaveLayerBounds(bool);
@ -1393,6 +1288,12 @@ 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.
@ -1437,6 +1338,10 @@ 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&);
@ -1460,7 +1365,7 @@ protected:
const SkPaint& paint);
virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
const SkPoint texCoords[4], SkBlendMode, const SkPaint& paint);
virtual void onDrawDrawable(SkDrawable*, const SkMatrix*);
@ -1472,12 +1377,9 @@ protected:
const SkPaint&);
virtual void onDrawRRect(const SkRRect&, const SkPaint&);
virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], 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 onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&);
virtual void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
int count, SkXfermode::Mode, const SkRect* cull, const SkPaint*);
int count, SkBlendMode, 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*,
@ -1500,10 +1402,10 @@ protected:
kSoft_ClipEdgeStyle
};
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 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 onDiscard();
@ -1515,12 +1417,6 @@ 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
@ -1551,7 +1447,7 @@ private:
SkBaseDevice* device() const;
const SkMatrix& matrix() const;
const SkRasterClip& clip() const;
void clip(SkRegion*) const;
const SkPaint& paint() const;
int x() const;
int y() const;
@ -1567,13 +1463,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 SkMatrix& ctm,
const SkClipStack* clipStack);
SkBaseDevice* dst, const SkIPoint& dstOrigin,
const SkMatrix& ctm);
enum ShaderOverrideOpacity {
kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitmap or image)
@ -1590,9 +1486,13 @@ 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;
@ -1600,7 +1500,7 @@ private:
enum {
kMCRecSize = 128, // most recent measurement
kMCRecCount = 32, // common depth for save/restores
kDeviceCMSize = 176, // most recent measurement
kDeviceCMSize = 184, // most recent measurement
};
intptr_t fMCRecStorage[kMCRecSize * kMCRecCount / sizeof(intptr_t)];
intptr_t fDeviceCMStorage[kDeviceCMSize / sizeof(intptr_t)];
@ -1610,6 +1510,7 @@ private:
int fSaveCount; // value returned by getSaveCount()
SkMetaData* fMetaData;
std::unique_ptr<SkRasterHandleAllocator> fAllocator;
SkSurface_Base* fSurfaceBase;
SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
@ -1619,8 +1520,7 @@ private:
friend class SkSurface_Base;
friend class SkSurface_Gpu;
bool fDeviceCMDirty; // cleared by updateDeviceCMCache()
void updateDeviceCMCache();
SkIRect fClipRestrictionRect = SkIRect::MakeEmpty();
void doSave();
void checkForDeferredSave();
@ -1628,15 +1528,17 @@ 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; // InitFlags
friend class SkLiteRecorder; // InitFlags
friend class SkNoSaveLayerCanvas; // InitFlags
friend class SkRecorder; // resetForNextPicture
friend class SkLiteRecorder; // resetForNextPicture
friend class SkNoDrawCanvas; // 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,
@ -1644,6 +1546,8 @@ private:
};
SkCanvas(const SkIRect& bounds, InitFlags);
SkCanvas(SkBaseDevice* device, InitFlags);
SkCanvas(const SkBitmap&, std::unique_ptr<SkRasterHandleAllocator>,
SkRasterHandleAllocator::Handle);
void resetForNextPicture(const SkIRect& bounds);
@ -1673,14 +1577,6 @@ 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
@ -1694,6 +1590,11 @@ 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
@ -1704,7 +1605,6 @@ private:
bool fAllowSoftClip;
bool fAllowSimplifyClip;
const bool fConservativeRasterClip;
class AutoValidateClip : ::SkNoncopyable {
public:
@ -1763,12 +1663,14 @@ private:
};
#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
#ifdef SK_SUPPORT_OBSOLETE_REPLAYCLIP
class SkCanvasClipVisitor {
public:
virtual ~SkCanvasClipVisitor();
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;
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;
};
#endif
#endif

Просмотреть файл

@ -1,89 +0,0 @@
/*
* 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,17 +10,20 @@
#include "SkTypes.h"
// these kept in SkRegion::Op order for now ...
enum SkClipOp {
kDifference_SkClipOp = 0,
kIntersect_SkClipOp = 1,
// SkClipOp enum values always match the corresponding values in SkRegion::Op
enum class SkClipOp {
kDifference = 0,
kIntersect = 1,
// Goal: remove these, since they can grow the current clip
kUnion_SkClipOp = 2,
kXOR_SkClipOp = 3,
kReverseDifference_SkClipOp = 4,
kReplace_SkClipOp = 5,
kUnion_deprecated = 2,
kXOR_deprecated = 3,
kReverseDifference_deprecated = 4,
kReplace_deprecated = 5,
kMax_EnumValue = kReplace_deprecated,
};
#endif

Просмотреть файл

@ -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 inline SkColor SkColorSetA(SkColor c, U8CPU a) {
static constexpr inline SkColor SkColorSetA(SkColor c, U8CPU a) {
return (c & 0x00FFFFFF) | (a << 24);
}
@ -183,6 +183,7 @@ 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,14 +8,16 @@
#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;
/**
@ -33,7 +35,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, SkXfermode::Mode* mode) const;
virtual bool asColorMode(SkColor* color, SkBlendMode* bmode) const;
/**
* If the filter can be represented by a 5x4 matrix, this
@ -71,7 +73,8 @@ public:
virtual void filterSpan4f(const SkPM4f src[], int count, SkPM4f result[]) const;
bool appendStages(SkRasterPipeline*) const;
bool appendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
bool shaderIsOpaque) const;
enum Flags {
/** If set the filter methods will not change the alpha channel of the colors.
@ -109,15 +112,12 @@ 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 xfermode mode that is applied to each color in
@param mode The blend 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, SkXfermode::Mode mode);
static sk_sp<SkColorFilter> MakeModeFilter(SkColor c, SkBlendMode mode) {
return MakeModeFilter(c, (SkXfermode::Mode)mode);
}
static sk_sp<SkColorFilter> MakeModeFilter(SkColor c, SkBlendMode 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,21 +134,6 @@ 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
@ -159,7 +144,8 @@ public:
*
* A null return indicates that the color filter isn't implemented for the GPU backend.
*/
virtual sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*) const;
virtual sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*,
SkColorSpace* dstColorSpace) const;
#endif
bool affectsTransparentBlack() const {
@ -174,7 +160,8 @@ public:
protected:
SkColorFilter() {}
virtual bool onAppendStages(SkRasterPipeline*) const;
virtual bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
bool shaderIsOpaque) const;
private:
/*

Просмотреть файл

@ -204,12 +204,8 @@ 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)
@ -584,22 +580,13 @@ 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;
@ -611,7 +598,6 @@ 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,31 +13,62 @@
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:
/**
* Common, named profiles that we can recognize.
* Create the sRGB color space.
*/
enum Named : uint8_t {
/**
* By far the most common color space.
* This is the default space for images, unmarked content, and monitors.
*/
kSRGB_Named,
static sk_sp<SkColorSpace> MakeSRGB();
/**
* 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,
};
/**
* 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();
enum RenderTargetGamma : uint8_t {
kLinear_RenderTargetGamma,
@ -49,28 +80,34 @@ public:
kSRGB_RenderTargetGamma,
};
/**
* 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);
enum Gamut {
kSRGB_Gamut,
kAdobeRGB_Gamut,
kDCIP3_D65_Gamut,
kRec2020_Gamut,
};
/**
* Create a common, named SkColorSpace.
* 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.
*/
static sk_sp<SkColorSpace> NewNamed(Named);
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);
/**
* Create an SkColorSpace from an ICC profile.
*/
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();
static sk_sp<SkColorSpace> MakeICC(const void*, size_t);
/**
* 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;
@ -79,6 +116,34 @@ 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.
@ -103,4 +168,17 @@ 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

Просмотреть файл

@ -0,0 +1,67 @@
/*
* 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

Просмотреть файл

@ -0,0 +1,20 @@
/*
* 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,10 +24,12 @@
*/
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);
virtual ~SkColorTable();
~SkColorTable() override;
/** Returns the number of colors in the table.
*/
@ -52,7 +54,7 @@ public:
void writeToBuffer(SkWriteBuffer&) const;
// may return null
static SkColorTable* Create(SkReadBuffer&);
static sk_sp<SkColorTable> Create(SkReadBuffer&);
private:
enum AllocatedWithMalloc {

Просмотреть файл

@ -0,0 +1,68 @@
/*
* 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,14 +168,8 @@ private:
explicit SkData(size_t size); // inplace new/delete
~SkData();
// 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); }
// Ensure the unsized delete is called.
void operator delete(void* p) { ::operator delete(p); }
// Called the first time someone calls NewEmpty to initialize the singleton.
friend SkData* sk_new_empty_data();

Просмотреть файл

@ -9,7 +9,6 @@
#define SkDataTable_DEFINED
#include "../private/SkTDArray.h"
#include "SkChunkAlloc.h"
#include "SkData.h"
#include "SkString.h"
@ -117,58 +116,4 @@ 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

Просмотреть файл

@ -19,6 +19,10 @@
class SkCanvas;
class SkWStream;
#ifdef SK_BUILD_FOR_WIN
struct IXpsOMObjectFactory;
#endif
/** SK_ScalarDefaultDPI is 72 DPI.
*/
#define SK_ScalarDefaultRasterDPI 72.0f
@ -46,7 +50,7 @@ public:
*/
struct PDFMetadata {
/**
* The documents title.
* The document's title.
*/
SkString fTitle;
/**
@ -141,19 +145,34 @@ 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.
* Returns NULL if XPS is not supported.
*
* @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.
*/
static sk_sp<SkDocument> MakeXPS(SkWStream* stream,
IXpsOMObjectFactory* xpsFactory,
SkScalar dpi = SK_ScalarDefaultRasterDPI);
/**
* 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);
#endif
// DEPRECATED; TODO(halcanary): remove this function after Chromium switches to new API.
static sk_sp<SkDocument> MakeXPS(SkWStream*) { return nullptr; }
/**
* Begin a new page for the document, returning the canvas that will draw

Просмотреть файл

@ -15,10 +15,12 @@
#include "SkPoint.h"
#include "SkColor.h"
class SkCanvas;
class SkPaint;
class SkArenaAlloc;
class SkCanvas;
class SkColorSpaceXformer;
class SkPaint;
struct SkRect;
class SkString;
class SkString;
/** \class SkDrawLooper
Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are,
@ -61,19 +63,8 @@ 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* 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;
virtual Context* makeContext(SkCanvas*, SkArenaAlloc*) const = 0;
/**
* The fast bounds functions are used to enable the paint to be culled early
@ -110,9 +101,16 @@ 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,6 +9,7 @@
#define SkDrawable_DEFINED
#include "SkFlattenable.h"
#include "SkScalar.h"
class SkCanvas;
class SkMatrix;

Просмотреть файл

@ -0,0 +1,33 @@
/*
* 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

Просмотреть файл

@ -1,91 +0,0 @@
/*
* 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 thats
* 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 */

Просмотреть файл

@ -0,0 +1,32 @@
/*
* 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,9 +11,12 @@
#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

Просмотреть файл

@ -0,0 +1,79 @@
/*
* 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 "SkTypes.h"
#include "SkRefCnt.h"
class SkData;
class SkImageGenerator;
@ -157,7 +157,8 @@ public:
*/
static void SetTLSFontCacheLimit(size_t bytes);
typedef SkImageGenerator* (*ImageGeneratorFromEncodedFactory)(SkData*);
typedef std::unique_ptr<SkImageGenerator>
(*ImageGeneratorFromEncodedDataFactory)(sk_sp<SkData>);
/**
* To instantiate images from encoded data, first looks at this runtime function-ptr. If it
@ -166,8 +167,8 @@ public:
*
* Returns the previous factory (which could be NULL).
*/
static ImageGeneratorFromEncodedFactory
SetImageGeneratorFromEncodedFactory(ImageGeneratorFromEncodedFactory);
static ImageGeneratorFromEncodedDataFactory
SetImageGeneratorFromEncodedDataFactory(ImageGeneratorFromEncodedDataFactory);
};
class SkAutoGraphics {

Просмотреть файл

@ -0,0 +1,109 @@
/*
* 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,6 +18,7 @@
class SkData;
class SkCanvas;
class SkColorTable;
class SkCrossContextImageData;
class SkImageGenerator;
class SkPaint;
class SkPicture;
@ -73,7 +74,8 @@ public:
*
* If a subset is specified, it must be contained within the generator's bounds.
*/
static sk_sp<SkImage> MakeFromGenerator(SkImageGenerator*, const SkIRect* subset = nullptr);
static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator>,
const SkIRect* subset = nullptr);
/**
* Construct a new SkImage based on the specified encoded data. Returns NULL on failure,
@ -154,10 +156,18 @@ public:
const SkISize nv12Sizes[2], GrSurfaceOrigin,
sk_sp<SkColorSpace> = nullptr);
static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture>, const SkISize& dimensions,
const SkMatrix*, const SkPaint*);
enum class BitDepth {
kU8,
kF16,
};
static sk_sp<SkImage> MakeTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted budgeted);
/**
* 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>);
///////////////////////////////////////////////////////////////////////////////////////////////
@ -167,6 +177,21 @@ 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()); }
/**
@ -176,11 +201,6 @@ 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;
@ -193,35 +213,6 @@ 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;
@ -234,8 +225,11 @@ 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) const;
GrBackendObject getTextureHandle(bool flushPendingGrContextIO,
GrSurfaceOrigin* origin = nullptr) const;
/**
* Hints to image calls where the system might cache computed intermediates (e.g. the results
@ -290,7 +284,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(SkImageEncoder::Type, int quality) const;
SkData* encode(SkEncodedImageFormat, int quality) const;
/**
* Encode the image and return the result as a caller-managed SkData. This will
@ -331,11 +325,20 @@ public:
sk_sp<SkImage> makeSubset(const SkIRect& subset) const;
/**
* 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.
* 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.
*/
sk_sp<SkImage> makeTextureImage(GrContext*) const;
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>);
/**
* If the image is texture-backed this will make a raster copy of it (or nullptr if reading back
@ -392,13 +395,16 @@ 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,
SkSourceGammaTreatment treatment =
SkSourceGammaTreatment::kIgnore) const;
SkColorSpace* dstColorSpace = nullptr) const;
/**
* Returns a texture-backed image from data produced in SkImage::getDeferredTextureImageData.
@ -431,39 +437,21 @@ public:
*/
bool isLazyGenerated() 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
/**
* 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;
protected:
SkImage(int width, int height, uint32_t uniqueID);
@ -471,7 +459,7 @@ protected:
private:
static sk_sp<SkImage> MakeTextureFromMipMap(GrContext*, const SkImageInfo&,
const GrMipLevel* texels, int mipLevelCount,
SkBudgeted, SkSourceGammaTreatment);
SkBudgeted, SkDestinationSurfaceColorMode);
const int fWidth;
const int fHeight;

Просмотреть файл

@ -8,112 +8,35 @@
#ifndef SkImageEncoder_DEFINED
#define SkImageEncoder_DEFINED
#include "SkImageInfo.h"
#include "SkTRegistry.h"
#include "SkBitmap.h"
#include "SkEncodedImageFormat.h"
#include "SkStream.h"
class SkBitmap;
class SkPixelSerializer;
class SkPixmap;
class SkData;
class SkWStream;
/**
* 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 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
#endif // SkImageEncoder_DEFINED

Просмотреть файл

@ -20,6 +20,7 @@
class GrContext;
class GrFragmentProcessor;
class SkColorFilter;
class SkColorSpaceXformer;
struct SkIPoint;
class SkSpecialImage;
class SkImageFilterCache;
@ -223,12 +224,6 @@ 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
@ -243,14 +238,6 @@ 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()
@ -284,7 +271,7 @@ protected:
SkImageFilter(sk_sp<SkImageFilter>* inputs, int inputCount, const CropRect* cropRect);
virtual ~SkImageFilter();
~SkImageFilter() override;
/**
* Constructs a new SkImageFilter read from an SkReadBuffer object.
@ -297,6 +284,10 @@ 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.
@ -400,8 +391,46 @@ 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,55 +10,20 @@
#include "SkBitmap.h"
#include "SkColor.h"
#include "SkImage.h"
#include "SkImageInfo.h"
#include "SkYUVSizeInfo.h"
class GrContext;
class GrTexture;
class GrTextureParams;
class GrContextThreadSafeProxy;
class GrTextureProxy;
class GrSamplerParams;
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:
/**
@ -79,11 +44,7 @@ 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
}
/**
@ -151,104 +112,49 @@ 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.
*
* Regarding the GrContext parameter:
* This routine also supports retrieving only a subset of the pixels. That subset is specified
* by the following rectangle:
*
* 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.
* subset = SkIRect::MakeXYWH(origin.x(), origin.y(), info.width(), info.height())
*
* 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.
* If subset is not contained inside the generator's bounds, this returns false.
*
* 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())
* whole = SkIRect::MakeWH(getInfo().width(), getInfo().height())
* if (!whole.contains(subset)) {
* return false;
* }
*
* 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.
* 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.
*/
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);
}
sk_sp<GrTextureProxy> generateTexture(GrContext*, const SkImageInfo& info,
const SkIPoint& origin);
#endif
/**
* 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 SkImageGenerator* NewFromEncoded(SkData*);
static std::unique_ptr<SkImageGenerator> MakeFromEncoded(sk_sp<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 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();
}
}
static std::unique_ptr<SkImageGenerator> MakeFromPicture(const SkISize&, sk_sp<SkPicture>,
const SkMatrix*, const SkPaint*,
SkImage::BitDepth,
sk_sp<SkColorSpace>);
protected:
enum {
@ -257,7 +163,7 @@ protected:
SkImageGenerator(const SkImageInfo& info, uint32_t uniqueId = kNeedNewImageUniqueID);
virtual SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM);
virtual SkData* onRefEncodedData(GrContext* ctx);
virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
SkPMColor ctable[], int* ctableCount);
@ -269,27 +175,38 @@ protected:
return false;
}
virtual GrTexture* onGenerateTexture(GrContext*, const SkIRect*) {
return nullptr;
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 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*);
#if SK_SUPPORT_GPU
virtual sk_sp<GrTextureProxy> onGenerateTexture(GrContext*, const SkImageInfo&,
const SkIPoint&);
#endif
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 SkImageGenerator* NewFromEncodedImpl(SkData*);
static std::unique_ptr<SkImageGenerator> MakeFromEncodedImpl(sk_sp<SkData>);
};
#endif // SkImageGenerator_DEFINED

Просмотреть файл

@ -169,9 +169,9 @@ enum SkYUVColorSpace {
///////////////////////////////////////////////////////////////////////////////
enum class SkSourceGammaTreatment {
kRespect,
kIgnore,
enum class SkDestinationSurfaceColorMode {
kLegacy,
kGammaAndColorSpaceAware,
};
/**
@ -234,6 +234,7 @@ 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; }
@ -277,7 +278,11 @@ public:
}
size_t minRowBytes() const {
return (size_t)this->minRowBytes64();
uint64_t minRowBytes = this->minRowBytes64();
if (!sk_64_isS32(minRowBytes)) {
return 0;
}
return sk_64_asS32(minRowBytes);
}
size_t computeOffset(int x, int y, size_t rowBytes) const {
@ -302,7 +307,7 @@ public:
if (0 == fHeight) {
return 0;
}
return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel();
return sk_64_mul(fHeight - 1, rowBytes) + sk_64_mul(fWidth, this->bytesPerPixel());
}
size_t getSafeSize(size_t rowBytes) const {
@ -344,16 +349,4 @@ 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,12 +22,10 @@ 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 SkMallocPixelRef* NewDirect(const SkImageInfo&, void* addr,
size_t rowBytes, SkColorTable*);
static sk_sp<SkPixelRef> MakeDirect(const SkImageInfo&, void* addr,
size_t rowBytes, sk_sp<SkColorTable>);
/**
* Return a new SkMallocPixelRef, automatically allocating storage for the
@ -39,22 +37,18 @@ public:
*
* Returns NULL on failure.
*/
static SkMallocPixelRef* NewAllocate(const SkImageInfo& info,
size_t rowBytes, SkColorTable*);
static sk_sp<SkPixelRef> MakeAllocate(const SkImageInfo&, size_t rowBytes, sk_sp<SkColorTable>);
/**
* Identical to NewAllocate, except all pixel bytes are zeroed.
* Identical to MakeAllocate, except all pixel bytes are zeroed.
*/
static SkMallocPixelRef* NewZeroed(const SkImageInfo& info,
size_t rowBytes, SkColorTable*);
static sk_sp<SkPixelRef> MakeZeroed(const SkImageInfo&, size_t rowBytes, sk_sp<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
@ -63,10 +57,10 @@ public:
* Returns NULL on failure.
*/
typedef void (*ReleaseProc)(void* addr, void* context);
static SkMallocPixelRef* NewWithProc(const SkImageInfo& info,
size_t rowBytes, SkColorTable*,
void* addr, ReleaseProc proc,
void* context);
static sk_sp<SkPixelRef> MakeWithProc(const SkImageInfo& info,
size_t rowBytes, sk_sp<SkColorTable>,
void* addr, ReleaseProc proc,
void* context);
/**
* Return a new SkMallocPixelRef that will use the provided
@ -74,51 +68,56 @@ 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);
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;
};
#endif
protected:
// The ownPixels version of this constructor is deprecated.
SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
bool ownPixels);
virtual ~SkMallocPixelRef();
~SkMallocPixelRef() override;
#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 SkMallocPixelRef* NewUsing(void*(*alloc)(size_t),
const SkImageInfo&,
size_t rowBytes,
SkColorTable*);
static sk_sp<SkPixelRef> MakeUsing(void*(*alloc)(size_t),
const SkImageInfo&,
size_t rowBytes,
sk_sp<SkColorTable>);
void* fStorage;
SkColorTable* fCTable;
size_t fRB;
ReleaseProc fReleaseProc;
void* fReleaseProcContext;
ReleaseProc fReleaseProc;
void* fReleaseProcContext;
SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, sk_sp<SkColorTable>,
ReleaseProc proc, void* context);
typedef SkPixelRef INHERITED;

Просмотреть файл

@ -18,10 +18,13 @@
class GrClip;
class GrContext;
class GrDrawContext;
class GrRenderTargetContext;
class GrPaint;
class GrFragmentProcessor;
class GrRenderTarget;
class GrTextureProvider;
class GrResourceProvider;
class GrTexture;
class GrTextureProxy;
class SkBitmap;
class SkBlitter;
class SkCachedData;
@ -109,23 +112,23 @@ public:
SkRect* maskRect) const;
/**
* Try to directly render the mask filter into the target. Returns
* true if drawing was successful.
* Try to directly render the mask filter into the target. Returns true if drawing was
* successful. If false is returned then paint is unmodified.
*/
virtual bool directFilterMaskGPU(GrTextureProvider* texProvider,
GrDrawContext* drawContext,
GrPaint* grp,
virtual bool directFilterMaskGPU(GrContext*,
GrRenderTargetContext* renderTargetContext,
GrPaint&& paint,
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.
* true if drawing was successful. If false is returned then paint is unmodified.
*/
virtual bool directFilterRRectMaskGPU(GrContext*,
GrDrawContext* drawContext,
GrPaint* grp,
GrRenderTargetContext* renderTargetContext,
GrPaint&& paint,
const GrClip&,
const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec,
@ -139,10 +142,10 @@ public:
* Implementations are free to get the GrContext from the src texture in order to create
* additional textures and perform multiple passes.
*/
virtual bool filterMaskGPU(GrTexture* src,
const SkMatrix& ctm,
const SkIRect& maskRect,
GrTexture** result) const;
virtual sk_sp<GrTextureProxy> filterMaskGPU(GrContext*,
sk_sp<GrTextureProxy> srcProxy,
const SkMatrix& ctm,
const SkIRect& maskRect) const;
#endif
/**

Просмотреть файл

@ -21,6 +21,8 @@ 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 {
@ -461,8 +463,7 @@ public:
/** Like mapPoints but with custom byte stride between the points.
*/
void mapPointsWithStride(SkPoint dst[], SkPoint src[],
size_t stride, int count) const {
void mapPointsWithStride(SkPoint dst[], const SkPoint src[], size_t stride, int count) const {
SkASSERT(stride >= sizeof(SkPoint));
SkASSERT(0 == stride % sizeof(SkScalar));
for (int i = 0; i < count; ++i) {
@ -815,6 +816,14 @@ 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,6 +126,12 @@ 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:
@ -491,7 +497,10 @@ 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 55
#define SK_MILESTONE 59
#endif

Просмотреть файл

@ -57,7 +57,7 @@ public:
private:
struct DrawData {
SkCanvas* fCanvas; // reffed
SkCanvas* fCanvas;
const SkPicture* fPicture; // reffed
SkMatrix fMatrix;
SkPaint* fPaint; // owned

Просмотреть файл

@ -12,9 +12,7 @@
#include "SkColor.h"
#include "SkFilterQuality.h"
#include "SkMatrix.h"
#include "SkXfermode.h"
//#define SK_SUPPORT_LEGACY_XFERMODE_OBJECT
#include "SkRefCnt.h"
class SkAutoDescriptor;
class SkAutoGlyphCache;
@ -39,8 +37,6 @@ 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
@ -105,8 +101,6 @@ 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
@ -119,9 +113,18 @@ 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)
*/
@ -230,32 +233,6 @@ 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.
*/
@ -483,6 +460,7 @@ 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
@ -503,61 +481,24 @@ 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, returning the parameter.
/** Set or clear the paint's colorfilter.
<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; }
@ -568,6 +509,7 @@ 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 />
@ -580,9 +522,6 @@ 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 />
@ -590,6 +529,7 @@ 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 />
@ -601,9 +541,6 @@ 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
@ -615,6 +552,7 @@ 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 />
@ -627,9 +565,6 @@ 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 />
@ -637,6 +572,7 @@ 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 />
@ -649,13 +585,10 @@ 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(); }
SkImageFilter* setImageFilter(SkImageFilter*);
sk_sp<SkImageFilter> refImageFilter() const;
void setImageFilter(sk_sp<SkImageFilter>);
/**
@ -663,6 +596,8 @@ 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.
@ -674,9 +609,7 @@ 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 {
@ -755,7 +688,7 @@ public:
A set flag indicates that the metric may be trusted.
*/
enum FontMetricsFlags {
kUnderlineThinknessIsValid_Flag = 1 << 0,
kUnderlineThicknessIsValid_Flag = 1 << 0,
kUnderlinePositionIsValid_Flag = 1 << 1,
};
@ -781,21 +714,21 @@ public:
*/
SkScalar fUnderlinePosition; //!< underline position, or 0 if cannot be determined
/** If the fontmetrics has a valid underlinethickness, return true, and set the
/** If the fontmetrics has a valid underline thickness, 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 & kUnderlineThinknessIsValid_Flag)) {
if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
*thickness = fUnderlineThickness;
return true;
}
return false;
}
/** 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.
/** 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.
*/
bool hasUnderlinePosition(SkScalar* position) const {
if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
@ -1111,7 +1044,7 @@ private:
SkColor fColor;
SkScalar fWidth;
SkScalar fMiterLimit;
uint32_t fBlendMode; // just need 5-6 bits for SkXfermode::Mode
uint32_t fBlendMode; // just need 5-6 bits
union {
struct {
// all of these bitfields should add up to 32

Просмотреть файл

@ -23,6 +23,8 @@ 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:
@ -357,6 +359,19 @@ 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
@ -1121,12 +1136,12 @@ private:
kCurrent_Version = 2
};
SkAutoTUnref<SkPathRef> fPathRef;
sk_sp<SkPathRef> fPathRef;
int fLastMoveToIndex;
uint8_t fFillType;
mutable uint8_t fConvexity;
mutable SkAtomic<uint8_t, sk_memory_order_relaxed> fFirstDirection;// SkPathPriv::FirstDirection
mutable SkBool8 fIsVolatile;
SkBool8 fIsVolatile;
/** Resets all fields other than fPathRef to their initial 'empty' values.
* Assumes the caller has already emptied fPathRef.
@ -1190,6 +1205,8 @@ 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,4 +1,3 @@
/*
* Copyright 2006 The Android Open Source Project
*
@ -6,7 +5,6 @@
* found in the LICENSE file.
*/
#ifndef SkPathEffect_DEFINED
#define SkPathEffect_DEFINED
@ -28,6 +26,23 @@ 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
@ -138,6 +153,8 @@ public:
virtual bool exposedInAndroidJavaAPI() const { return false; }
#endif
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
protected:
SkPathEffect() {}
@ -149,125 +166,4 @@ 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 SkAutoTUnref, which may be updated to point to a new SkPathRef after the editor's
* constructor returns.
* constructor a pointer to a sk_sp<SkPathRef>, 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(SkAutoTUnref<SkPathRef>* pathRef,
Editor(sk_sp<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(SkAutoTUnref<SkPathRef>* dst,
static void CreateTransformedCopy(sk_sp<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(SkAutoTUnref<SkPathRef>* pathRef);
static void Rewind(sk_sp<SkPathRef>* pathRef);
~SkPathRef();
int countPoints() const { SkDEBUGCODE(this->validate();) return fPointCnt; }

Просмотреть файл

@ -52,21 +52,6 @@ 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.
*
@ -182,18 +167,6 @@ 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();
@ -225,10 +198,12 @@ 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 = 50;
static const uint32_t CURRENT_PICTURE_VERSION = 52;
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&, SkCanvas::ClipOp, bool doAntiAlias);
void analyzeClipPath(const SkPath&, SkClipOp, bool doAntiAlias);
/**
* Reset all accumulated stats.

Просмотреть файл

@ -38,7 +38,6 @@ public:
};
enum FinishFlags {
kReturnNullForEmpty_FinishFlag = 1 << 0, // no draw-ops will return nullptr
};
/** Returns the canvas that records the drawing commands.
@ -78,7 +77,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
* endRecordingAsPicture(), except that this method updates the cull rect initially passed
* finishRecordingAsPicture(), 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.
@ -92,26 +91,13 @@ public:
* beginRecording/getRecordingCanvas. Ownership of the object is passed to the caller, who
* must call unref() when they are done using it.
*
* Unlike endRecordingAsPicture(), which returns an immutable picture, the returned drawable
* Unlike finishRecordingAsPicture(), 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();
@ -124,13 +110,13 @@ private:
friend class SkPictureRecorderReplayTester; // for unit testing
void partialReplay(SkCanvas* canvas) const;
bool fActivelyRecording;
uint32_t fFlags;
SkRect fCullRect;
SkAutoTUnref<SkBBoxHierarchy> fBBH;
SkAutoTUnref<SkRecorder> fRecorder;
SkAutoTUnref<SkRecord> fRecord;
SkMiniRecorder fMiniRecorder;
bool fActivelyRecording;
uint32_t fFlags;
SkRect fCullRect;
sk_sp<SkBBoxHierarchy> fBBH;
std::unique_ptr<SkRecorder> fRecorder;
sk_sp<SkRecord> fRecord;
SkMiniRecorder fMiniRecorder;
typedef SkNoncopyable INHERITED;
};

Просмотреть файл

@ -18,10 +18,8 @@
#include "SkRefCnt.h"
#include "SkSize.h"
#include "SkString.h"
#include "SkYUVSizeInfo.h"
class SkColorTable;
class SkData;
struct SkIRect;
class GrTexture;
@ -37,7 +35,11 @@ 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 {
@ -96,14 +98,6 @@ 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.
@ -147,39 +141,6 @@ 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;
@ -206,34 +167,6 @@ 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
@ -258,12 +191,10 @@ 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.
@ -271,8 +202,14 @@ protected:
* The caller will have already acquired a mutex for thread safety, so this
* method need not do that.
*/
virtual bool onNewLockPixels(LockRec*) = 0;
bool onNewLockPixels(LockRec*) {
SkASSERT(false); // should never be called
return true;
}
#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
@ -281,32 +218,13 @@ protected:
* The caller will have already acquired a mutex for thread safety, so this
* method need not do that.
*/
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();
void onUnlockPixels() {
SkASSERT(false); // should never be called
}
// 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.
@ -317,31 +235,36 @@ protected:
*/
virtual size_t getAllocatedSizeInBytes() const;
virtual bool onRequestLock(const LockRequest&, LockResult*);
virtual bool onIsLazyGenerated() const { return false; }
#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
/** 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); }
@ -353,8 +276,6 @@ 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;
@ -387,19 +308,9 @@ 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,6 +70,7 @@ 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()); }
@ -89,6 +90,22 @@ 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,15 +77,6 @@
# 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,7 +8,8 @@
#ifndef SkRSXform_DEFINED
#define SkRSXform_DEFINED
#include "SkScalar.h"
#include "SkPoint.h"
#include "SkSize.h"
/**
* A compressed form of a rotation+scale matrix.

Просмотреть файл

@ -0,0 +1,87 @@
/*
* 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 SK_WARN_UNUSED_RESULT intersect(const SkIRect& r) {
bool intersect(const SkIRect& r) {
return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom);
}
@ -327,8 +327,7 @@ struct SK_API SkIRect {
otherwise return false and do not change this rectangle.
If either rectangle is empty, do nothing and return false.
*/
bool SK_WARN_UNUSED_RESULT intersect(int32_t left, int32_t top,
int32_t right, int32_t bottom) {
bool 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;
@ -676,15 +675,14 @@ 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 SK_WARN_UNUSED_RESULT intersect(const SkRect& r);
bool 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 SK_WARN_UNUSED_RESULT intersect(SkScalar left, SkScalar top,
SkScalar right, SkScalar bottom);
bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom);
/**
* If rectangles a and b intersect, return true and set this rectangle to

Просмотреть файл

@ -16,8 +16,6 @@
#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
@ -71,15 +69,7 @@ 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);
}
@ -147,6 +137,28 @@ 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(); \
@ -154,6 +166,8 @@ class SK_API SkRefCnt : public SkRefCntBase {
dst = src; \
} while (0)
#endif
/** Call obj->ref() and return obj. The obj must not be nullptr.
*/
@ -189,32 +203,6 @@ 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>
@ -447,20 +435,14 @@ 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,6 +436,8 @@ private:
int count_runtype_values(int* itop, int* ibot) const;
bool isValid() const;
static void BuildRectRuns(const SkIRect& bounds,
RunType runs[kRectRegionRuns]);

Просмотреть файл

@ -10,14 +10,9 @@
#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
@ -56,48 +51,6 @@ 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)
@ -181,9 +134,6 @@ 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,6 +9,7 @@
#define SkShader_DEFINED
#include "SkBitmap.h"
#include "SkFilterQuality.h"
#include "SkFlattenable.h"
#include "SkImageInfo.h"
#include "SkMask.h"
@ -16,12 +17,13 @@
#include "SkPaint.h"
#include "../gpu/GrColor.h"
class SkArenaAlloc;
class SkColorFilter;
class SkColorSpace;
class SkImage;
class SkPath;
class SkPicture;
class SkXfermode;
class SkRasterPipeline;
class GrContext;
class GrFragmentProcessor;
@ -38,7 +40,7 @@ class GrFragmentProcessor;
class SK_API SkShader : public SkFlattenable {
public:
SkShader(const SkMatrix* localMatrix = NULL);
virtual ~SkShader();
~SkShader() override;
/**
* Returns the local matrix.
@ -98,6 +100,12 @@ 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.
*/
@ -108,16 +116,18 @@ public:
};
ContextRec(const SkPaint& paint, const SkMatrix& matrix, const SkMatrix* localM,
DstType dstType)
DstType dstType, SkColorSpace* dstColorSpace)
: fPaint(&paint)
, fMatrix(&matrix)
, fLocalMatrix(localM)
, fPreferredDstType(dstType) {}
, fPreferredDstType(dstType)
, fDstColorSpace(dstColorSpace) {}
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 {
@ -153,7 +163,7 @@ public:
struct BlitState {
// inputs
Context* fCtx;
SkXfermode* fXfer;
SkBlendMode fMode;
// outputs
enum { N = 2 };
@ -219,15 +229,11 @@ public:
};
/**
* Create the actual object that does the shading.
* Size of storage must be >= contextSize.
* Make a context using the memory provided by the arena.
*
* @return pointer to context or nullptr if can't be created
*/
Context* createContext(const ContextRec&, void* storage) const;
/**
* Return the size of a Context returned by createContext.
*/
size_t contextSize(const ContextRec&) const;
Context* makeContext(const ContextRec&, SkArenaAlloc*) const;
#ifdef SK_SUPPORT_LEGACY_SHADER_ISABITMAP
/**
@ -320,32 +326,30 @@ public:
struct ComposeRec {
const SkShader* fShaderA;
const SkShader* fShaderB;
const SkXfermode* fMode;
SkBlendMode fBlendMode;
};
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,
SkSourceGammaTreatment gammaTreatment)
SkColorSpace* dstColorSpace)
: fContext(context)
, fViewMatrix(viewMatrix)
, fLocalMatrix(localMatrix)
, fFilterQuality(filterQuality)
, fDstColorSpace(dstColorSpace)
, fGammaTreatment(gammaTreatment) {}
, fDstColorSpace(dstColorSpace) {}
GrContext* fContext;
const SkMatrix* fViewMatrix;
const SkMatrix* fLocalMatrix;
SkFilterQuality fFilterQuality;
SkColorSpace* fDstColorSpace;
SkSourceGammaTreatment fGammaTreatment;
GrContext* fContext;
const SkMatrix* fViewMatrix;
const SkMatrix* fLocalMatrix;
SkFilterQuality fFilterQuality;
SkColorSpace* fDstColorSpace;
};
/**
@ -374,14 +378,6 @@ 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
@ -399,7 +395,7 @@ public:
//////////////////////////////////////////////////////////////////////////
// Factory methods for stock shaders
/**
* Call this to create a new "empty" shader, that will not draw anything.
*/
@ -419,40 +415,7 @@ public:
*/
static sk_sp<SkShader> MakeColorShader(const SkColor4f&, sk_sp<SkColorSpace>);
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
static sk_sp<SkShader> MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader> src, SkBlendMode);
/** Call this to create a new shader that will draw with the specified bitmap.
*
@ -491,34 +454,30 @@ public:
const SkMatrix* localMatrix, const SkRect* tile);
/**
* 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.
* 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.
*/
virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const;
virtual sk_sp<SkShader> makeAsALocalMatrixShader(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;
/**
* Your subclass must also override contextSize() if it overrides onCreateContext().
* Base class impl returns NULL.
* Specialize creating a SkShader context using the supplied allocator.
* @return pointer to context owned by the arena allocator.
*/
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 Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const {
return nullptr;
}
virtual bool onAsLuminanceColor(SkColor*) const {
return false;
@ -534,6 +493,10 @@ 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,101 +10,83 @@
#include "SkScalar.h"
template <typename T> struct SkTSize {
T fWidth;
T fHeight;
struct SkISize {
int32_t fWidth;
int32_t fHeight;
static SkTSize Make(T w, T h) {
SkTSize s;
s.fWidth = w;
s.fHeight = h;
return s;
}
static SkISize Make(int32_t w, int32_t h) { return {w, h}; }
void set(T w, T h) {
fWidth = w;
fHeight = h;
}
static SkISize MakeEmpty() { return {0, 0}; }
void set(int32_t w, int32_t h) { *this = SkISize{w, 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; }
T width() const { return fWidth; }
T height() const { return fHeight; }
int32_t width() const { return fWidth; }
int32_t height() const { return fHeight; }
/** 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;
}
bool equals(int32_t w, int32_t h) const { return fWidth == w && fHeight == h; }
};
template <typename T>
static inline bool operator==(const SkTSize<T>& a, const SkTSize<T>& b) {
static inline bool operator==(const SkISize& a, const SkISize& b) {
return a.fWidth == b.fWidth && a.fHeight == b.fHeight;
}
template <typename T>
static inline bool operator!=(const SkTSize<T>& a, const SkTSize<T>& b) {
return !(a == b);
}
static inline bool operator!=(const SkISize& a, const SkISize& b) { return !(a == b); }
///////////////////////////////////////////////////////////////////////////////
typedef SkTSize<int32_t> SkISize;
struct SkSize {
SkScalar fWidth;
SkScalar fHeight;
struct SkSize : public SkTSize<SkScalar> {
static SkSize Make(SkScalar w, SkScalar h) {
SkSize s;
s.fWidth = w;
s.fHeight = h;
return s;
static SkSize Make(SkScalar w, SkScalar h) { return {w, h}; }
static SkSize Make(const SkISize& src) {
return {SkIntToScalar(src.width()), SkIntToScalar(src.height())};
}
SkSize& operator=(const SkISize& src) {
this->set(SkIntToScalar(src.fWidth), SkIntToScalar(src.fHeight));
return *this;
return *this = SkSize{SkIntToScalar(src.fWidth), SkIntToScalar(src.fHeight)};
}
SkISize toRound() const {
SkISize s;
s.set(SkScalarRoundToInt(fWidth), SkScalarRoundToInt(fHeight));
return s;
}
static SkSize MakeEmpty() { return {0, 0}; }
SkISize toCeil() const {
SkISize s;
s.set(SkScalarCeilToInt(fWidth), SkScalarCeilToInt(fHeight));
return s;
}
void set(SkScalar w, SkScalar h) { *this = SkSize{w, h}; }
SkISize toFloor() const {
SkISize s;
s.set(SkScalarFloorToInt(fWidth), SkScalarFloorToInt(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)}; }
};
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,6 +12,8 @@
#include "SkRefCnt.h"
#include "SkScalar.h"
#include <memory.h>
class SkStream;
class SkStreamRewindable;
class SkStreamSeekable;
@ -187,21 +189,31 @@ 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);
bool write16(U16CPU);
bool write32(uint32_t);
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 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);
@ -220,9 +232,20 @@ 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. */
@ -231,28 +254,20 @@ 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[] = NULL);
explicit SkFILEStream(const char path[] = nullptr);
enum Ownership {
kCallerPasses_Ownership,
kCallerRetains_Ownership
};
/** Initialize the stream with an existing C file stream.
* 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.
* The C file stream will be closed in the destructor.
*/
explicit SkFILEStream(FILE* file, Ownership ownership = kCallerPasses_Ownership);
explicit SkFILEStream(FILE* file);
virtual ~SkFILEStream();
~SkFILEStream() override;
/** Returns true if the current path could be opened. */
bool isValid() const { return fFILE != NULL; }
bool isValid() const { return fFILE != nullptr; }
/** 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[]);
/** Close this SkFILEStream. */
void close();
size_t read(void* buffer, size_t size) override;
bool isAtEnd() const override;
@ -270,11 +285,14 @@ public:
const void* getMemoryBase() override;
private:
FILE* fFILE;
SkString fName;
Ownership fOwnership;
// fData is lazilly initialized when needed.
mutable sk_sp<SkData> fData;
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;
typedef SkStreamAsset INHERITED;
};
@ -289,14 +307,6 @@ 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>);
@ -314,22 +324,6 @@ 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();
@ -363,7 +357,7 @@ private:
class SK_API SkFILEWStream : public SkWStream {
public:
SkFILEWStream(const char path[]);
virtual ~SkFILEWStream();
~SkFILEWStream() override;
/** Returns true if the current path could be opened.
*/
@ -380,52 +374,28 @@ 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();
virtual ~SkDynamicMemoryWStream();
~SkDynamicMemoryWStream() override;
bool write(const void* buffer, size_t size) 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; }
size_t bytesWritten() const override;
// copy what has been written to the stream into dst
bool read(void* buffer, size_t offset, size_t size);
/** More efficient version of read(dst, 0, bytesWritten()). */
void copyTo(void* dst) const;
void writeToStream(SkWStream* dst) const;
sk_sp<SkData> snapshotAsData() const;
// Return the contents as SkData, and then reset the stream.
/** 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> 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. */
SkStreamAsset* detachAsStream();
std::unique_ptr<SkStreamAsset> detachAsStream();
/** Reset the stream to its original, empty, state. */
void reset();
@ -434,10 +404,13 @@ private:
struct Block;
Block* fHead;
Block* fTail;
size_t fBytesWritten;
mutable sk_sp<SkData> fCopy; // is invalidated if we write after it is created
size_t fBytesWrittenBeforeTail;
void invalidateCopy();
#ifdef SK_DEBUG
void validate() const;
#else
void validate() const {}
#endif
// For access to the Block type.
friend class SkBlockMemoryStream;
@ -446,22 +419,4 @@ 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,12 +18,11 @@ class GrContext;
class GrRenderTarget;
/**
* 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 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).
*
* To draw into a canvas, first create the appropriate type of Surface, and
* then request the canvas from the surface.
* 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).
*
* 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.
@ -51,14 +50,10 @@ public:
void* context, const SkSurfaceProps* = nullptr);
/**
* 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.
* 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.
*
* If the requested surface cannot be created, or the request is not a
* supported configuration, NULL will be returned.
@ -150,60 +145,12 @@ 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; }
@ -302,32 +249,10 @@ 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. If a copy must be made the Budgeted
* parameter controls whether it counts against the resource budget
* (currently for the gpu backend only).
* will not be reflected in this image. For the GPU-backend, the budgeting
* decision for the snapped image will match that of the surface.
*/
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
sk_sp<SkImage> makeImageSnapshot();
/**
* Though the caller could get a snapshot image explicitly, and draw that,
@ -349,10 +274,6 @@ 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

Просмотреть файл

@ -1,55 +0,0 @@
/*
* 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,6 +9,7 @@
#define SkTextBlob_DEFINED
#include "../private/SkTemplates.h"
#include "../private/SkAtomics.h"
#include "SkPaint.h"
#include "SkString.h"
#include "SkRefCnt.h"
@ -60,7 +61,7 @@ private:
friend class SkNVRefCnt<SkTextBlob>;
class RunRecord;
SkTextBlob(int runCount, const SkRect& bounds);
explicit SkTextBlob(const SkRect& bounds);
~SkTextBlob();
@ -75,12 +76,19 @@ 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 int fRunCount;
const SkRect fBounds;
const uint32_t fUniqueID;
const SkRect fBounds;
const uint32_t fUniqueID;
mutable SkAtomic<bool> fAddedToCache;
SkDEBUGCODE(size_t fStorageSize;)
@ -101,17 +109,13 @@ public:
~SkTextBlobBuilder();
/**
* Returns an immutable SkTextBlob for the current runs/glyphs. The builder is reset and
* can be reused.
* Returns an immutable SkTextBlob for the current runs/glyphs,
* or nullptr if no runs were allocated.
*
* 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,6 +11,7 @@
#include "../private/SkBitmaskEnum.h"
#include "../private/SkOnce.h"
#include "../private/SkWeakRefCnt.h"
#include "SkFontArguments.h"
#include "SkFontStyle.h"
#include "SkRect.h"
#include "SkString.h"
@ -77,6 +78,20 @@ 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.
*/
@ -95,28 +110,17 @@ 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);
#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
static SkTypeface* CreateFromName(const char familyName[], Style style) {
return MakeFromName(familyName, SkFontStyle::FromOldStyle(style)).release();
}
#endif
static sk_sp<SkTypeface> MakeFromName(const char familyName[], SkFontStyle fontStyle);
/** 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.
@ -132,22 +136,12 @@ 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.
@ -308,8 +302,9 @@ public:
* if allowFailure is true, this returns NULL, else it returns a
* dummy scalercontext that will not crash, but will draw nothing.
*/
SkScalerContext* createScalerContext(const SkScalerContextEffects&, const SkDescriptor*,
bool allowFailure = false) const;
std::unique_ptr<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
@ -367,6 +362,10 @@ 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,28 +34,12 @@
// 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"
/**
* 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;
}
// enable to test new device-base clipping
//#define SK_USE_DEVICE_CLIPPING
/** \file SkTypes.h
*/
@ -66,57 +50,13 @@ static inline void* sk_careful_memcpy(void* dst, const void* src, size_t len) {
#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
@ -395,10 +335,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> inline void SkTSwap(T& a, T& b) {
T c(a);
a = b;
b = c;
template <typename T> static inline void SkTSwap(T& a, T& b) {
T c(std::move(a));
a = std::move(b);
b = std::move(c);
}
static inline int32_t SkAbs32(int32_t value) {
@ -409,7 +349,7 @@ static inline int32_t SkAbs32(int32_t value) {
return value;
}
template <typename T> inline T SkTAbs(T value) {
template <typename T> static inline T SkTAbs(T value) {
if (value < 0) {
value = -value;
}
@ -509,222 +449,6 @@ 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

Просмотреть файл

@ -0,0 +1,139 @@
/*
* 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();
~SkBinaryWriteBuffer() override;
bool isCrossProcess() const override {
return SkToBool(fFlags & kCrossProcess_Flag);
@ -134,12 +134,10 @@ 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(SkPixelSerializer*);
SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer; }
void setPixelSerializer(sk_sp<SkPixelSerializer>);
SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer.get(); }
private:
const uint32_t fFlags;
@ -148,7 +146,7 @@ private:
SkRefCntSet* fTFSet;
SkAutoTUnref<SkPixelSerializer> fPixelSerializer;
sk_sp<SkPixelSerializer> fPixelSerializer;
// Only used if we do not have an fFactorySet
SkTHashMap<SkString, uint32_t> fFlattenableDict;

Просмотреть файл

@ -8,6 +8,8 @@
#ifndef SkYUVSizeInfo_DEFINED
#define SkYUVSizeInfo_DEFINED
#include "SkSize.h"
struct SkYUVSizeInfo {
enum {
kY = 0,

Просмотреть файл

@ -58,12 +58,6 @@ 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,13 +26,6 @@ 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();
};

Просмотреть файл

@ -0,0 +1,30 @@
/*
* 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

Просмотреть файл

@ -1,44 +0,0 @@
/*
* 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,85 +10,13 @@
#define SkBlurDrawLooper_DEFINED
#include "SkDrawLooper.h"
#include "SkColor.h"
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;
/**
* 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);
};
#endif

Просмотреть файл

@ -17,15 +17,6 @@ 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,6 +48,7 @@ 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)
@ -58,19 +59,6 @@ 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;

Просмотреть файл

@ -1,81 +0,0 @@
/*
* 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,20 +21,11 @@ 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,18 +20,6 @@ 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,13 +19,6 @@ 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());
@ -33,6 +26,7 @@ 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,12 +24,6 @@ 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;
@ -41,7 +35,7 @@ public:
#endif
protected:
virtual ~SkCornerPathEffect();
~SkCornerPathEffect() override;
explicit SkCornerPathEffect(SkScalar radius);
void flatten(SkWriteBuffer&) const override;

Просмотреть файл

@ -38,12 +38,6 @@ 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;
@ -61,7 +55,7 @@ public:
#endif
protected:
virtual ~SkDashPathEffect();
~SkDashPathEffect() override;
SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase);
void flatten(SkWriteBuffer&) const override;

Просмотреть файл

@ -31,12 +31,6 @@ 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,23 +35,11 @@ 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,20 +32,11 @@ 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:

Просмотреть файл

@ -1,48 +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 SkGammaColorFilter_DEFINED
#define SkGammaColorFilter_DEFINED
#include "SkColorFilter.h"
#include "SkRefCnt.h"
// This colorfilter can be used to perform pixel-by-pixel conversion between linear and
// power-law color spaces. A gamma of 2.2 is interpreted to mean convert from sRGB to linear
// while a gamma of 1/2.2 is interpreted to mean convert from linear to sRGB. Any other
// values are just directly applied (i.e., out = in^gamma)
//
// More complicated color space mapping (i.e., ICC profiles) should be handled via the
// SkColorSpace object.
class SK_API SkGammaColorFilter : public SkColorFilter {
public:
static sk_sp<SkColorFilter> Make(SkScalar gamma);
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
static SkColorFilter* Create(SkScalar gamma) { return Make(gamma).release(); }
#endif
void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override;
#if SK_SUPPORT_GPU
sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*) const override;
#endif
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLumaColorFilter)
protected:
void flatten(SkWriteBuffer&) const override;
private:
SkGammaColorFilter(SkScalar gamma);
SkScalar fGamma;
typedef SkColorFilter INHERITED;
};
#endif

Просмотреть файл

@ -198,60 +198,6 @@ public:
return MakeSweep(cx, cy, colors, std::move(colorSpace), pos, count, 0, NULL);
}
#ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR
static SkShader* CreateLinear(const SkPoint pts[2],
const SkColor colors[], const SkScalar pos[], int count,
SkShader::TileMode mode,
uint32_t flags, const SkMatrix* localMatrix) {
return MakeLinear(pts, colors, pos, count, mode, flags, localMatrix).release();
}
static SkShader* CreateLinear(const SkPoint pts[2],
const SkColor colors[], const SkScalar pos[], int count,
SkShader::TileMode mode) {
return CreateLinear(pts, colors, pos, count, mode, 0, NULL);
}
static SkShader* CreateRadial(const SkPoint& center, SkScalar radius,
const SkColor colors[], const SkScalar pos[], int count,
SkShader::TileMode mode,
uint32_t flags, const SkMatrix* localMatrix) {
return MakeRadial(center, radius, colors, pos, count, mode, flags, localMatrix).release();
}
static SkShader* CreateRadial(const SkPoint& center, SkScalar radius,
const SkColor colors[], const SkScalar pos[], int count,
SkShader::TileMode mode) {
return CreateRadial(center, radius, colors, pos, count, mode, 0, NULL);
}
static SkShader* CreateTwoPointConical(const SkPoint& start, SkScalar startRadius,
const SkPoint& end, SkScalar endRadius,
const SkColor colors[], const SkScalar pos[], int count,
SkShader::TileMode mode,
uint32_t flags, const SkMatrix* localMatrix) {
return MakeTwoPointConical(start, startRadius, end, endRadius, colors, pos, count, mode,
flags, localMatrix).release();
}
static SkShader* CreateTwoPointConical(const SkPoint& start, SkScalar startRadius,
const SkPoint& end, SkScalar endRadius,
const SkColor colors[], const SkScalar pos[], int count,
SkShader::TileMode mode) {
return CreateTwoPointConical(start, startRadius, end, endRadius, colors, pos, count, mode,
0, NULL);
}
static SkShader* CreateSweep(SkScalar cx, SkScalar cy,
const SkColor colors[], const SkScalar pos[], int count,
uint32_t flags, const SkMatrix* localMatrix) {
return MakeSweep(cx, cy, colors, pos, count, flags, localMatrix).release();
}
static SkShader* CreateSweep(SkScalar cx, SkScalar cy,
const SkColor colors[], const SkScalar pos[], int count) {
return CreateSweep(cx, cy, colors, pos, count, 0, NULL);
}
#endif
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
};

Просмотреть файл

@ -0,0 +1,81 @@
/*
* 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 SkHighContrastFilter_DEFINED
#define SkHighContrastFilter_DEFINED
#include "SkColorFilter.h"
#include "SkPaint.h"
/**
* Configuration struct for SkHighContrastFilter.
*
* Provides transformations to improve contrast for users with low vision.
*/
struct SkHighContrastConfig {
enum class InvertStyle {
kNoInvert,
kInvertBrightness,
kInvertLightness,
};
SkHighContrastConfig() {
fGrayscale = false;
fInvertStyle = InvertStyle::kNoInvert;
fContrast = 0.0f;
}
SkHighContrastConfig(bool grayscale,
InvertStyle invertStyle,
SkScalar contrast)
: fGrayscale(grayscale),
fInvertStyle(invertStyle),
fContrast(contrast) {}
// Returns true if all of the fields are set within the valid range.
bool isValid() const {
return fInvertStyle >= InvertStyle::kNoInvert &&
fInvertStyle <= InvertStyle::kInvertLightness &&
fContrast >= -1.0 &&
fContrast <= 1.0;
}
// If true, the color will be converted to grayscale.
bool fGrayscale;
// Whether to invert brightness, lightness, or neither.
InvertStyle fInvertStyle;
// After grayscale and inverting, the contrast can be adjusted linearly.
// The valid range is -1.0 through 1.0, where 0.0 is no adjustment.
SkScalar fContrast;
};
/**
* Color filter that provides transformations to improve contrast
* for users with low vision.
*
* Applies the following transformations in this order. Each of these
* can be configured using SkHighContrastConfig.
*
* - Conversion to grayscale
* - Color inversion (either in RGB or HSL space)
* - Increasing the resulting contrast.
*
* Calling SkHighContrastFilter::Make will return nullptr if the config is
* not valid, e.g. if you try to call it with a contrast outside the range of
* -1.0 to 1.0.
*/
class SK_API SkHighContrastFilter {
public:
// Returns the filter, or nullptr if the config is invalid.
static sk_sp<SkColorFilter> Make(const SkHighContrastConfig& config);
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
};
#endif

Просмотреть файл

@ -24,23 +24,12 @@ public:
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageSource)
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
static SkImageFilter* Create(SkImage* image) {
return Make(sk_ref_sp<SkImage>(image)).release();
}
static SkImageFilter* Create(SkImage* image,
const SkRect& srcRect,
const SkRect& dstRect,
SkFilterQuality filterQuality) {
return Make(sk_ref_sp<SkImage>(image), srcRect, dstRect, filterQuality).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;
private:
explicit SkImageSource(sk_sp<SkImage>);

Просмотреть файл

@ -11,11 +11,11 @@
#include "SkDrawLooper.h"
#include "SkPaint.h"
#include "SkPoint.h"
#include "SkXfermode.h"
#include "SkBlendMode.h"
class SK_API SkLayerDrawLooper : public SkDrawLooper {
public:
virtual ~SkLayerDrawLooper();
~SkLayerDrawLooper() override;
/**
* Bits specifies which aspects of the layer's paint should replace the
@ -51,15 +51,15 @@ public:
* The layer's paint's color is treated as the SRC
* The draw's paint's color is treated as the DST
* final-color = Mode(layers-color, draws-color);
* Any SkXfermode::Mode will work. Two common choices are:
* kSrc_Mode: to use the layer's color, ignoring the draw's
* kDst_Mode: to just keep the draw's color, ignoring the layer's
* Any SkBlendMode will work. Two common choices are:
* kSrc: to use the layer's color, ignoring the draw's
* kDst: to just keep the draw's color, ignoring the layer's
*/
struct SK_API LayerInfo {
BitFlags fPaintBits;
SkXfermode::Mode fColorMode;
SkVector fOffset;
bool fPostTranslate; //!< applies to fOffset
BitFlags fPaintBits;
SkBlendMode fColorMode;
SkVector fOffset;
bool fPostTranslate; //!< applies to fOffset
/**
* Initial the LayerInfo. Defaults to settings that will draw the
@ -71,9 +71,7 @@ public:
LayerInfo();
};
SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const override;
size_t contextSize() const override { return sizeof(LayerDrawLooperContext); }
SkDrawLooper::Context* makeContext(SkCanvas*, SkArenaAlloc*) const override;
bool asABlurShadow(BlurShadowRec* rec) const override;
@ -83,6 +81,8 @@ public:
static sk_sp<SkFlattenable> CreateProc(SkReadBuffer& buffer);
protected:
sk_sp<SkDrawLooper> onMakeColorSpace(SkColorSpaceXformer*) const override;
SkLayerDrawLooper();
void flatten(SkWriteBuffer&) const override;
@ -143,11 +143,6 @@ public:
* also reset the builder, so it can be used to build another looper.
*/
sk_sp<SkDrawLooper> detach();
#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
SkLayerDrawLooper* detachLooper() {
return (SkLayerDrawLooper*)this->detach().release();
}
#endif
private:
Rec* fRecs;

Просмотреть файл

@ -16,7 +16,7 @@ class SkPaint;
class SK_API SkLayerRasterizer : public SkRasterizer {
public:
virtual ~SkLayerRasterizer();
~SkLayerRasterizer() override;
class SK_API Builder {
public:
@ -58,15 +58,6 @@ public:
*/
sk_sp<SkLayerRasterizer> snapshot() const;
#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
SkLayerRasterizer* detachRasterizer() {
return this->detach().release();
}
SkLayerRasterizer* snapshotRasterizer() const {
return this->snapshot().release();
}
#endif
private:
SkDeque* fLayers;
};

Просмотреть файл

@ -41,49 +41,6 @@ public:
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
static SkImageFilter* CreateDistantLitDiffuse(const SkPoint3& direction,
SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
return MakeDistantLitDiffuse(direction, lightColor, surfaceScale, kd,
sk_ref_sp<SkImageFilter>(input), cropRect).release();
}
static SkImageFilter* CreatePointLitDiffuse(const SkPoint3& location,
SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
return MakePointLitDiffuse(location, lightColor, surfaceScale, kd,
sk_ref_sp<SkImageFilter>(input), cropRect).release();
}
static SkImageFilter* CreateSpotLitDiffuse(const SkPoint3& location,
const SkPoint3& target, SkScalar specularExponent, SkScalar cutoffAngle,
SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
return MakeSpotLitDiffuse(location, target, specularExponent, cutoffAngle,
lightColor, surfaceScale, kd,
sk_ref_sp<SkImageFilter>(input), cropRect).release();
}
static SkImageFilter* CreateDistantLitSpecular(const SkPoint3& direction,
SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
SkScalar shininess, SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
return MakeDistantLitSpecular(direction, lightColor, surfaceScale, ks, shininess,
sk_ref_sp<SkImageFilter>(input), cropRect).release();
}
static SkImageFilter* CreatePointLitSpecular(const SkPoint3& location,
SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
SkScalar shininess, SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
return MakePointLitSpecular(location, lightColor, surfaceScale, ks, shininess,
sk_ref_sp<SkImageFilter>(input), cropRect).release();
}
static SkImageFilter* CreateSpotLitSpecular(const SkPoint3& location,
const SkPoint3& target, SkScalar specularExponent, SkScalar cutoffAngle,
SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
SkScalar shininess, SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
return MakeSpotLitSpecular(location, target, specularExponent, cutoffAngle,
lightColor, surfaceScale, ks, shininess,
sk_ref_sp<SkImageFilter>(input), cropRect).release();
}
#endif
protected:
SkLightingImageFilter(sk_sp<SkImageFilterLight> light,
SkScalar surfaceScale,

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше