A drawing method and related equipment

By calling the native drawing interface and encapsulating the native interface on the React Native platform, cross-platform drawing is realized, which solves the performance problems in the high-performance drawing requirements of the React Native platform and improves drawing efficiency and device performance.

CN114064017BActive Publication Date: 2024-08-30TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010773295.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-08-04
Publication Date
2024-08-30
Estimated Expiration
2040-08-04

AI Technical Summary

Technical Problem

When the existing React Native platform requires high-performance drawing, there are performance problems in implementing graphics drawing through nested webview solutions. Frequent communication leads to inefficient drawing and can easily cause lags or application crashes.

Method used

Call the native drawing interfaces of different operating systems through one interface to reduce the number of redraws and improve graphics drawing efficiency. Use the native drawing interface in the cross-platform framework to associate with at least two mobile device operating systems, and encapsulate the native interface to achieve cross-platform drawing. Use the underlying vector drawing library to draw graphics in batches.

Benefits of technology

Open up the barriers between different operating systems, reduce the number of redraws, improve drawing efficiency, improve device performance, and avoid stuck and crash problems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114064017B
    Figure CN114064017B
Patent Text Reader

Abstract

The present application provides a drawing method and related equipment, which breaks through the barriers between different operating systems, and can reduce the number of redrawing times when drawing, improve the efficiency of graphics drawing, and reduce performance loss. The method includes: receiving a first operation instruction from a user; based on the first operation instruction, calling a first drawing command through a target interface, the target interface is a native drawing interface in a cross-platform framework, and the native drawing interface in the cross-platform framework has an association relationship with at least two mobile device operating systems; determining a first identifier of the first drawing command and a first call parameter of the first drawing command; storing the first identifier and the first call parameter in a drawing command array, the drawing command array including identifiers and call parameters of multiple drawing commands in the current cycle; when the current cycle ends, drawing is performed according to the identifiers of all drawing commands in the drawing command array and the call parameters of all drawing commands in the drawing command array.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of graphics drawing, and in particular to a drawing method and related equipment. Background Art

[0002] React Native: A cross-platform framework officially launched by Facebook. Developers can use the web development language (JavaScript / TypeScript) to write mobile applications. A set of codes can compile IOS and Android clients at the same time. The performance of the built application is comparable to that of native applications, which greatly improves development efficiency and user experience, and has become the mainstream cross-platform development solution on the market.

[0003] Currently, React Native is the mainstream cross-platform development solution in the market, and there are many component libraries available. However, there are very few solutions available in the field of drawing. Some drawing requirements with high performance requirements, such as developing games and drawing data charts, have very few options, and the mature Web drawing libraries in the industry are difficult to port to the ReactNative platform.

[0004] Currently, the main way to draw graphics is to nest webview in React Native. The core of this solution is to use the existing canvas in webview. Webview provides a set of interfaces for interacting with canvas for React Native to use. Therefore, React Native will communicate with webview frequently. When the amount of data is large or the interaction is frequent, there will be performance problems, low drawing efficiency, and it is easy to cause freezes or even application crashes. Summary of the invention

[0005] The present application provides a drawing method and related equipment, which not only breaks through the barriers between different operating systems, but also can call the drawing interfaces of different operating systems through one interface, and can reduce the number of redrawing times during drawing, improve the efficiency of graphics drawing, and reduce performance loss.

[0006] The first aspect of the present application provides a drawing method, comprising:

[0007] receiving a first operation instruction from a user;

[0008] Based on the first operation instruction, calling a first drawing command through a target interface, wherein the target interface is a native drawing interface in a cross-platform framework, and the native drawing interface in the cross-platform framework has an association relationship with at least two mobile device operating systems;

[0009] Determine a first identifier of the first drawing command and a first calling parameter of the first drawing command;

[0010] storing the first identifier and the first calling parameter in a drawing command array, wherein the drawing command array includes identifiers and calling parameters of multiple drawing commands in a current cycle;

[0011] When the current cycle ends, drawing is performed according to the identifiers of all drawing commands in the drawing command array and the calling parameters of all drawing commands in the drawing command array.

[0012] Optionally, the method further comprises:

[0013] Determine native drawing interfaces corresponding to the at least two mobile device operating systems;

[0014] The native drawing interfaces corresponding to the at least two mobile device operating systems are encapsulated to obtain the target interface.

[0015] Optionally, the performing drawing according to the identifiers of all the drawing commands in the drawing command array and the calling parameters of all the drawing commands in the drawing command array comprises:

[0016] The identifiers of all drawing commands in the drawing command array and the calling parameters corresponding to all drawing commands in the drawing command array are batch-drawn to the screen of the device through a target drawing method, wherein the target drawing method is a drawing method corresponding to all drawing commands in the drawing command array in an underlying vector drawing library, and the underlying vector drawing library is a cross-platform drawing library of multiple drawing methods including the target drawing method, and the underlying vector drawing library corresponds to the cross-platform framework.

[0017] Optionally, the method further comprises:

[0018] receiving a second operation instruction from the user;

[0019] calling a matrix transformation interface according to the second operation instruction;

[0020] The target matrix is ​​created through the matrix transformation interface to adjust the drawn graphics.

[0021] Optionally, after drawing according to the identifiers of all drawing commands in the drawing command array and the calling parameters of all drawing commands in the drawing command array, the method further includes:

