void paintArtifactToSkCanvas(const PaintArtifact& artifact, SkCanvas* canvas)
{
    SkAutoCanvasRestore restore(canvas, true);
    const DisplayItemList& displayItems = artifact.displayItemList();
    const EffectPaintPropertyNode* previousEffect = nullptr;
    for (const PaintChunk& chunk : artifact.paintChunks()) {
        // Setup the canvas clip state first because it clobbers matrix state.
        for (const ClipPaintPropertyNode* currentClipNode = chunk.properties.clip.get();
            currentClipNode; currentClipNode = currentClipNode->parent()) {
            canvas->setMatrix(TransformationMatrix::toSkMatrix44(totalTransform(currentClipNode->localTransformSpace())));
            canvas->clipRRect(currentClipNode->clipRect());
        }

        // Set the canvas state to match the paint properties.
        TransformationMatrix combinedMatrix = totalTransform(chunk.properties.transform.get());
        canvas->setMatrix(TransformationMatrix::toSkMatrix44(combinedMatrix));

        // Push and pop layers on the SkCanvas as necessary to implement the
        // current effect.
        // TODO(pdr): This will need to be revisited for non-opacity effects
        // such as filters which require interleaving with transforms.
        const EffectPaintPropertyNode* chunkEffect = chunk.properties.effect.get();
        applyEffectNodesToCanvas(previousEffect, chunkEffect, canvas);
        previousEffect = chunkEffect;

        // Draw the display items in the paint chunk.
        DisplayItemList::const_iterator begin = displayItems.begin() + chunk.beginIndex;
        DisplayItemList::const_iterator end = displayItems.begin() + chunk.endIndex;
        for (DisplayItemList::const_iterator it = begin; it != end; ++it)
            paintDisplayItemToSkCanvas(*it, canvas);
    }
}
Exemplo n.º 2
0
			void
			Shape::setTransform(const ::rl::math::Transform& transform)
			{
				this->transform = transform;
				
				::rl::math::Transform totalTransform = this->transform * this->baseTransform;
				
				::dGeomSetOffsetPosition(
					this->geom,
					static_cast< ::dReal>(totalTransform(0, 3)),
					static_cast< ::dReal>(totalTransform(1, 3)),
					static_cast< ::dReal>(totalTransform(2, 3))
				);
				
				::dMatrix3 rotation;
				
				for (::std::size_t i = 0; i < 3; ++i)
				{
					for (::std::size_t j = 0; j < 3; ++j)
					{
						rotation[i * 4 + j] = static_cast< ::dReal>(totalTransform(i, j));
					}
				}
				
				rotation[3] = 0;
				rotation[7] = 0;
				rotation[11] = 0;
				
				::dGeomSetOffsetRotation(this->geom, rotation);
			}