add resId to cache DoricResource on native

This commit is contained in:
pengfei.zhou
2021-11-18 17:39:01 +08:00
committed by osborn
parent d746c5b4d4
commit 5b80e4e0e1
17 changed files with 107 additions and 23 deletions

View File

@@ -2145,11 +2145,13 @@ var __extends$f = (undefined && undefined.__extends) || (function () {
})();
var Resource = /** @class */ (function () {
function Resource(type, identifier) {
this.resId = uniqueId("resource");
this.type = type;
this.identifier = identifier;
}
Resource.prototype.toModel = function () {
return {
resId: this.resId,
type: this.type,
identifier: this.identifier,
};

View File

@@ -1610,11 +1610,13 @@ function text(config) {
class Resource {
constructor(type, identifier) {
this.resId = uniqueId("resource");
this.type = type;
this.identifier = identifier;
}
toModel() {
return {
resId: this.resId,
type: this.type,
identifier: this.identifier,
};

View File

@@ -3138,11 +3138,13 @@ function text(config) {
class Resource {
constructor(type, identifier) {
this.resId = uniqueId("resource");
this.type = type;
this.identifier = identifier;
}
toModel() {
return {
resId: this.resId,
type: this.type,
identifier: this.identifier,
};

2
doric-js/index.d.ts vendored
View File

@@ -1688,8 +1688,10 @@ declare module 'doric/lib/src/util/resource' {
export abstract class Resource implements Modeling {
type: string;
identifier: string;
resId: string;
constructor(type: string, identifier: string);
toModel(): {
resId: string;
type: string;
identifier: string;
};

View File

@@ -1,6 +1,9 @@
import { Resource } from "../util/resource";
import { BridgeContext } from "../runtime/global";
export declare function imageDecoder(context: BridgeContext): {
getBitmapInfo: (resource: Resource) => Promise<ArrayBuffer>;
decodeToPixels: (resource: Resource) => Promise<ArrayBuffer>;
decode: (resource: Resource) => Promise<{
width: number;
height: number;
format: string;
}>;
};

View File

@@ -13,13 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
export function imageDecoder(context) {
return {
getBitmapInfo: (resource) => {
return context.callNative('imageDecoder', 'getBitmapInfo', resource);
},
decodeToPixels: (resource) => {
return context.callNative('imageDecoder', 'decode', resource);
},
decode: (resource) => __awaiter(this, void 0, void 0, function* () {
yield context.callNative('imageDecoder', 'loadResource', resource);
const imageInfo = yield context.callNative('imageDecoder', 'getImageInfo', resource.resId);
const pixels = yield context.callNative('imageDecoder', 'decodeToPixels', resource.resId);
yield context.callNative('imageDecoder', 'releaseResource', resource.resId);
return Object.assign(Object.assign({}, imageInfo), { pixels });
}),
};
}

View File

@@ -2,8 +2,10 @@ import { Modeling } from "./types";
export declare abstract class Resource implements Modeling {
type: string;
identifier: string;
resId: string;
constructor(type: string, identifier: string);
toModel(): {
resId: string;
type: string;
identifier: string;
};

View File

@@ -1,10 +1,13 @@
import { uniqueId } from "./uniqueId";
export class Resource {
constructor(type, identifier) {
this.resId = uniqueId("resource");
this.type = type;
this.identifier = identifier;
}
toModel() {
return {
resId: this.resId,
type: this.type,
identifier: this.identifier,
};

View File

@@ -19,11 +19,26 @@ import { BridgeContext } from "../runtime/global"
export function imageDecoder(context: BridgeContext) {
return {
getBitmapInfo: (resource: Resource) => {
return context.callNative('imageDecoder', 'getBitmapInfo', resource) as Promise<ArrayBuffer>
},
decodeToPixels: (resource: Resource) => {
return context.callNative('imageDecoder', 'decode', resource) as Promise<ArrayBuffer>
decode: async (resource: Resource) => {
await context.callNative('imageDecoder', 'loadResource', resource);
const imageInfo = await context.callNative(
'imageDecoder',
'getImageInfo',
resource.resId) as Promise<
{
width: number,
height: number,
format: string,
}>;
const pixels = await context.callNative(
'imageDecoder',
'decodeToPixels',
resource.resId) as Promise<ArrayBuffer>;
await context.callNative('imageDecoder', 'releaseResource', resource.resId);
return {
...imageInfo,
pixels,
};
},
}
}

View File

@@ -1,14 +1,17 @@
import { Modeling } from "./types";
import { uniqueId } from "./uniqueId";
export abstract class Resource implements Modeling {
type: string;
identifier: string;
resId = uniqueId("resource");
constructor(type: string, identifier: string) {
this.type = type;
this.identifier = identifier;
}
toModel() {
return {
resId: this.resId,
type: this.type,
identifier: this.identifier,
}