[0022] The drawing command array is reset, and the second identifier of the second drawing command and the second calling parameter of the second drawing command acquired in a cycle next to the current cycle are stored in the reset drawing command array.

[0023] A second aspect of the present application provides a drawing device, including:

[0024] A receiving unit, configured to receive a first operation instruction from a user;

[0025] a calling unit, configured to call a first drawing command through a target interface based on the first operation instruction, wherein the target interface is a native drawing interface in a cross-platform framework, and the native drawing interface in the cross-platform framework is associated with at least two mobile device operating systems;

[0026] a determining unit, configured to determine a first identifier of the first drawing command and a first calling parameter of the first drawing command;

[0027] a storage unit, used for storing the first identifier and the first calling parameter into a drawing command array, wherein the drawing command array includes identifiers and calling parameters of a plurality of drawing commands in a current cycle;

[0028] The drawing unit is used for drawing according to the identifiers of all the drawing commands in the drawing command array and the calling parameters of all the drawing commands in the drawing command array when the current cycle ends.

[0029] Optionally, the determining unit is further used to determine native drawing interfaces corresponding to the at least two mobile device operating systems;

[0030] The drawing device also includes:

[0031] The encapsulation unit is used to encapsulate the native drawing interfaces corresponding to the at least two mobile device operating systems to obtain the target interface.

[0032] Optionally, the drawing unit is specifically used for:

[0033] The identifiers of all drawing commands in the drawing command array and the calling parameters corresponding to all drawing commands in the drawing command array are batch-drawn to the screen of the device through a target drawing method, wherein the target drawing method is a drawing method corresponding to all drawing commands in the drawing command array in an underlying vector drawing library, and the underlying vector drawing library is a cross-platform drawing library of multiple drawing methods including the target drawing method, and the underlying vector drawing library corresponds to the cross-platform framework.

[0034] Optionally, the receiving unit is further configured to receive a second operation instruction from the user;

[0035] The calling unit is further used to call the matrix transformation interface according to the second operation instruction;

[0036] The drawing unit is further used to create a target matrix through the matrix transformation interface to adjust the drawn graphics.

[0037] Optionally, the device further comprises:

[0038] The reset unit is used to reset the drawing command array, and store the second identifier of the second drawing command and the second calling parameter of the second drawing command acquired in the next cycle of the current cycle into the reset drawing command array.

[0039] A third aspect of the present application provides a computer device comprising at least one connected processor, memory and transceiver, wherein the memory is used to store program code, and the program code is loaded and executed by the processor to implement the steps of the above-mentioned drawing method.

[0040] A fourth aspect of the present application provides a computer-readable storage medium, which includes instructions, and when the instructions are executed on a computer, the computer executes the steps of the above-mentioned drawing method.

[0041] In summary, it can be seen that in the embodiment provided by the present application, the drawing device calls the drawing command through the target interface, the target interface is associated with the native drawing interface of at least two mobile device operating systems, and determines the identification and calling parameters of the drawing command, and stores the identification and calling parameters of the drawing command in the drawing command array, the drawing command array includes the identifications and calling parameters of multiple drawing commands in the current cycle, and at the end of the current cycle, drawing is performed according to the identifications of all drawing commands in the drawing command array and the calling parameters of all drawing commands in the drawing command array. In this way, not only the barriers between different operating systems are broken, but the drawing interfaces of different operating systems can be called through one interface, and in one cycle, the drawing-related commands can be called many times, but they will not be drawn on the device screen immediately, but will be drawn at the end of the cycle, thereby greatly reducing the number of redrawing times and improving drawing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 A schematic diagram of a network architecture of a drawing method provided in an embodiment of the present application;

[0043] Figure 2 A specific usage flow chart of the drawing method provided in the embodiment of the present application;

[0044] Figure 3A schematic diagram of the canvas interface provided in an embodiment of the present application;

[0045] Figure 4 A method schematic diagram corresponding to CanvasRenderingContext2D is provided for the embodiment of the present application;

[0046] Figure 5 Provides a schematic diagram of image cropping and placement for the embodiment of the present application;

[0047] Figure 6 A schematic diagram of a flow chart of a drawing method provided in an embodiment of the present application;

[0048] Figure 7 Another schematic diagram of a flow chart of a drawing method provided in an embodiment of the present application;

[0049] Figure 8 A schematic diagram of a virtual structure of a drawing device provided in an embodiment of the present application;

[0050] Fig. 9 A schematic diagram of the hardware structure of the drawing device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0051] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.

[0052] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described here can be implemented in an order other than the information illustrated or described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or modules is not necessarily limited to those steps or modules clearly listed, but may include other steps or modules that are not clearly listed or inherent to these processes, methods, products or devices. The division of modules that appear in this application is only a logical division. There may be other division methods when implemented in actual applications, such as multiple modules can be combined or integrated into another system, or some feature vectors can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, and the indirect coupling or communication connection between modules can be electrical or other similar forms, which are not limited in this application. Furthermore, the modules or sub-modules described as separate components may or may not be physically separated, may or may not be physical modules, or may be distributed in multiple circuit modules, and some or all of the modules may be selected according to actual needs to achieve the purpose of the present application.

