Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
extract.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5
6
7#include <QtCore/QJniEnvironment>
8
9#include <alloca.h>
10#include <android/log.h>
11#include <extract.h>
12#include <jni.h>
13#include <stdlib.h>
14
15#define LOG_TAG "extractSyleInfo"
16#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
17
18// The following part was shamelessly stolen from ResourceTypes.cpp from Android's sources
19/*
20 * Copyright (C) 2005 The Android Open Source Project
21 *
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
25 *
26 * http://www.apache.org/licenses/LICENSE-2.0
27 *
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
33 */
34
35static void deserializeInternal(const void* inData, Res_png_9patch* outData) {
36 char* patch = (char*) inData;
37 if (inData != outData) {
38 memmove(&outData->wasDeserialized, patch, 4); // copy wasDeserialized, numXDivs, numYDivs, numColors
39 memmove(&outData->paddingLeft, patch + 12, 4); // copy wasDeserialized, numXDivs, numYDivs, numColors
40 }
41 outData->wasDeserialized = true;
42 char* data = (char*)outData;
43 data += sizeof(Res_png_9patch);
44 outData->xDivs = (int32_t*) data;
45 data += outData->numXDivs * sizeof(int32_t);
46 outData->yDivs = (int32_t*) data;
47 data += outData->numYDivs * sizeof(int32_t);
48 outData->colors = (uint32_t*) data;
49}
50
51Res_png_9patch* Res_png_9patch::deserialize(const void* inData)
52{
53 if (sizeof(void*) != sizeof(int32_t)) {
54 LOGE("Cannot deserialize on non 32-bit system\n");
55 return NULL;
56 }
57 deserializeInternal(inData, (Res_png_9patch*) inData);
58 return (Res_png_9patch*) inData;
59}
60
61extern "C" JNIEXPORT jintArray JNICALL
63{
64 Res_png_9patch20* chunk = reinterpret_cast<Res_png_9patch20*>(addr);
65 Res_png_9patch20::deserialize(chunk);
66 //printChunkInformation(chunk);
67 jintArray result;
68 size_t size = 3+chunk->numXDivs+chunk->numYDivs+chunk->numColors;
69 result = env->NewIntArray(size);
70 if (!result)
71 return 0;
72
73 jint *data = (jint*)malloc(sizeof(jint)*size);
74 size_t pos = 0;
75 data[pos++] = chunk->numXDivs;
76 data[pos++] = chunk->numYDivs;
77 data[pos++] = chunk->numColors;
78
79 int32_t* xDivs = chunk->getXDivs();
80 int32_t* yDivs = chunk->getYDivs();
81 uint32_t* colors = chunk->getColors();
82
83 for (int x = 0; x <chunk->numXDivs; x ++)
84 data[pos++]=xDivs[x];
85 for (int y = 0; y <chunk->numYDivs; y ++)
86 data[pos++] = yDivs[y];
87 for (int c = 0; c <chunk->numColors; c ++)
88 data[pos++] = colors[c];
89 env->SetIntArrayRegion(result, 0, size, data);
90 free(data);
91 return result;
92}
93
94static inline void fill9patchOffsets(Res_png_9patch20* patch) {
95 patch->xDivsOffset = sizeof(Res_png_9patch20);
96 patch->yDivsOffset = patch->xDivsOffset + (patch->numXDivs * sizeof(int32_t));
97 patch->colorsOffset = patch->yDivsOffset + (patch->numYDivs * sizeof(int32_t));
98}
99
100Res_png_9patch20* Res_png_9patch20::deserialize(void* inData)
101{
102 Res_png_9patch20* patch = reinterpret_cast<Res_png_9patch20*>(inData);
103 patch->wasDeserialized = true;
105 return patch;
106}
JNIEXPORT jintArray JNICALL Java_org_qtproject_qt_android_ExtractStyle_extractNativeChunkInfo20(JNIEnv *, jobject, long)
static void deserializeInternal(const void *inData, Res_png_9patch *outData)
Definition extract.cpp:35
static void fill9patchOffsets(Res_png_9patch20 *patch)
Definition extract.cpp:94
#define LOGE(...)
Definition extract.cpp:16
GLint GLint GLint GLint GLint x
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint y
const GLubyte * c
GLenum const void * addr
GLuint64EXT * result
[6]
static QT_BEGIN_NAMESPACE const QRgb colors[][14]
manager patch(request, myData, this, [this](QRestReply &reply) { if(reply.isSuccess()) })
[9]