本文整理汇总了C++中SkTArray::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ SkTArray::push_back方法的具体用法?C++ SkTArray::push_back怎么用?C++ SkTArray::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkTArray
的用法示例。
在下文中一共展示了SkTArray::push_back方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CubicToQuads
void CubicToQuads(const SkDCubic& cubic, double precision, SkTArray<SkDQuad, true>& quads) {
SkTArray<double, true> ts;
toQuadraticTs(&cubic, precision, &ts);
if (ts.count() <= 0) {
SkDQuad quad = cubic.toQuad();
quads.push_back(quad);
return;
}
double tStart = 0;
for (int i1 = 0; i1 <= ts.count(); ++i1) {
const double tEnd = i1 < ts.count() ? ts[i1] : 1;
SkDRect bounds;
bounds.setBounds(cubic);
SkDCubic part = cubic.subDivide(tStart, tEnd);
SkDQuad quad = part.toQuad();
if (quad[1].fX < bounds.fLeft) {
quad[1].fX = bounds.fLeft;
} else if (quad[1].fX > bounds.fRight) {
quad[1].fX = bounds.fRight;
}
if (quad[1].fY < bounds.fTop) {
quad[1].fY = bounds.fTop;
} else if (quad[1].fY > bounds.fBottom) {
quad[1].fY = bounds.fBottom;
}
quads.push_back(quad);
tStart = tEnd;
}
}
示例2: handle_cmd
static void handle_cmd(struct android_app* app, int32_t cmd) {
struct VisualBenchState* state = (struct VisualBenchState*)app->userData;
switch (cmd) {
case APP_CMD_INIT_WINDOW:
// The window is being shown, get it ready.
if (state->fApp->window != nullptr && kInit_State == state->fState) {
// drain any events that occurred before |window| was assigned.
while (SkEvent::ProcessEvent());
// Start normal Skia sequence
application_init();
SkTArray<const char*> args;
args.push_back("VisualBench");
for (int i = 0; i < state->fFlags.count(); i++) {
SkDebugf(state->fFlags[i].c_str());
args.push_back(state->fFlags[i].c_str());
}
state->fWindow = create_sk_window((void*)state->fApp->window,
args.count(),
const_cast<char**>(args.begin()));
state->fWindow->forceInvalAll();
state->fState = kAnimate_State;
}
break;
case APP_CMD_TERM_WINDOW:
state->fState = kDestroyRequested_State;
break;
}
}
示例3: onDraw
void onDraw(SkCanvas* canvas) override {
// This GM exists to test a specific feature of the GPU backend. It does not work with the
// sw rasterizer, tile modes, etc.
if (nullptr == canvas->getGrContext()) {
skiagm::GM::DrawGpuOnlyMessage(canvas);
return;
}
SkPaint paint;
SkTArray<SkMatrix> devMats;
devMats.push_back().reset();
devMats.push_back().setRotate(45, 500, 500);
devMats.push_back().setRotate(-30, 200, 200);
devMats.back().setPerspX(-SK_Scalar1 / 2000);
devMats.back().setPerspY(SK_Scalar1 / 1000);
SkTArray<SkMatrix> viewMats;
viewMats.push_back().setScale(0.75f, 0.75f);
viewMats.push_back().setRotate(45, 50, 50);
viewMats.back().postScale(0.5f, 1.1f);
canvas->translate(10, 20);
canvas->save();
SkScalar tx = 0, maxTy = 0;
static const SkScalar kW = 900;
for (int aa = 0; aa < 2; ++aa) {
for (int i = 0; i < fPrims.count(); ++i) {
for (int j = 0; j < devMats.count(); ++j) {
for (int k = 0; k < viewMats.count(); ++k) {
paint.setShader(new DCShader(devMats[j]))->unref();
paint.setAntiAlias(SkToBool(aa));
canvas->save();
canvas->concat(viewMats[k]);
SkRect bounds = fPrims[i]->draw(canvas, paint);
canvas->restore();
viewMats[k].mapRect(&bounds);
// add margins
bounds.fRight += 20;
bounds.fBottom += 20;
canvas->translate(bounds.fRight, 0);
tx += bounds.fRight;
maxTy = SkTMax(bounds.fBottom, maxTy);
if (tx > kW) {
tx = 0;
canvas->restore();
canvas->translate(0, maxTy);
canvas->save();
maxTy = 0;
}
}
}
}
}
canvas->restore();
}
示例4: write_subset
/**
* Helper function to write a bitmap subset to a file. Only called if subsets were created
* and a writePath was provided. Behaves differently depending on
* FLAGS_writeChecksumBasedFilenames. If true:
* Writes the image to a PNG file named according to the digest hash, as described in
* write_bitmap.
* If false:
* Creates a subdirectory called 'subsets' and writes a PNG to that directory. Also
* creates a subdirectory called 'extracted' and writes a bitmap created using
* extractSubset to a PNG in that directory. Both files will represent the same
* subrectangle and have the same name for convenient comparison. In this case, the
* digest is ignored.
*
* @param writePath Parent directory to hold the folders for the PNG files to write. Must
* not be NULL.
* @param subsetName Basename of the original file, with the dimensions of the subset tacked
* on. Used to name the new file/folder.
* @param bitmapAndDigestFromDecodeSubset SkBitmap (with digest) created by
* SkImageDecoder::DecodeSubset, using rect as the area to decode.
* @param rect Rectangle of the area decoded into bitmapFromDecodeSubset. Used to call
* extractSubset on originalBitmap to create a bitmap with the same dimensions/pixels as
* bitmapFromDecodeSubset (assuming decodeSubset worked properly).
* @param originalBitmap SkBitmap decoded from the same stream as bitmapFromDecodeSubset,
* using SkImageDecoder::decode to get the entire image. Used to create a PNG file for
* comparison to the PNG created by bitmapAndDigestFromDecodeSubset's bitmap.
* @return bool Whether the function succeeded at drawing the decoded subset and the extracted
* subset to files.
*/
static bool write_subset(const char* writePath, const SkString& subsetName,
const skiagm::BitmapAndDigest bitmapAndDigestFromDecodeSubset,
SkIRect rect, const SkBitmap& originalBitmap) {
// All parameters must be valid.
SkASSERT(writePath != NULL);
SkString subsetPath;
if (FLAGS_writeChecksumBasedFilenames) {
subsetPath.set(writePath);
} else {
// Create a subdirectory to hold the results of decodeSubset.
subsetPath = SkOSPath::SkPathJoin(writePath, "subsets");
if (!sk_mkdir(subsetPath.c_str())) {
gFailedSubsetDecodes.push_back().printf("Successfully decoded subset %s, but "
"failed to create a directory to write to.",
subsetName.c_str());
return false;
}
}
SkAssertResult(write_bitmap(subsetPath.c_str(), subsetName.c_str(),
bitmapAndDigestFromDecodeSubset));
gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", subsetName.c_str());
if (!FLAGS_writeChecksumBasedFilenames) {
// FIXME: The goal of extracting the subset is for visual comparison/using skdiff/skpdiff.
// Currently disabling for writeChecksumBasedFilenames since it will be trickier to
// determine which files to compare.
// Also use extractSubset from the original for visual comparison.
// Write the result to a file in a separate subdirectory.
SkBitmap extractedSubset;
if (!originalBitmap.extractSubset(&extractedSubset, rect)) {
gFailedSubsetDecodes.push_back().printf("Successfully decoded subset %s, but failed "
"to extract a similar subset for comparison.",
subsetName.c_str());
return false;
}
SkString dirExtracted = SkOSPath::SkPathJoin(writePath, "extracted");
if (!sk_mkdir(dirExtracted.c_str())) {
gFailedSubsetDecodes.push_back().printf("Successfully decoded subset%s, but failed "
"to create a directory for extractSubset "
"comparison.",
subsetName.c_str());
return false;
}
skiagm::BitmapAndDigest bitmapAndDigestFromExtractSubset(extractedSubset);
SkAssertResult(write_bitmap(dirExtracted.c_str(), subsetName.c_str(),
bitmapAndDigestFromExtractSubset));
}
return true;
}
示例5: GetJMethod
JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_init(JNIEnv* env,
jobject thiz, jobject jsampleActivity, jint msaaSampleCount)
{
// setup jni hooks to the java activity
gActivityGlue.m_env = env;
jclass clazz = env->FindClass("com/skia/SkiaSampleActivity");
gActivityGlue.m_obj = env->NewWeakGlobalRef(jsampleActivity);
gActivityGlue.m_setTitle = GetJMethod(env, clazz, "setTitle", "(Ljava/lang/CharSequence;)V");
gActivityGlue.m_setSlideList = GetJMethod(env, clazz, "setSlideList", "([Ljava/lang/String;)V");
gActivityGlue.m_addToDownloads = GetJMethod(env, clazz, "addToDownloads",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
env->DeleteLocalRef(clazz);
// setup jni hooks to the java renderer
clazz = env->FindClass("com/skia/SkiaSampleRenderer");
gWindowGlue.m_obj = env->NewWeakGlobalRef(thiz);
gWindowGlue.m_inval = GetJMethod(env, clazz, "requestRender", "()V");
gWindowGlue.m_queueSkEvent = GetJMethod(env, clazz, "queueSkEvent", "()V");
gWindowGlue.m_startTimer = GetJMethod(env, clazz, "startTimer", "(I)V");
gWindowGlue.m_getMSAASampleCount = GetJMethod(env, clazz, "getMSAASampleCount", "()I");
env->DeleteLocalRef(clazz);
application_init();
SkTArray<const char*> args;
args.push_back("SampleApp");
// TODO: push ability to select skp dir into the UI
args.push_back("--pictureDir");
args.push_back("/sdcard/skiabot/skia_skp");
SkString msaaSampleCountString;
if (msaaSampleCount > 0) {
args.push_back("--msaa");
msaaSampleCountString.appendS32(static_cast<uint32_t>(msaaSampleCount));
args.push_back(msaaSampleCountString.c_str());
}
gWindow = new SampleWindow(NULL, args.count(), const_cast<char**>(args.begin()), NULL);
// send the list of slides up to the activity
const int slideCount = gWindow->sampleCount();
jobjectArray slideList = env->NewObjectArray(slideCount, env->FindClass("java/lang/String"), env->NewStringUTF(""));
for (int i = 0; i < slideCount; i++) {
jstring slideTitle = env->NewStringUTF(gWindow->getSampleTitle(i).c_str());
env->SetObjectArrayElement(slideList, i, slideTitle);
env->DeleteLocalRef(slideTitle);
}
env->CallVoidMethod(gActivityGlue.m_obj, gActivityGlue.m_setSlideList, slideList);
env->DeleteLocalRef(slideList);
}
示例6: CameraView
CameraView() {
fRX = fRY = fRZ = 0;
fShaderIndex = 0;
fFrontFace = false;
for (int i = 0;; i++) {
SkString str;
str.printf("/skimages/elephant%d.jpeg", i);
SkBitmap bm;
if (decode_file(str.c_str(), &bm)) {
SkRect src = { 0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm.height()) };
SkRect dst = { -150, -150, 150, 150 };
SkMatrix matrix;
matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
fShaders.push_back(SkShader::MakeBitmapShader(bm,
SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode,
&matrix));
} else {
break;
}
}
this->setBGColor(0xFFDDDDDD);
}
示例7: setupSingleVbo
void GLCpuPosInstancedArraysBench::setupSingleVbo(const GrGLInterface* gl,
const SkMatrix* viewMatrices) {
// Constants for our various shader programs
Vertex vertices[kVerticesPerTri * kNumTri];
for (uint32_t i = 0; i < kNumTri; i++) {
Vertex* v = &vertices[i * kVerticesPerTri];
v[0].fPositions.set(-1.0f, -1.0f);
v[1].fPositions.set( 1.0f, -1.0f);
v[2].fPositions.set( 1.0f, 1.0f);
SkPoint* position = reinterpret_cast<SkPoint*>(v);
viewMatrices[i].mapPointsWithStride(position, sizeof(Vertex), kVerticesPerTri);
// set colors
float color = i == kNumTri - 1 ? 1.0f : 0.0f;
for (uint32_t j = 0; j < kVerticesPerTri; j++) {
uint32_t offset = 0;
v->fColors[offset++] = color; v->fColors[offset++] = 0.0f; v->fColors[offset++] = 0.0f;
v++;
}
}
GrGLuint vbo;
// setup VBO
GR_GL_CALL(gl, GenBuffers(1, &vbo));
GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, vbo));
GR_GL_CALL(gl, EnableVertexAttribArray(0));
GR_GL_CALL(gl, EnableVertexAttribArray(1));
GR_GL_CALL(gl, VertexAttribPointer(0, 2, GR_GL_FLOAT, GR_GL_FALSE, sizeof(Vertex),
(GrGLvoid*)0));
GR_GL_CALL(gl, VertexAttribPointer(1, 3, GR_GL_FLOAT, GR_GL_FALSE, sizeof(Vertex),
(GrGLvoid*)(sizeof(SkPoint))));
GR_GL_CALL(gl, BufferData(GR_GL_ARRAY_BUFFER, sizeof(vertices), vertices, GR_GL_STATIC_DRAW));
fBuffers.push_back(vbo);
}
示例8: FindOrAdd
int FindOrAdd(IDWriteFontFileLoader* fontFileLoader,
const void* refKey, UINT32 refKeySize) const
{
SkTScopedComPtr<IUnknown> fontFileLoaderId;
HR_GENERAL(fontFileLoader->QueryInterface(&fontFileLoaderId),
"Failed to re-convert to IDWriteFontFileLoader.",
SkFontIdentity::kInvalidDataId);
SkAutoMutexAcquire ama(fDataIdCacheMutex);
int count = fDataIdCache.count();
int i;
for (i = 0; i < count; ++i) {
const DataId& current = fDataIdCache[i];
if (fontFileLoaderId.get() == current.fLoader &&
refKeySize == current.fKeySize &&
0 == memcmp(refKey, current.fKey, refKeySize))
{
return i;
}
}
DataId& added = fDataIdCache.push_back();
added.fLoader = fontFileLoaderId.release(); // Ref is passed.
added.fKey = sk_malloc_throw(refKeySize);
memcpy(added.fKey, refKey, refKeySize);
added.fKeySize = refKeySize;
return i;
}
示例9: push_sink
static void push_sink(const SkCommandLineConfig& config, Sink* s) {
SkAutoTDelete<Sink> sink(s);
// Try a simple Src as a canary. If it fails, skip this sink.
struct : public Src {
Error draw(SkCanvas* c) const override {
c->drawRect(SkRect::MakeWH(1,1), SkPaint());
return "";
}
SkISize size() const override { return SkISize::Make(16, 16); }
Name name() const override { return "justOneRect"; }
} justOneRect;
SkBitmap bitmap;
SkDynamicMemoryWStream stream;
SkString log;
Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
if (err.isFatal()) {
info("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
exit(1);
}
TaggedSink& ts = gSinks.push_back();
ts.reset(sink.release());
ts.tag = config.getTag();
}
示例10: buildNameToFamilyMap
void buildNameToFamilyMap(SkTDArray<FontFamily*> families) {
for (int i = 0; i < families.count(); i++) {
FontFamily& family = *families[i];
SkTDArray<NameToFamily>* nameToFamily = &fNameToFamilyMap;
if (family.fIsFallbackFont) {
nameToFamily = &fFallbackNameToFamilyMap;
if (0 == family.fNames.count()) {
SkString& fallbackName = family.fNames.push_back();
fallbackName.printf("%.2x##fallback", i);
}
}
SkFontStyleSet_Android* newSet =
SkNEW_ARGS(SkFontStyleSet_Android, (family, fScanner));
if (0 == newSet->count()) {
SkDELETE(newSet);
continue;
}
fFontStyleSets.push_back().reset(newSet);
for (int j = 0; j < family.fNames.count(); j++) {
NameToFamily* nextEntry = nameToFamily->append();
SkNEW_PLACEMENT_ARGS(&nextEntry->name, SkString, (family.fNames[j]));
nextEntry->styleSet = newSet;
}
}
}
示例11: buildNameToFamilyMap
void buildNameToFamilyMap(SkTDArray<FontFamily*> families, const bool isolated) {
for (int i = 0; i < families.count(); i++) {
FontFamily& family = *families[i];
SkTDArray<NameToFamily>* nameToFamily = &fNameToFamilyMap;
if (family.fIsFallbackFont) {
nameToFamily = &fFallbackNameToFamilyMap;
if (0 == family.fNames.count()) {
SkString& fallbackName = family.fNames.push_back();
fallbackName.printf("%.2x##fallback", i);
}
}
SkFontStyleSet_Android* newSet = new SkFontStyleSet_Android(family, fScanner, isolated);
if (0 == newSet->count()) {
delete newSet;
continue;
}
fFontStyleSets.push_back().reset(newSet);
for (int j = 0; j < family.fNames.count(); j++) {
NameToFamily* nextEntry = nameToFamily->append();
new (&nextEntry->name) SkString(family.fNames[j]);
nextEntry->styleSet = newSet;
}
}
}
示例12: start
static void start(ImplicitString config, ImplicitString src,
ImplicitString srcOptions, ImplicitString name) {
SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
srcOptions.c_str(), name.c_str());
SkAutoMutexAcquire lock(gRunningMutex);
gRunning.push_back(id);
}
示例13: push_sink
static void push_sink(const char* tag, Sink* s) {
SkAutoTDelete<Sink> sink(s);
if (!FLAGS_config.contains(tag)) {
return;
}
// Try a simple Src as a canary. If it fails, skip this sink.
struct : public Src {
Error draw(SkCanvas* c) const override {
c->drawRect(SkRect::MakeWH(1,1), SkPaint());
return "";
}
SkISize size() const override { return SkISize::Make(16, 16); }
Name name() const override { return "justOneRect"; }
} justOneRect;
SkBitmap bitmap;
SkDynamicMemoryWStream stream;
SkString log;
Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
if (err.isFatal()) {
SkDebugf("Could not run %s: %s\n", tag, err.c_str());
exit(1);
}
TaggedSink& ts = gSinks.push_back();
ts.reset(sink.detach());
ts.tag = tag;
}
示例14: CubicToQuads
void CubicToQuads(const SkDCubic& cubic, double precision, SkTArray<SkDQuad, true>& quads) {
SkTArray<double, true> ts;
toQuadraticTs(&cubic, precision, &ts);
if (ts.count() <= 0) {
SkDQuad quad = cubic.toQuad();
quads.push_back(quad);
return;
}
double tStart = 0;
for (int i1 = 0; i1 <= ts.count(); ++i1) {
const double tEnd = i1 < ts.count() ? ts[i1] : 1;
SkDCubic part = cubic.subDivide(tStart, tEnd);
SkDQuad quad = part.toQuad();
quads.push_back(quad);
tStart = tEnd;
}
}
示例15: TestTSet_basic
static void TestTSet_basic(skiatest::Reporter* reporter) {
SkTArray<int, MEM_MOVE> a;
// Starts empty.
REPORTER_ASSERT(reporter, a.empty());
REPORTER_ASSERT(reporter, a.count() == 0);
// { }, add a default constructed element
a.push_back() = 0;
REPORTER_ASSERT(reporter, !a.empty());
REPORTER_ASSERT(reporter, a.count() == 1);
// { 0 }, removeShuffle the only element.
a.removeShuffle(0);
REPORTER_ASSERT(reporter, a.empty());
REPORTER_ASSERT(reporter, a.count() == 0);
// { }, add a default, add a 1, remove first
a.push_back() = 0;
REPORTER_ASSERT(reporter, a.push_back() = 1);
a.removeShuffle(0);
REPORTER_ASSERT(reporter, !a.empty());
REPORTER_ASSERT(reporter, a.count() == 1);
REPORTER_ASSERT(reporter, a[0] == 1);
// { 1 }, replace with new array
int b[5] = { 0, 1, 2, 3, 4 };
a.reset(b, SK_ARRAY_COUNT(b));
REPORTER_ASSERT(reporter, a.count() == SK_ARRAY_COUNT(b));
REPORTER_ASSERT(reporter, a[2] == 2);
REPORTER_ASSERT(reporter, a[4] == 4);
// { 0, 1, 2, 3, 4 }, removeShuffle the last
a.removeShuffle(4);
REPORTER_ASSERT(reporter, a.count() == SK_ARRAY_COUNT(b) - 1);
REPORTER_ASSERT(reporter, a[3] == 3);
// { 0, 1, 2, 3 }, remove a middle, note shuffle
a.removeShuffle(1);
REPORTER_ASSERT(reporter, a.count() == SK_ARRAY_COUNT(b) - 2);
REPORTER_ASSERT(reporter, a[0] == 0);
REPORTER_ASSERT(reporter, a[1] == 3);
REPORTER_ASSERT(reporter, a[2] == 2);
// {0, 3, 2 }
}