[0053] See also Figure 1 , Figure 1 A schematic diagram of the network architecture of the drawing method provided in an embodiment of the present application, wherein ECharts 103 and d3.js 104 are mature drawing libraries running on the web and cannot be used directly in React Native 101. After the Canvas API 102 is implemented in React Native 101, these drawing libraries can be used directly on React Native through simple adaptation (specifically, by adjusting the corresponding environment parameters), which is equivalent to a code that can run directly on the Web and React Native without the need for additional development. In addition, other applications 105 that rely on canvas can be used directly on React Native.

[0054] Among them, React Native ART is the underlying vector drawing library officially launched by React Native, which provides basic drawing functions such as drawing lines and polygons, and the provided application programming interface (Application Programming Interface, API) is relatively low-level.

[0055] Canvas is a new element of Hyper Text Markup Language 5.0 (HTML5). Canvas provides a set of 2D drawing APIs. Developers can use this set of APIs to develop high-performance animations, games, and drawing tools. It is very powerful.

[0056] ECharts is an open source visualization library written in JavaScript launched by Baidu. It integrates many charts, such as line charts, bar charts, pie charts, scatter charts, etc. The underlying rendering engine is ZRender and the underlying engine of ZRender is Canvas.

[0057] See also Figure 2 , Figure 2 The specific use flow chart of the drawing method provided in the embodiment of the present application is based on iOS and Android to implement a set of Canvas API. The whole design is divided into two layers, namely React Native layer and Native layer. The Native layer includes Android and iOS, that is, Figure 2 Native Android201 and NativeIOS202 in the Native layer provide native drawing interfaces to the React Native layer (i.e. Figure 2 React Native canvas 203) is used in the Android side, where the native interface is implemented through Graphic Canvas, and the native interface is implemented through CoreGraphics on the iOS side. The React Native layer encapsulates the Native native interface and provides a consistent interface to the upper-level React Native application 204, which smooths out the differences between the two platforms. Developers do not need to care about the underlying implementation when using it.

[0058] See also Figure 3 , Figure 3 The interface diagram of the canvas provided in the embodiment of the present application includes:

[0059] Canvas300, CanvasRenderingContext2D301, Pattern302, Path2D303, DOMMatrix2DInit304 and DOMMatrixInit305;

[0060] Among them, the main functions of the CanvasRenderingContenxt2D301 interface are to provide drawing graphics, drawing lines, drawing images, and performing matrix changes;

[0061] Pattern302 is used to create a Pattern object for use by CanvasRenderingContext2D301;

[0062] Path2D 303 is used to construct a path object and can be used by CanvasRenderingContext2D 301;

[0063] DOMMatrix2DInit304 is used to create a 2x 2 matrix to perform 2D operations on the graphics drawn by CanvasRenderingContext2D301. For example, the image drawn by CanvasRenderingContext2D301 can be controlled to perform 2D operations such as scaling, translation, and rotation by performing matrix transformation on the matrix created by DOMMatrix2DInit304.

[0064] DOMMatrixInit305 is used to create a 4x 4 matrix for performing 3D operations on the graphics drawn by CanvasRenderingContext2D 301. For example, the image drawn by CanvasRenderingContext2D 301 can be controlled to perform 3D operations such as scaling, translation, and rotation by performing matrix transformation on the matrix created by DOMMatrixInit305.

[0065] See also Figure 4 , Figure 4 The method diagram corresponding to the CanvasRenderingContext2D provided in the embodiment of the present application includes the following commands:

[0066] fillRect401, fillText402, drawImage403, timer404 and _draw405, where canvas represents a canvas object reference;

[0067] The drawImage403 command is used to draw a picture. The picture is drawn by setting the call parameters of drawImage. The parameter settings are as follows: image: any, sx: any, sy: any, sw?: any, sh?: any, dx?: any, dy?: any, dw?: any, dh?: any. The specific usage of the above parameters is explained below:

[0068] sx->source axisX;

[0069] sy->source axisY;

[0070] sw->source width;

[0071] sh->source height;

[0072] Use the above parameters to crop the source image and select which parts of the image to draw, such as Figure 5 As shown, 501 is a source image, and sx, sy, sw, and sh are used to determine how to crop the source image, and 5011 is the image obtained after cropping;

[0073] The cropped image 5011 is placed by setting the following parameters, such as Figure 5 In the example, picture 5011 is placed in 502. The specific placement position is as follows:

[0074] dx->destination axisX;

[0075] dy->destination axisY;

[0076] dw->destination width;

[0077] dh->destination height;

[0078] After the source image 501 is cropped according to the above calling parameters, the image 5011 can be drawn on the canvas (i.e. Figure 5 Which position and range on 502) in.

[0079] fillRect401 means filling a rectangular area, which is set by the following parameters: x: number, y: number, w: number, h: number, where number is used to set a specific value, such as Figure 5 501 and 502; wherein, fill(path?:any, fillRule?:any) means filling the current path; rect(x:number, y:number, w:number, h:number) means drawing a rectangular path;

[0080] fillText402 is used to draw the specified text, and is set by the following parameters: text: string (indicating specific text), x: number, y: number, maxWidth?: number|undefined;

[0081] raf represents a timer, which is used to send messages to the Native layer at regular intervals;

[0082] ctx represents the drawing object provided by the Native layer.

[0083] Commands represents the drawing command array, which is used to store the method name and calling parameters of the drawing method called;

[0084] _draw405 represents a custom drawing method, which calls the Native layer for graphics drawing, that is, the Native interface implemented by the Android Graphic Canvas interface and the iOS Core Graphics interface mentioned above.

