2015-02-02 18:39:33 -08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#include "GlopBuilder.h"
|
|
|
|
|
|
|
|
#include "Caches.h"
|
|
|
|
#include "Glop.h"
|
|
|
|
#include "Matrix.h"
|
|
|
|
#include "renderstate/MeshState.h"
|
|
|
|
#include "renderstate/RenderState.h"
|
2015-02-05 10:12:38 -08:00
|
|
|
#include "SkiaShader.h"
|
|
|
|
#include "Texture.h"
|
2015-02-02 18:39:33 -08:00
|
|
|
#include "utils/PaintUtils.h"
|
2015-02-05 10:12:38 -08:00
|
|
|
#include "VertexBuffer.h"
|
2015-02-02 18:39:33 -08:00
|
|
|
|
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
#include <SkPaint.h>
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
2015-02-05 10:12:38 -08:00
|
|
|
#define TRIGGER_STAGE(stageFlag) \
|
|
|
|
LOG_ALWAYS_FATAL_IF(stageFlag & mStageFlags, "Stage %d cannot be run twice"); \
|
2015-02-11 13:17:06 -08:00
|
|
|
mStageFlags = static_cast<StageFlags>(mStageFlags | (stageFlag))
|
2015-02-05 10:12:38 -08:00
|
|
|
|
2015-02-09 18:58:32 -08:00
|
|
|
#define REQUIRE_STAGES(requiredFlags) \
|
2015-02-11 13:17:06 -08:00
|
|
|
LOG_ALWAYS_FATAL_IF((mStageFlags & (requiredFlags)) != (requiredFlags), \
|
2015-02-09 18:58:32 -08:00
|
|
|
"not prepared for current stage")
|
|
|
|
|
2015-02-13 17:47:21 -08:00
|
|
|
static void setUnitQuadTextureCoords(Rect uvs, TextureVertex* quadVertex) {
|
2015-02-11 13:17:06 -08:00
|
|
|
TextureVertex::setUV(quadVertex++, uvs.left, uvs.top);
|
|
|
|
TextureVertex::setUV(quadVertex++, uvs.right, uvs.top);
|
|
|
|
TextureVertex::setUV(quadVertex++, uvs.left, uvs.bottom);
|
|
|
|
TextureVertex::setUV(quadVertex++, uvs.right, uvs.bottom);
|
|
|
|
}
|
|
|
|
|
2015-02-02 18:39:33 -08:00
|
|
|
GlopBuilder::GlopBuilder(RenderState& renderState, Caches& caches, Glop* outGlop)
|
|
|
|
: mRenderState(renderState)
|
|
|
|
, mCaches(caches)
|
2015-02-13 17:47:21 -08:00
|
|
|
, mShader(nullptr)
|
2015-02-11 13:17:06 -08:00
|
|
|
, mOutGlop(outGlop) {
|
2015-02-05 10:12:38 -08:00
|
|
|
mStageFlags = kInitialStage;
|
|
|
|
}
|
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Mesh
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2015-02-05 10:12:38 -08:00
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
GlopBuilder& GlopBuilder::setMeshUnitQuad() {
|
|
|
|
TRIGGER_STAGE(kMeshStage);
|
2015-02-05 10:12:38 -08:00
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
mOutGlop->mesh.vertexFlags = kNone_Attrib;
|
2015-02-05 10:12:38 -08:00
|
|
|
mOutGlop->mesh.primitiveMode = GL_TRIANGLE_STRIP;
|
2015-02-11 13:17:06 -08:00
|
|
|
mOutGlop->mesh.vertexBufferObject = mRenderState.meshState().getUnitQuadVBO();
|
|
|
|
mOutGlop->mesh.vertices = nullptr;
|
2015-02-05 10:12:38 -08:00
|
|
|
mOutGlop->mesh.indexBufferObject = 0;
|
2015-02-11 13:17:06 -08:00
|
|
|
mOutGlop->mesh.indices = nullptr;
|
|
|
|
mOutGlop->mesh.elementCount = 4;
|
|
|
|
mOutGlop->mesh.stride = kTextureVertexStride;
|
|
|
|
mOutGlop->mesh.texCoordOffset = nullptr;
|
2015-02-05 10:12:38 -08:00
|
|
|
return *this;
|
2015-02-02 18:39:33 -08:00
|
|
|
}
|
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
GlopBuilder& GlopBuilder::setMeshTexturedUnitQuad(const UvMapper* uvMapper,
|
|
|
|
bool isAlphaMaskTexture) {
|
2015-02-05 10:12:38 -08:00
|
|
|
TRIGGER_STAGE(kMeshStage);
|
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
mOutGlop->mesh.vertexFlags = kTextureCoord_Attrib;
|
2015-02-02 18:39:33 -08:00
|
|
|
mOutGlop->mesh.primitiveMode = GL_TRIANGLE_STRIP;
|
2015-02-11 13:17:06 -08:00
|
|
|
|
|
|
|
if (CC_UNLIKELY(uvMapper)) {
|
|
|
|
Rect uvs(0, 0, 1, 1);
|
|
|
|
uvMapper->map(uvs);
|
|
|
|
setUnitQuadTextureCoords(uvs, &mOutGlop->mesh.mappedVertices[0]);
|
|
|
|
|
|
|
|
mOutGlop->mesh.vertexBufferObject = 0;
|
|
|
|
mOutGlop->mesh.vertices = &mOutGlop->mesh.mappedVertices[0];
|
|
|
|
} else {
|
|
|
|
// standard UV coordinates, use regular unit quad VBO
|
|
|
|
mOutGlop->mesh.vertexBufferObject = mRenderState.meshState().getUnitQuadVBO();
|
|
|
|
mOutGlop->mesh.vertices = nullptr;
|
|
|
|
}
|
2015-02-02 18:39:33 -08:00
|
|
|
mOutGlop->mesh.indexBufferObject = 0;
|
2015-02-05 10:12:38 -08:00
|
|
|
mOutGlop->mesh.indices = nullptr;
|
2015-02-11 13:17:06 -08:00
|
|
|
mOutGlop->mesh.elementCount = 4;
|
2015-02-02 18:39:33 -08:00
|
|
|
mOutGlop->mesh.stride = kTextureVertexStride;
|
2015-02-11 13:17:06 -08:00
|
|
|
mOutGlop->mesh.texCoordOffset = (GLvoid*) kMeshTextureOffset;
|
|
|
|
|
|
|
|
mDescription.hasTexture = true;
|
|
|
|
mDescription.hasAlpha8Texture = isAlphaMaskTexture;
|
2015-02-02 18:39:33 -08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-02-06 15:25:51 -08:00
|
|
|
GlopBuilder& GlopBuilder::setMeshIndexedQuads(void* vertexData, int quadCount) {
|
|
|
|
TRIGGER_STAGE(kMeshStage);
|
|
|
|
|
|
|
|
mOutGlop->mesh.vertexFlags = kNone_Attrib;
|
|
|
|
mOutGlop->mesh.primitiveMode = GL_TRIANGLES;
|
|
|
|
mOutGlop->mesh.vertexBufferObject = 0;
|
|
|
|
mOutGlop->mesh.vertices = vertexData;
|
|
|
|
mOutGlop->mesh.indexBufferObject = mRenderState.meshState().getQuadListIBO();
|
|
|
|
mOutGlop->mesh.indices = nullptr;
|
2015-02-11 13:17:06 -08:00
|
|
|
mOutGlop->mesh.elementCount = 6 * quadCount;
|
2015-02-06 15:25:51 -08:00
|
|
|
mOutGlop->mesh.stride = kVertexStride;
|
2015-02-11 13:17:06 -08:00
|
|
|
mOutGlop->mesh.texCoordOffset = nullptr;
|
2015-02-06 15:25:51 -08:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
GlopBuilder& GlopBuilder::setMeshVertexBuffer(const VertexBuffer& vertexBuffer, bool shadowInterp) {
|
|
|
|
TRIGGER_STAGE(kMeshStage);
|
2015-02-05 10:12:38 -08:00
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
const VertexBuffer::MeshFeatureFlags flags = vertexBuffer.getMeshFeatureFlags();
|
2015-02-06 15:25:51 -08:00
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
bool alphaVertex = flags & VertexBuffer::kAlpha;
|
|
|
|
bool indices = flags & VertexBuffer::kIndices;
|
|
|
|
mOutGlop->mesh.vertexFlags = alphaVertex ? kAlpha_Attrib : kNone_Attrib;
|
|
|
|
mOutGlop->mesh.primitiveMode = GL_TRIANGLE_STRIP;
|
|
|
|
mOutGlop->mesh.vertexBufferObject = 0;
|
|
|
|
mOutGlop->mesh.vertices = vertexBuffer.getBuffer();
|
|
|
|
mOutGlop->mesh.indexBufferObject = 0;
|
|
|
|
mOutGlop->mesh.indices = vertexBuffer.getIndices();
|
|
|
|
mOutGlop->mesh.elementCount = indices
|
|
|
|
? vertexBuffer.getIndexCount() : vertexBuffer.getVertexCount();
|
|
|
|
mOutGlop->mesh.stride = alphaVertex ? kAlphaVertexStride : kVertexStride;
|
2015-02-02 18:39:33 -08:00
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
mDescription.hasVertexAlpha = alphaVertex;
|
|
|
|
mDescription.useShadowAlphaInterp = shadowInterp;
|
2015-02-06 15:25:51 -08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Fill
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2015-02-06 15:25:51 -08:00
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
void GlopBuilder::setFill(int color, float alphaScale, SkXfermode::Mode mode,
|
|
|
|
const SkShader* shader, const SkColorFilter* colorFilter) {
|
2015-02-02 18:39:33 -08:00
|
|
|
if (mode != SkXfermode::kClear_Mode) {
|
|
|
|
float alpha = (SkColorGetA(color) / 255.0f) * alphaScale;
|
2015-02-05 10:12:38 -08:00
|
|
|
if (!shader) {
|
|
|
|
float colorScale = alpha / 255.0f;
|
|
|
|
mOutGlop->fill.color = {
|
|
|
|
colorScale * SkColorGetR(color),
|
|
|
|
colorScale * SkColorGetG(color),
|
2015-02-11 13:17:06 -08:00
|
|
|
colorScale * SkColorGetB(color),
|
|
|
|
alpha
|
2015-02-05 10:12:38 -08:00
|
|
|
};
|
|
|
|
} else {
|
2015-02-11 13:17:06 -08:00
|
|
|
mOutGlop->fill.color = { 1, 1, 1, alpha };
|
2015-02-02 18:39:33 -08:00
|
|
|
}
|
|
|
|
} else {
|
2015-02-11 13:17:06 -08:00
|
|
|
mOutGlop->fill.color = { 0, 0, 0, 1 };
|
2015-02-02 18:39:33 -08:00
|
|
|
}
|
|
|
|
const bool SWAP_SRC_DST = false;
|
|
|
|
|
2015-02-05 10:12:38 -08:00
|
|
|
mOutGlop->blend = { GL_ZERO, GL_ZERO };
|
2015-02-02 18:39:33 -08:00
|
|
|
if (mOutGlop->fill.color.a < 1.0f
|
2015-02-09 18:58:32 -08:00
|
|
|
|| (mOutGlop->mesh.vertexFlags & kAlpha_Attrib)
|
2015-02-11 13:17:06 -08:00
|
|
|
|| (mOutGlop->fill.texture && mOutGlop->fill.texture->blend)
|
|
|
|
|| mOutGlop->roundRectClipState
|
2015-02-05 10:12:38 -08:00
|
|
|
|| PaintUtils::isBlendedShader(shader)
|
2015-02-02 18:39:33 -08:00
|
|
|
|| PaintUtils::isBlendedColorFilter(colorFilter)
|
|
|
|
|| mode != SkXfermode::kSrcOver_Mode) {
|
|
|
|
if (CC_LIKELY(mode <= SkXfermode::kScreen_Mode)) {
|
|
|
|
Blend::getFactors(mode, SWAP_SRC_DST,
|
|
|
|
&mOutGlop->blend.src, &mOutGlop->blend.dst);
|
|
|
|
} else {
|
|
|
|
// These blend modes are not supported by OpenGL directly and have
|
|
|
|
// to be implemented using shaders. Since the shader will perform
|
|
|
|
// the blending, don't enable GL blending off here
|
|
|
|
// If the blend mode cannot be implemented using shaders, fall
|
|
|
|
// back to the default SrcOver blend mode instead
|
2015-02-05 10:12:38 -08:00
|
|
|
if (CC_UNLIKELY(mCaches.extensions().hasFramebufferFetch())) {
|
2015-02-02 18:39:33 -08:00
|
|
|
mDescription.framebufferMode = mode;
|
|
|
|
mDescription.swapSrcDst = SWAP_SRC_DST;
|
|
|
|
// blending in shader, don't enable
|
|
|
|
} else {
|
|
|
|
// unsupported
|
|
|
|
Blend::getFactors(SkXfermode::kSrcOver_Mode, SWAP_SRC_DST,
|
|
|
|
&mOutGlop->blend.src, &mOutGlop->blend.dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-13 17:47:21 -08:00
|
|
|
mShader = shader; // shader resolved in ::build()
|
2015-02-05 10:12:38 -08:00
|
|
|
|
|
|
|
if (colorFilter) {
|
|
|
|
SkColor color;
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
SkScalar srcColorMatrix[20];
|
|
|
|
if (colorFilter->asColorMode(&color, &mode)) {
|
|
|
|
mOutGlop->fill.filterMode = mDescription.colorOp = ProgramDescription::kColorBlend;
|
|
|
|
mDescription.colorMode = mode;
|
|
|
|
|
|
|
|
const float alpha = SkColorGetA(color) / 255.0f;
|
|
|
|
float colorScale = alpha / 255.0f;
|
|
|
|
mOutGlop->fill.filter.color = {
|
|
|
|
colorScale * SkColorGetR(color),
|
|
|
|
colorScale * SkColorGetG(color),
|
|
|
|
colorScale * SkColorGetB(color),
|
2015-02-11 13:17:06 -08:00
|
|
|
alpha,
|
2015-02-05 10:12:38 -08:00
|
|
|
};
|
|
|
|
} else if (colorFilter->asColorMatrix(srcColorMatrix)) {
|
|
|
|
mOutGlop->fill.filterMode = mDescription.colorOp = ProgramDescription::kColorMatrix;
|
|
|
|
|
|
|
|
float* colorMatrix = mOutGlop->fill.filter.matrix.matrix;
|
|
|
|
memcpy(colorMatrix, srcColorMatrix, 4 * sizeof(float));
|
|
|
|
memcpy(&colorMatrix[4], &srcColorMatrix[5], 4 * sizeof(float));
|
|
|
|
memcpy(&colorMatrix[8], &srcColorMatrix[10], 4 * sizeof(float));
|
|
|
|
memcpy(&colorMatrix[12], &srcColorMatrix[15], 4 * sizeof(float));
|
|
|
|
|
|
|
|
// Skia uses the range [0..255] for the addition vector, but we need
|
|
|
|
// the [0..1] range to apply the vector in GLSL
|
|
|
|
float* colorVector = mOutGlop->fill.filter.matrix.vector;
|
|
|
|
colorVector[0] = srcColorMatrix[4] / 255.0f;
|
|
|
|
colorVector[1] = srcColorMatrix[9] / 255.0f;
|
|
|
|
colorVector[2] = srcColorMatrix[14] / 255.0f;
|
|
|
|
colorVector[3] = srcColorMatrix[19] / 255.0f;
|
2015-02-06 15:25:51 -08:00
|
|
|
} else {
|
|
|
|
LOG_ALWAYS_FATAL("unsupported ColorFilter");
|
2015-02-05 10:12:38 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mOutGlop->fill.filterMode = ProgramDescription::kColorNone;
|
|
|
|
}
|
2015-02-11 13:17:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
GlopBuilder& GlopBuilder::setFillTexturePaint(Texture& texture, bool isAlphaMaskTexture,
|
|
|
|
const SkPaint* paint, float alphaScale) {
|
|
|
|
TRIGGER_STAGE(kFillStage);
|
|
|
|
REQUIRE_STAGES(kMeshStage);
|
|
|
|
|
|
|
|
mOutGlop->fill.texture = &texture;
|
|
|
|
mOutGlop->fill.textureFilter = PaintUtils::getFilter(paint);
|
2015-02-12 10:41:39 -08:00
|
|
|
mOutGlop->fill.textureClamp = GL_CLAMP_TO_EDGE;
|
2015-02-11 13:17:06 -08:00
|
|
|
|
|
|
|
if (paint) {
|
|
|
|
int color = paint->getColor();
|
|
|
|
SkShader* shader = paint->getShader();
|
|
|
|
|
|
|
|
if (!isAlphaMaskTexture) {
|
|
|
|
// Texture defines color, so disable shaders, and reset all non-alpha color channels
|
|
|
|
color |= 0x00FFFFFF;
|
|
|
|
shader = nullptr;
|
|
|
|
}
|
|
|
|
setFill(color, alphaScale, PaintUtils::getXfermode(paint->getXfermode()),
|
|
|
|
shader, paint->getColorFilter());
|
|
|
|
} else {
|
|
|
|
mOutGlop->fill.color = { alphaScale, alphaScale, alphaScale, alphaScale };
|
|
|
|
|
|
|
|
const bool SWAP_SRC_DST = false;
|
|
|
|
if (alphaScale < 1.0f
|
|
|
|
|| (mOutGlop->mesh.vertexFlags & kAlpha_Attrib)
|
|
|
|
|| texture.blend
|
|
|
|
|| mOutGlop->roundRectClipState) {
|
|
|
|
Blend::getFactors(SkXfermode::kSrcOver_Mode, SWAP_SRC_DST,
|
|
|
|
&mOutGlop->blend.src, &mOutGlop->blend.dst);
|
|
|
|
} else {
|
|
|
|
mOutGlop->blend = { GL_ZERO, GL_ZERO };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAlphaMaskTexture) {
|
|
|
|
mDescription.modulate = mOutGlop->fill.color.a < 1.0f
|
|
|
|
|| mOutGlop->fill.color.r > 0.0f
|
|
|
|
|| mOutGlop->fill.color.g > 0.0f
|
|
|
|
|| mOutGlop->fill.color.b > 0.0f;
|
|
|
|
} else {
|
|
|
|
mDescription.modulate = mOutGlop->fill.color.a < 1.0f;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
GlopBuilder& GlopBuilder::setFillPaint(const SkPaint& paint, float alphaScale) {
|
|
|
|
TRIGGER_STAGE(kFillStage);
|
|
|
|
REQUIRE_STAGES(kMeshStage);
|
|
|
|
|
|
|
|
mOutGlop->fill.texture = nullptr;
|
2015-02-12 10:41:39 -08:00
|
|
|
mOutGlop->fill.textureFilter = GL_INVALID_ENUM;
|
|
|
|
mOutGlop->fill.textureClamp = GL_INVALID_ENUM;
|
2015-02-11 13:17:06 -08:00
|
|
|
|
|
|
|
setFill(paint.getColor(), alphaScale, PaintUtils::getXfermode(paint.getXfermode()),
|
|
|
|
paint.getShader(), paint.getColorFilter());
|
|
|
|
mDescription.modulate = mOutGlop->fill.color.a < 1.0f;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-02-12 10:41:39 -08:00
|
|
|
GlopBuilder& GlopBuilder::setFillPathTexturePaint(Texture& texture,
|
|
|
|
const SkPaint& paint, float alphaScale) {
|
|
|
|
TRIGGER_STAGE(kFillStage);
|
|
|
|
REQUIRE_STAGES(kMeshStage);
|
|
|
|
|
|
|
|
mOutGlop->fill.texture = &texture;
|
|
|
|
|
|
|
|
//specify invalid, since these are always static for path textures
|
|
|
|
mOutGlop->fill.textureFilter = GL_INVALID_ENUM;
|
|
|
|
mOutGlop->fill.textureClamp = GL_INVALID_ENUM;
|
|
|
|
|
|
|
|
setFill(paint.getColor(), alphaScale, PaintUtils::getXfermode(paint.getXfermode()),
|
|
|
|
paint.getShader(), paint.getColorFilter());
|
|
|
|
|
|
|
|
mDescription.modulate = mOutGlop->fill.color.a < 1.0f
|
|
|
|
|| mOutGlop->fill.color.r > 0.0f
|
|
|
|
|| mOutGlop->fill.color.g > 0.0f
|
|
|
|
|| mOutGlop->fill.color.b > 0.0f;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Transform
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
GlopBuilder& GlopBuilder::setTransformClip(const Matrix4& ortho,
|
|
|
|
const Matrix4& transform, bool fudgingOffset) {
|
|
|
|
TRIGGER_STAGE(kTransformStage);
|
|
|
|
|
|
|
|
mOutGlop->transform.ortho.load(ortho);
|
|
|
|
mOutGlop->transform.canvas.load(transform);
|
|
|
|
mOutGlop->transform.fudgingOffset = fudgingOffset;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ModelView
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
GlopBuilder& GlopBuilder::setModelViewMapUnitToRect(const Rect destination) {
|
|
|
|
TRIGGER_STAGE(kModelViewStage);
|
|
|
|
|
|
|
|
mOutGlop->transform.modelView.loadTranslate(destination.left, destination.top, 0.0f);
|
|
|
|
mOutGlop->transform.modelView.scale(destination.getWidth(), destination.getHeight(), 1.0f);
|
|
|
|
mOutGlop->bounds = destination;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
GlopBuilder& GlopBuilder::setModelViewMapUnitToRectSnap(const Rect destination) {
|
|
|
|
TRIGGER_STAGE(kModelViewStage);
|
|
|
|
REQUIRE_STAGES(kTransformStage | kFillStage);
|
|
|
|
|
|
|
|
float left = destination.left;
|
|
|
|
float top = destination.top;
|
|
|
|
|
|
|
|
const Matrix4& canvasTransform = mOutGlop->transform.canvas;
|
|
|
|
if (CC_LIKELY(canvasTransform.isPureTranslate())) {
|
|
|
|
const float translateX = canvasTransform.getTranslateX();
|
|
|
|
const float translateY = canvasTransform.getTranslateY();
|
|
|
|
|
|
|
|
left = (int) floorf(left + translateX + 0.5f) - translateX;
|
|
|
|
top = (int) floorf(top + translateY + 0.5f) - translateY;
|
|
|
|
mOutGlop->fill.textureFilter = GL_NEAREST;
|
|
|
|
}
|
|
|
|
|
|
|
|
mOutGlop->transform.modelView.loadTranslate(left, top, 0.0f);
|
|
|
|
mOutGlop->transform.modelView.scale(destination.getWidth(), destination.getHeight(), 1.0f);
|
|
|
|
mOutGlop->bounds = destination;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
GlopBuilder& GlopBuilder::setModelViewOffsetRect(float offsetX, float offsetY, const Rect source) {
|
|
|
|
TRIGGER_STAGE(kModelViewStage);
|
|
|
|
|
|
|
|
mOutGlop->transform.modelView.loadTranslate(offsetX, offsetY, 0.0f);
|
|
|
|
mOutGlop->bounds = source;
|
|
|
|
mOutGlop->bounds.translate(offsetX, offsetY);
|
|
|
|
return *this;
|
|
|
|
}
|
2015-02-02 18:39:33 -08:00
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
GlopBuilder& GlopBuilder::setRoundRectClipState(const RoundRectClipState* roundRectClipState) {
|
|
|
|
TRIGGER_STAGE(kRoundRectClipStage);
|
|
|
|
|
|
|
|
mOutGlop->roundRectClipState = roundRectClipState;
|
|
|
|
mDescription.hasRoundRectClip = roundRectClipState != nullptr;
|
2015-02-02 18:39:33 -08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Build
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-02-02 18:39:33 -08:00
|
|
|
void GlopBuilder::build() {
|
2015-02-09 18:58:32 -08:00
|
|
|
REQUIRE_STAGES(kAllStages);
|
2015-02-05 10:12:38 -08:00
|
|
|
|
2015-02-13 17:47:21 -08:00
|
|
|
// serialize shader info into ShaderData
|
|
|
|
GLuint textureUnit = mOutGlop->fill.texture ? 1 : 0;
|
|
|
|
SkiaShader::store(mCaches, mShader, mOutGlop->transform.modelView,
|
|
|
|
&textureUnit, &mDescription, &(mOutGlop->fill.skiaShaderData));
|
|
|
|
|
2015-02-02 18:39:33 -08:00
|
|
|
mOutGlop->fill.program = mCaches.programCache.get(mDescription);
|
2015-02-05 10:12:38 -08:00
|
|
|
mOutGlop->transform.canvas.mapRect(mOutGlop->bounds);
|
2015-02-11 13:17:06 -08:00
|
|
|
|
|
|
|
// duplicates ProgramCache's definition of color uniform presence
|
|
|
|
const bool singleColor = !mDescription.hasTexture
|
|
|
|
&& !mDescription.hasExternalTexture
|
|
|
|
&& !mDescription.hasGradient
|
|
|
|
&& !mDescription.hasBitmap;
|
|
|
|
mOutGlop->fill.colorEnabled = mDescription.modulate || singleColor;
|
2015-02-02 18:39:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace uirenderer */
|
|
|
|
} /* namespace android */
|