[0085] Among them, rafctx, commands, and _draw are custom properties and methods. Based on performance considerations, the communication between ReactNative and Native is asynchronous. The drawing commands of the React Native layer are stored in commands, and the asynchronous call to the Native method is realized through requestAnimationFrame (where requestAnimationFrame is called after React Native completes the rendering of each frame). It can be understood that requestAnimationFrame here is the native API of React Native. This API will call the methods registered on it (such as drawImage, fillText, and react methods). The calling time is the gap between each frame rendering of React Native. Using this method will not trigger drawing frequently, thereby improving performance.

[0086] The implementation of the Path2D interface is described below.

[0087] addPath: means adding a new path to the current path;

[0088] arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean|undefined): indicates drawing an arc path, where x and y indicate the position of the arc center, radius indicates the radius, startAngle is the starting angle, and endAngle is the ending angle;

[0089] arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): indicates drawing an arc path based on a certain point, where x1 and y1 are the positions of the first point, x2 and y2 are the positions of the second point, and radius is the radius;

[0090] bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): means drawing a cubic Bezier curve, cp1x, cp1y, cp2x, cp2y, x, y represent the positions of three points;

[0091] closePath(): Draw a path from the current point to the starting point;

[0092] ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: boolean|undefined): means drawing an ellipse path;

[0093] lineTo(x: number, y: number): means drawing a path from the current point to the end point;

[0094] moveTo(x: number, y: number): means moving the starting point of the path without drawing a new path;

[0095] quadraticCurveTo(cpx:number, cpy:number, x:number, y:number): means drawing the Bezier curve twice;

[0096] rect(x: number, y: number, w: number, h: number): means drawing a rectangular path. That is to say, if the user wants to draw an arc path, he can call the arc method and store the arc method identifier and calling parameters (the calling parameters are the number in the above arc command. It can be understood that all the above numbers are calling parameters corresponding to the respective commands. The user can draw different lines or arcs by modifying the number) in the drawing command array. When the execution cycle comes, the identifiers and calling parameters of all commands in the drawing command array are batch imported into the Native layer to draw the graphics on the device, so that there is no need to draw frequently, which improves the drawing efficiency and device performance.

[0097] The following describes the drawing method provided by the present application from the perspective of the drawing device. Figure 6 , Figure 6 A schematic flow chart of a drawing method provided in an embodiment of the present application includes:

[0098] 601. Receive a first operation instruction from a user.

[0099] 602. Based on the first operation instruction, call a first drawing command through a target interface.

[0100] In this embodiment, the drawing device can call the first drawing command through the target interface based on the first operation instruction, wherein the target interface is a native drawing interface in the cross-platform interface, and the native drawing interface in the cross-platform framework has an association relationship with at least two mobile device operating systems, and the first drawing command includes but is not limited to a text drawing command, an image drawing command, and a line drawing command. That is, the drawing device can call the corresponding drawing command through the target interface according to the user's first operation instruction, for example, it can call drawing-related methods such as drawImage, fillText, and react methods through the target interface according to the user's first operation instruction. Figure 2 As shown, the at least two mobile device operating systems here include Android and IOS. Of course, other mobile device operating systems may also be included, such as Windows Phone operating system. There is no specific limitation. Android and IOS are used as examples for illustration. Android implements the native interface, that is, the target interface, through GraphicCanvas, and IOS implements the native interface through Core Graphics.

[0101] It should be noted that the drawing device can first determine the native drawing interfaces corresponding to at least two mobile device operating systems, and encapsulate the native drawing interfaces corresponding to at least two mobile device operating systems to obtain the target interface, that is, encapsulate the Graphic Canvas native drawing interface of the Android side and the Core Graphics interface of the IOS side, thereby ensuring that when the Android operating system calls the first drawing command through the target interface, it is implemented through GraphicCanvas, and when the IOS operating system calls the first drawing command through the target interface, it is implemented through Core Graphics, thereby breaking through the barrier between at least two mobile device operating systems.

[0102] In one embodiment, the operation for generating the first operation instruction includes at least one of a gesture operation, a sliding operation, a click operation, and a voice control operation. For example, when a user performs a click operation, the drawing device can receive the click operation. At this time, the click operation generates the first operation instruction. That is to say, the operation instruction can be defined in advance. For example, the sliding operation is defined in advance as an operation for calling the first drawing command (such as a left slide operation, a right slide operation, an up slide operation, and a down slide operation, etc.), or the click operation is defined as an operation for calling the first drawing command (such as a single-click operation or a double-click operation, etc.), or the gesture operation is defined as an operation for calling the first drawing command (such as swinging the wrist or arm to the left, swinging the wrist or arm to the right, such as a four-finger pinch operation or a three-finger up slide operation, etc.), or the voice control operation is defined as an operation for calling the first drawing command (such as receiving a sound for calling a drawing command and specifically calling which drawing method). The above is only an example and does not represent a limitation on the operation for generating the first operation instruction.

[0103] 603. Determine a first identifier of a first drawing command and a first calling parameter of the first drawing command.

[0104] In this embodiment, after calling the first drawing command, the drawing device can determine the first identifier of the first drawing command and the first calling parameter of the first drawing command. That is, each time a drawing-related method such as drawImage, fillText, and react is called, the identifier and calling parameters of the called method, i.e., the drawing command, will be determined. For example, after calling the drawing command fillText('hello', 10, 20), it can be determined that the identifier of the drawing command is fillText, and the calling parameters of the drawing command are 'hello', 10, 20.

[0105] 604. Store the first identifier and the first calling parameter into a drawing command array.

[0106] In this embodiment, after determining the first identifier of the first drawing command and the first calling parameter of the first drawing command, the drawing device can store the first identifier and the first calling parameter in the drawing command array, wherein the drawing command array stores identifiers and calling parameters of multiple drawing commands in the current cycle, that is, in the current cycle, drawing-related commands (such as drawImage, fillText and react) will be called many times, and each time the drawing-related command is called, the identifier and calling parameter corresponding to the drawing command will be stored in the drawing command array commands. That is, the identifier and calling method of the drawing command are stored in commands (here, the identifier of the drawing command is taken as the name of the drawing command as an example for explanation, of course, it can also be other identifiers, as long as it can uniquely identify the drawing command, and there is no specific limitation). For example, after the first drawing command is to call fillText ('hello', 10, 20), the first identifier fillText of the first drawing command and the first calling parameter 'hello', 10, 20 of the first drawing can be stored in commands, wherein the data stored in commands of the first identifier and the first calling parameter are as follows:

[0107]

[0108]

[0109] 605. When the current cycle ends, drawing is performed according to the identifiers of all drawing commands in the drawing command array and the calling parameters of all drawing commands in the drawing command array.

[0110] In this embodiment, at the end of the current cycle, the drawing device can draw according to the identifiers of all drawing commands in the drawing command array and the calling parameters of all drawing commands in the drawing command array. Specifically, the identifiers of all drawing commands in the drawing command array and the calling parameters corresponding to all drawing commands in the drawing command array can be drawn to the screen of the device in batches through the target drawing method. The target drawing method is a drawing method corresponding to all drawing commands in the drawing command array in the underlying vector drawing library. The underlying vector drawing library is a cross-platform drawing library of multiple drawing methods including the target drawing method, and the underlying vector drawing library corresponds to the cross-platform framework. That is, when the execution cycle of requestAnimationFrame arrives (that is, the current cycle ends, and the execution cycle of requestAnimationFrame is described as a cycle), the data in commands is drawn to the device (the device can be an Android device or an Apple device, which is not specifically limited) in batches through the ctx.draw method (ctx.draw is a drawing method provided by the native layer). The above is a complete drawing cycle. The graphics are drawn in a cycle. Therefore, within a requestAnimationFrame cycle, drawing-related methods can be called many times, but they will not be drawn on the device screen immediately. Instead, they will be drawn when the execution cycle arrives, thereby greatly reducing the number of redrawings. That is, the execution of the requestAnmationFrame is cyclical. Between each execution cycle, the drawing device can obtain multiple drawing commands from the user. The identifiers and calling parameters of these drawing commands will be cached in commands. When the execution cycle of requestAnmationFrame arrives, these drawing commands will be executed in batches to improve drawing efficiency.

[0111] In one embodiment, after performing drawing according to the identifiers of all drawing commands in the drawing command array and the calling parameters of all drawing commands in the drawing command array, the drawing device further performs the following operations:

[0112] The drawing command array is reset, and the second identifier of the second drawing command and the second calling parameter of the second drawing command acquired in a cycle next to the current cycle are stored in the reset drawing command array.

[0113] In this embodiment, when the execution cycle of requestAnimationFrame arrives, the drawing device batch draws the data in commands to the device through the ctx.draw (drawing method provided by the native layer) method, and then resets the drawing command array commands, and repeats the above operation to obtain user instructions, determine the drawing command according to the user instructions, and store the identification and calling parameters of the drawing command in the reset drawing command array. Then, when the execution cycle of requestAnimationFrame arrives again, the data in commands is batch drawn to the device through the ctx.draw method, and the drawing command array commands is reset, and the cycle is repeated to draw the graphics.

[0114] See also Figure 7 , Figure 7 Another schematic flow chart of the drawing method provided in the embodiment of the present application includes:

[0115] 701. The drawing method of RenderingContext2D is called (drawImage, fillText). The drawing device may call the drawing method of RenderingContext2D through the target interface according to the user's operation instruction, such as the drawImage method or the fillText method.

[0116] 702, commands of RenderingContext2D, the rendering device calls the rendering method of RenderingContext2D, such as the drawImage method or the fillText method, through the target interface according to the user's operation instruction, and then stores the identifier and calling parameters of the called rendering method of RenderingContext2D in the commands of RenderingContext2D;

[0117] 703. requestAnimationFrame loop, that is, the execution time of requestAnimationFrame. After each frame is rendered, the method registered by requestAnimationFrame will be called. As long as the graphics drawing behavior occurs, requestAnimationFrame will be executed, which is equivalent to a loop.

[0118] 704, Native layer drawing method, the drawing device will batch import the identifiers and call parameters in the commands of RenderingContext2D into the Native layer to draw graphics;

[0119] 705. IOS / Android, draw graphics on the screen of an IOS device or an Android device.

[0120] That is to say, every time a drawing-related method such as drawImage, fillText, react is called (for example, when a user wants to crop an image, the drawImage method is called), the method name and calling parameters of the method are stored in commands. For example, after calling fillText('hello', 10, 20), the data stored in commands is: fillText, calling parameters:

[0121] 'hello', 10, 20; When the requestAnimationFrame execution cycle arrives, the data in commands is batch drawn to the Android device or Apple device through the ctx.draw (drawing method provided by the native layer) method. After that, commands can be reset, and the graphics can be drawn repeatedly.

[0122] Therefore, in a requestAnimationFrame cycle, drawing-related methods can be called many times, but they will not be drawn immediately on the device screen (calling the ctx.draw method), but will be drawn when the execution cycle arrives, thereby greatly reducing the number of redraws and improving drawing efficiency.

[0123] In one embodiment, the drawing device may receive a second operation instruction from the user, and call a matrix transformation interface according to the second operation instruction, and create a target matrix through the matrix transformation interface to adjust the drawn graphics.

[0124] In this embodiment, when the user needs to adjust the drawn graphics, he can operate the drawn graphics. At this time, the drawing device can receive the second operation instruction of the user, and call the corresponding interface according to the second operation instruction to create a corresponding matrix to adjust the drawn image. Figure 3As shown in , the drawing device can call DOMMatrix2DInit304 according to the user's second operation instruction to create a 2x 2 matrix to perform 2D operations on the drawn graphics. For example, the drawn image can be controlled to perform 2D operations such as scaling, translation and rotation by performing matrix transformation on the matrix created by DOMMatrix2DInit; or the drawing device can call DOMMatrixInit305 according to the user's second operation instruction to create a 4x 4 matrix to perform 3D operations on the drawn graphics. For example, the drawn image can be controlled to perform 3D operations such as scaling, translation and rotation by performing matrix transformation on the matrix created by DOMMatrixInit305.

[0125] In summary, it can be seen that in the embodiment provided by the present application, the drawing device calls the drawing command through the target interface, the target interface is associated with the native drawing interface of at least two mobile device operating systems, and determines the identification and calling parameters of the drawing command, and stores the identification and calling parameters of the drawing command in the drawing command array, the drawing command array includes the identifications and calling parameters of multiple drawing commands in the current cycle, and at the end of the current cycle, drawing is performed according to the identifications of all drawing commands in the drawing command array and the calling parameters of all drawing commands in the drawing command array. In this way, not only the barriers between different operating systems are broken, but the drawing interfaces of different operating systems can be called through one interface, and in one cycle, the drawing-related commands can be called many times, but they will not be drawn on the device screen immediately, but will be drawn at the end of the cycle, thereby greatly reducing the number of redrawing times and improving drawing efficiency.

[0126] The present application is described above from the perspective of a drawing method, and the present application is described below from the perspective of a drawing device.

[0127] See also Figure 8 , Figure 8 A virtual structural diagram of a drawing device provided in an embodiment of the present application includes:

[0128] The receiving unit 801 is used to receive a first operation instruction from a user;

[0129] A calling unit 802 is configured to call a first drawing command through a target interface based on the first operation instruction, wherein the target interface is a native drawing interface in a cross-platform framework, and the native drawing interface in the cross-platform framework is associated with at least two mobile device operating systems;

[0130] A determining unit 803, configured to determine a first identifier of the first drawing command and a first calling parameter of the first drawing command;

[0131] The storage unit 804 is used to store the first identifier and the first calling parameter into a drawing command array, where the drawing command array includes identifiers and calling parameters of multiple drawing commands in a current cycle;

[0132] The drawing unit 805 is configured to perform drawing according to the identifiers of all the drawing commands in the drawing command array and the calling parameters of all the drawing commands in the drawing command array when the current cycle ends.

[0133] Optionally, the determining unit 803 is further configured to determine native drawing interfaces corresponding to the at least two mobile device operating systems;

[0134] The drawing device also includes:

[0135] The encapsulation unit 806 is configured to encapsulate the native drawing interfaces corresponding to the at least two mobile device operating systems to obtain the target interface.

[0136] Optionally, the drawing unit 805 is specifically used for:

[0137] The identifiers of all drawing commands in the drawing command array and the calling parameters corresponding to all drawing commands in the drawing command array are batch-drawn to the screen of the device through a target drawing method, wherein the target drawing method is a drawing method corresponding to all drawing commands in the drawing command array in an underlying vector drawing library, and the underlying vector drawing library is a cross-platform drawing library of multiple drawing methods including the target drawing method.

[0138] Optionally, the receiving unit 801 is further configured to receive a second operation instruction from the user;

[0139] The calling unit 802 is further configured to call the matrix transformation interface according to the second operation instruction;

[0140] The drawing unit 805 is further used to create a target matrix through the matrix transformation interface to adjust the drawn graphics.

[0141] Optionally, the device further comprises:

[0142] The resetting unit 807 is configured to reset the drawing command array, and store the second identifier of the second drawing command acquired in a cycle next to the current cycle and the second calling parameter of the second drawing command into the reset drawing command array.

[0143] In summary, it can be seen that in the embodiment provided by the present application, the drawing device calls the drawing command through the target interface, the target interface is associated with the native drawing interface of at least two mobile device operating systems, and determines the identification and calling parameters of the drawing command, and stores the identification and calling parameters of the drawing command in the drawing command array, the drawing command array includes the identifications and calling parameters of multiple drawing commands in the current cycle, and at the end of the current cycle, drawing is performed according to the identifications of all drawing commands in the drawing command array and the calling parameters of all drawing commands in the drawing command array. In this way, the barriers between different operating systems are broken, and the drawing interfaces of different operating systems can be called through one interface, and in one cycle, the drawing-related commands can be called many times, but they will not be drawn on the device screen immediately, but will be drawn at the end of the cycle, thereby greatly reducing the number of redrawing times and improving drawing efficiency.

[0144] The present application embodiment also provides another drawing device, such as Fig. 9 For the sake of convenience, only the parts related to the embodiments of the present application are shown. For specific technical details not disclosed, please refer to the method part of the embodiments of the present application. The drawing device can be a terminal, and the terminal can be any terminal device including a mobile phone, a tablet computer, a PDA (Personal Digital Assistant), a POS (Point of Sales), a car computer, etc., taking the terminal as a mobile phone as an example:

[0145] Fig. 9 FIG. 1 is a block diagram showing a partial structure of a mobile phone related to a terminal provided in an embodiment of the present application. Fig. 9 The mobile phone includes: a radio frequency (RF) circuit 910, a memory 920, an input unit 930, a display unit 940, a sensor 950, an audio circuit 960, a wireless fidelity (WiFi) module 970, a processor 980, and a power supply 990. Those skilled in the art can understand that Fig. 9 The mobile phone structure shown in the figure does not constitute a limitation on the mobile phone, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0146] Combine the following Fig. 9 A detailed introduction to the various components of the mobile phone:

[0147] The RF circuit 910 can be used for receiving and sending signals during the process of sending and receiving information or making calls. In particular, after receiving the downlink information of the base station, it is sent to the processor 980 for processing; in addition, the designed uplink data is sent to the base station. Generally, the RF circuit 910 includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (Low Noise Amplifier, LNA), a duplexer, etc. In addition, the RF circuit 910 can also communicate with the network and other devices through wireless communication. The above-mentioned wireless communication can use any communication standard or protocol, including but not limited to the Global System of Mobile communication (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, Short Messaging Service (SMS), etc.

[0148] The memory 920 can be used to store software programs and modules. The processor 980 executes various functional applications and data processing of the mobile phone by running the software programs and modules stored in the memory 920. The memory 920 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory 920 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0149] The input unit 930 can be used to receive input digital or character information, and to generate key signal input related to the user settings and function control of the mobile phone. Specifically, the input unit 930 may include a touch panel 931 and other input devices 932. The touch panel 931, also known as a touch screen, can collect the user's touch operation on or near it (such as the user's operation on the touch panel 931 or near the touch panel 931 using any suitable object or accessory such as a finger, stylus, etc.), and drive the corresponding connection device according to a pre-set program. Optionally, the touch panel 931 may include two parts: a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into contact coordinates, and then sends it to the processor 980, and can receive and execute commands sent by the processor 980. In addition, the touch panel 931 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic waves. In addition to the touch panel 931, the input unit 930 may further include other input devices 932. Specifically, the other input devices 932 may include but are not limited to one or more of a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, a joystick, etc.

[0150] The display unit 940 may be used to display information input by the user or information provided to the user and various menus of the mobile phone. The display unit 940 may include a display panel 941. Optionally, the display panel 941 may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc. Further, the touch panel 931 may cover the display panel 941. When the touch panel 931 detects a touch operation on or near it, it is transmitted to the processor 980 to determine the type of touch event. Subsequently, the processor 980 provides a corresponding visual output on the display panel 941 according to the type of touch event. Although in Fig. 9 In the embodiment, the touch panel 931 and the display panel 941 are used as two independent components to realize the input and output functions of the mobile phone, but in some embodiments, the touch panel 931 and the display panel 941 can be integrated to realize the input and output functions of the mobile phone.

[0151] The mobile phone may also include at least one sensor 950, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel 941 according to the brightness of the ambient light, and the proximity sensor may turn off the display panel 941 and / or the backlight when the mobile phone is moved to the ear. As a type of motion sensor, the accelerometer sensor can detect the magnitude of acceleration in all directions (generally three axes), and can detect the magnitude and direction of gravity when stationary. It can be used for applications that identify the posture of the mobile phone (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; as for other sensors that can be configured in the mobile phone, such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., they will not be repeated here.

[0152] The audio circuit 960, the speaker 961, and the microphone 962 can provide an audio interface between the user and the mobile phone. The audio circuit 960 can transmit the received audio data to the speaker 961 after converting the received audio data into an electrical signal, which is converted into a sound signal for output; on the other hand, the microphone 962 converts the collected sound signal into an electrical signal, which is received by the audio circuit 960 and converted into audio data, and then the audio data is output to the processor 980 for processing, and then sent to another mobile phone through the RF circuit 910, or the audio data is output to the memory 920 for further processing.

[0153] WiFi is a short-range wireless transmission technology. The mobile phone can help users send and receive emails, browse web pages and access streaming media through the WiFi module 970. It provides users with wireless broadband Internet access. Fig. 9 A WiFi module 970 is shown, but it is understandable that it is not an essential component of the mobile phone and can be omitted as needed without changing the essence of the invention.

[0154] The processor 980 is the control center of the mobile phone. It uses various interfaces and lines to connect various parts of the entire mobile phone. It executes various functions of the mobile phone and processes data by running or executing software programs and / or modules stored in the memory 920, and calling data stored in the memory 920. Optionally, the processor 980 may include one or more processing units; preferably, the processor 980 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 980.

[0155] The mobile phone also includes a power supply 990 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 980 through a power management system, so that the power management system can manage charging, discharging, power consumption and other functions.

[0156] Although not shown, the mobile phone may also include a camera, a Bluetooth module, etc., which will not be described in detail here.

[0157] In the embodiment of the present application, the above steps performed by the drawing device may be performed by the processor 980 included in the terminal.

[0158] The embodiment of the present application further provides a computer-readable storage medium on which a program is stored. When the program is executed by a processor, the steps of the above-mentioned drawing method are implemented.

[0159] An embodiment of the present application further provides a processor, which is used to run a program, wherein the program executes the steps of the above-mentioned drawing method when running.

[0160] An embodiment of the present application also provides a terminal device, which includes a processor, a memory, and a program stored in the memory and executable on the processor, wherein the program code is loaded and executed by the processor to implement the steps of the above-mentioned drawing method.

[0161] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing the steps of the above-mentioned drawing method.

[0162] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0163] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and modules described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0164] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0165] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products of the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0166] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0167] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0168] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0169] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0170] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.

[0171] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0172] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0173] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.

Claims

1. A drawing method, characterized in that: include: receiving a first operation instruction from a user; Based on the first operation instruction, calling a first drawing command through a target interface, wherein the target interface is obtained by encapsulating native drawing interfaces corresponding to at least two mobile device operating systems, and the native drawing interface is associated with the at least two mobile device operating systems; Determine a first identifier of the first drawing command and a first calling parameter of the first drawing command; storing the first identifier and the first calling parameter in a drawing command array, wherein the drawing command array includes identifiers and calling parameters of multiple drawing commands in a current cycle; When the current cycle ends, drawing is performed according to the identifiers of all drawing commands in the drawing command array and the calling parameters of all drawing commands in the drawing command array.

2. The method according to claim 1, characterized in that The drawing according to the identifiers of all the drawing commands in the drawing command array and the calling parameters of all the drawing commands in the drawing command array comprises: The identifiers of all drawing commands in the drawing command array and the calling parameters corresponding to all drawing commands in the drawing command array are batch-drawn to the screen of the device through a target drawing method, wherein the target drawing method is a drawing method corresponding to all drawing commands in the drawing command array in an underlying vector drawing library, and the underlying vector drawing library is a cross-platform drawing library of multiple drawing methods including the target drawing method, and the underlying vector drawing library corresponds to the cross-platform framework.

3. The method according to any one of claims 1 to 2, characterized in that The method further comprises: receiving a second operation instruction from the user; calling a matrix transformation interface according to the second operation instruction; The target matrix is ​​created through the matrix transformation interface to adjust the drawn graphics.

4. The method according to any one of claims 1 to 2, characterized in that After drawing according to the identifiers of all drawing commands in the drawing command array and the calling parameters of all drawing commands in the drawing command array, the method further includes: The drawing command array is reset, and the second identifier of the second drawing command and the second calling parameter of the second drawing command acquired in a cycle next to the current cycle are stored in the reset drawing command array.

5. A drawing device, characterized in that: include: A receiving unit, configured to receive a first operation instruction from a user; a calling unit, configured to call a first drawing command through a target interface based on the first operation instruction, wherein the target interface is obtained by encapsulating native drawing interfaces corresponding to at least two mobile device operating systems, and the native drawing interface is associated with the at least two mobile device operating systems; a determining unit, configured to determine a first identifier of the first drawing command and a first calling parameter of the first drawing command; a storage unit, used for storing the first identifier and the first calling parameter into a drawing command array, wherein the drawing command array includes identifiers and calling parameters of a plurality of drawing commands in a current cycle; The drawing unit is used for drawing according to the identifiers of all the drawing commands in the drawing command array and the calling parameters of all the drawing commands in the drawing command array when the current cycle ends.

6. The device according to claim 5, characterized in that: The drawing unit is specifically used for: The identifiers of all drawing commands in the drawing command array and the calling parameters corresponding to all drawing commands in the drawing command array are batch-drawn to the screen of the device through a target drawing method, wherein the target drawing method is a drawing method corresponding to all drawing commands in the drawing command array in an underlying vector drawing library, and the underlying vector drawing library is a cross-platform drawing library of multiple drawing methods including the target drawing method, and the underlying vector drawing library corresponds to the cross-platform framework.

7. The device according to any one of claims 5 to 6, characterized in that: The receiving unit is further configured to receive a second operation instruction from the user; The calling unit is further used to call the matrix transformation interface according to the second operation instruction; The drawing unit is further used to create a target matrix through the matrix transformation interface to adjust the drawn graphics.

8. The device according to any one of claims 5 to 6, characterized in that: The device also includes: The reset unit is used to reset the drawing command array, and store the second identifier of the second drawing command and the second calling parameter of the second drawing command acquired in the next cycle of the current cycle into the reset drawing command array.

9. A computer device, characterized in that: include: At least one connected processor, memory and transceiver, wherein the memory is used to store program code, and the program code is loaded and executed by the processor to implement the steps of the drawing method described in any one of claims 1 to 4.

10. A computer-readable storage medium, characterized in that: The invention comprises instructions, which, when being executed on a computer, enable the computer to execute the steps of the drawing method according to any one of claims 1 to 4.

11. A computer program product, characterized in that The computer program product comprises instructions, and when the instructions are executed on a computer device, the computer device is caused to perform the steps of the drawing method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Flash based game image rendering method and system

    CN104240284A

  • Method and device for processing cross-platform application of mobile terminal

    CN105955723A