A layer processing method and related apparatus
By adjusting the layer storage method, only the part containing the drawing content is saved and the overlapping layers are composited, which solves the problem of lag and memory crashes caused by the increased time of layer compositing, and improves the performance and user experience of the painting application.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HUAWEI TECH CO LTD
- Filing Date
- 2024-12-04
- Publication Date
- 2026-06-05
AI Technical Summary
In digital painting scenarios, as the number of layers increases, the time required for layer compositing also increases, leading to lag and memory crashes in painting applications, which negatively impacts the user experience.
Electronic devices can adjust the layer storage method to save only the parts containing the drawn content, build a list of layers to be composited, and only composite overlapping layers, thereby reducing memory usage and improving the real-time layer compositing performance.
It reduces the memory footprint of layers, improving the performance and user experience of real-time layer compositing.
Smart Images

Figure CN122156348A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of terminal and communication technology, and in particular to a layer processing method and related apparatus. Background Technology
[0002] In digital painting, users can break down an artwork into multiple layers, drawing and adjusting content on each layer. The content from all layers is then composited in real-time and displayed on the device screen. When creating layers, electronic devices allocate and bind a block of memory related to the layer's canvas size to store its data. As the number of layers increases, the time required for layer compositing also increases, and the memory usage of the painting application increases dramatically, leading to lag, crashes due to low memory usage, and ultimately impacting the user experience. Summary of the Invention
[0003] This application provides a layer processing method and related apparatus.
[0004] In a first aspect, this application provides a layer processing method applied to an electronic device. The method includes: the electronic device displaying a first composite result, the first composite result being obtained by compositing N layers, where N is an integer greater than 0; for the Mth layer among the N layers, the electronic device determining that the Mth layer contains a first part of first drawn content, the electronic device saving the first part and not saving any part of the Mth layer other than the first part, where M is a positive integer less than or equal to N; in response to a drawing operation, adding second drawn content to an active layer; based on the overlap between the second drawn content and the first drawn content in the Mth layer, the electronic device adding the Mth layer to a layer composition list, the layer composition list indicating the layers that need to participate in the composition, the layer composition list including the active layer; the electronic device obtaining a second composite result based on the layer composition list and the first composite result; and the electronic device displaying the second composite result, the second composite result including the second drawn content.
[0005] Using the first method, electronic devices can adjust the way layers are stored, storing only the valid drawn content within each layer. The electronic device can also determine if the user's new drawing overlaps with previous drawings and, based on this, construct a list of layers to be composited, only compositing layers that overlap with the user's new drawing. In this way, the electronic device can reduce layer memory usage and improve the performance of real-time layer compositing, thus enhancing the user experience.
[0006] It should be understood that, considering the degree of freedom users have in drawing, the second drawn content on the active layer can vary in size, shape, color, and transparency. Therefore, the overlap mentioned in the context is generally not understood as a complete overlap, but rather as an overlap between the second and first drawn content. This is a reasonable interpretation of the term "overlap."
[0007] In conjunction with the first aspect, in one possible implementation, the first part includes a first rectangle, which is the smallest rectangle enclosing the first drawn content; the electronic device obtains a second composite result based on the layer composition list and the first composite result, specifically including: the electronic device obtains the second composite result based on the composite result of the first rectangle of the layer in the layer composition list.
[0008] The electronic device can use the bounding box of each layer as the first part of that layer. For each layer, the electronic device saves the portion inside its bounding box, but not the portion outside the bounding box. This frees up memory occupied by the portion outside the bounding box of each layer, reducing the memory footprint of each layer. Simultaneously, the electronic device can utilize the contents of each layer's bounding box in subsequent layer compositing, reducing the computational load of layer compositing and improving the performance of real-time layer compositing.
[0009] In conjunction with the first aspect, in one possible implementation, the first part includes one or more layer slices. The electronic device determines the first part containing first drawing content in the Mth layer, specifically including: the electronic device dividing the Mth layer into K layer slices, the K layer slices having the same size, where K is an integer greater than 1; the electronic device calculating slice markers for the Mth layer, the slice markers including K markers, each of the K markers corresponding to one of the K layer slices; for the Mth layer, the relative positional relationship of the K markers in the slice markers is used to indicate the relative positional relationship of the corresponding layer slices in the Mth layer; the slice markers include a first type of marker and a second type of marker, the first type of marker being used to identify that the layer slice corresponding to the first type of marker has no drawing content, and the second type of marker being used to identify that the layer slice corresponding to the second type of marker has drawing content; the electronic device determining the first part based on the slice markers.
[0010] The first part can also consist of layer slices. The electronic device can divide each inactive layer into multiple layer slices. The size and number of layer slices can be referred to the description in the following embodiments, and will not be repeated here. After dividing the layer into layer slices, the electronic device can also calculate the slice marker of the layer, where the slice marker can be used to indicate whether there is drawing content in its corresponding layer slice. The electronic device can identify and save layer slices with drawing content based on the slice marker. This reduces the memory usage of layers, avoids lag in the drawing application, and improves the user experience.
[0011] In conjunction with the first aspect, in one possible implementation, the electronic device saves the first part but does not save the part outside the first part in the Mth layer. Specifically, the electronic device records the first position information of the layer slice corresponding to the second type of mark in the slice mark in the Mth layer and saves the layer slice corresponding to the second type of mark in the slice mark as a first atlas; the electronic device does not save the layer slice corresponding to the first type of mark in the slice mark.
[0012] In this way, electronic devices can save only layer slices containing drawn content and not layer slices without drawn content, which can reduce the memory usage of layers and improve the user experience.
[0013] In conjunction with the first aspect, in one possible implementation, after the electronic device saves the first portion and does not save the portion of the Mth layer other than the first portion, the method further includes: the electronic device, in response to a user's selection of the Mth layer, restoring the Mth layer based on the first location information and the first atlas.
[0014] For layers that the user hasn't currently selected (i.e., inactive layers), the electronic device can retain only the layer slices containing drawing content as the first atlas, while also preserving the positional mapping between the layer slices in the first atlas and the layer itself. When the user selects the layer and makes it the active layer, the electronic device can restore the layer using the first atlas and the positional mapping to display its complete content and support the user's drawing operations. In this way, the electronic device can save inactive layers as atlases, reducing memory usage, and can respond promptly when the user selects a layer, restoring the layer and reducing operational latency in the drawing application, thus improving the user experience.
[0015] In conjunction with the first aspect, in one possible implementation, before the electronic device adds the Mth layer to the layer composition list, the method further includes: the electronic device calculating the bounding box of the Mth layer, the bounding box including the first drawn content in the Mth layer, the bounding box being used to identify the region in the Mth layer where the first drawn content exists.
[0016] In one possible implementation, the bounding box of the Mth layer can be a first rectangle. The electronic device determines the first rectangle, which includes the smallest rectangle that encloses all drawn content in the Mth layer; the electronic device represents the first rectangle by a first coordinate, which includes a first value, a second value, a third value, and a fourth value, where the first value corresponds to the first side of the first rectangle, the second value corresponds to the second side of the first rectangle, the third value corresponds to the third side of the first rectangle, and the fourth value corresponds to the fourth side of the first rectangle.
[0017] In this way, electronic devices can identify the areas in a layer where drawing content exists, so that layers that need to be included in the composition can be selected later, thereby reducing the amount of computation required for real-time layer composition.
[0018] In conjunction with the first aspect, in one possible implementation, the electronic device calculates the bounding box of the Mth layer, specifically including: the electronic device determines a second rectangle based on the slice marker, the second rectangle including the layer slice in the slice marker corresponding to the second type of marker, and the edge of the second rectangle coincides with the edge of the layer slice in the slice marker corresponding to the second type of marker.
[0019] In this way, electronic devices can quickly calculate the coarse bounding box of a layer based on its slice markers, which can reduce the time spent calculating the bounding box, reduce the operation latency of painting applications, and improve the user experience.
[0020] In conjunction with the first aspect, in one possible implementation, after the electronic device adds second drawing content to the active layer, the method further includes: the electronic device determining a drawing dirty area, the drawing dirty area including the second drawing content.
[0021] In this way, electronic devices can identify the area of newly added drawing content in the active layer, so as to select the layers that need to participate in the composition later, thereby reducing the amount of calculation required for real-time layer composition.
[0022] In conjunction with the first aspect, in one possible implementation, based on the overlap between the second drawn content and the first drawn content in the Mth layer, the electronic device adds the Mth layer to the layer composition list, specifically including: when the electronic device determines that the bounding box intersects with the dirty drawing area, and the electronic device determines that the slice marker intersects with the dirty drawing area, the electronic device determines that the second drawn content overlaps with the first drawn content in the Mth layer; the electronic device adds the Mth layer to the layer composition list.
[0023] For example, this overlap could be between the dirty drawing area corresponding to the second drawn content and the layer slice. In this way, the electronic device can only composite the layers that overlap with the dirty drawing area, reducing the number of layers involved in the compositing and improving the performance of real-time layer compositing.
[0024] In conjunction with the first aspect, in one possible implementation, the electronic device obtains a second composite result based on the layer composition list and the first composite result, specifically including: the electronic device compositing the layers in the layer composition list with the regions that overlap with the drawn dirty region to obtain a dirty region composition result; the electronic device replacing the regions that overlap with the drawn dirty region in the first composite result with the dirty region composition result to obtain the second composite result.
[0025] In this way, electronic devices can use dirty area compositing to blend newly added drawing content into the previous layer composition result, improving the performance of real-time layer compositing.
[0026] Secondly, this application provides a layer processing method applied to an electronic device. The method includes: the electronic device displaying a first layer, wherein the first layer has first drawing content; in response to an operation of adding a new layer, the electronic device adding a second layer and displaying a first composite result of the first layer and the second layer; wherein the second layer is a non-empty layer; the electronic device saving a slice of the first layer containing the first drawing content; the first layer slice is a part of the first layer; in response to a drawing operation on the second layer, adding second drawing content to the second layer; wherein the second drawing content overlaps with the first layer slice; the electronic device obtaining a second composite result based on the second layer and the first layer slice; and the electronic device displaying the second composite result.
[0027] It should be understood that, considering the user's degree of freedom in drawing, the second drawn content on the second layer can vary in size, shape, color, and transparency. Therefore, the overlap mentioned in the context should generally not be understood as a complete overlap, but rather as an overlap between the second drawn content and the first layer slice. This is a reasonable interpretation of the term "overlap." For example, if the second drawn content is projected onto the first layer, the slice containing the second drawn content is the slice of the first layer.
[0028] In conjunction with the second aspect, in one possible implementation, the electronic device saves a first layer slice containing the first drawing content in the first layer, specifically including: the electronic device dividing the first layer into multiple layer slices; the electronic device determining slice markers for the first layer based on the first drawing content, the slice markers including a first type of marker and a second type of marker, the first type of marker being used to identify that the layer slice has no drawing content, and the second type of marker being used to identify that the layer slice has drawing content; the layer slice corresponding to the second type of marker is the first layer slice; for the first layer, the electronic device does not save the layer slice corresponding to the first type of marker, but saves the first layer slice.
[0029] In one possible implementation, when the second layer is the active layer, it can also be divided into multiple layer slices. Layer slices from different layers can correspond one-to-one. In this implementation, overlap is interpreted as complete overlap. The overlap between the second drawn content and which layer slices of the first layer are determined by the layer slices of the second layer.
[0030] In conjunction with the second aspect, in one possible implementation, the electronic device adds second drawing content to the second layer in response to a drawing operation on the second layer, specifically including: the electronic device adding the second drawing content to the second layer based on the drawing operation on the second layer; and the electronic device determining a drawing dirty area of the second layer based on the second drawing content, the drawing dirty area including the second drawing content.
[0031] In conjunction with the second aspect, in one possible implementation, the electronic device obtains a second composite result based on the second layer and the slice of the first layer. Specifically, the electronic device merges the pixels of the dirty area in the second layer with the pixels in the slice of the first layer that correspond to the position of the dirty area to obtain a dirty area composite result; the electronic device replaces the part of the first composite result that overlaps with the dirty area with the dirty area using the dirty area composite result to obtain the second composite result.
[0032] In conjunction with the second aspect, in one possible implementation, after the electronic device adds second drawing content to the second layer, the method further includes: modifying the second drawing content of the second layer in response to a modification operation on the second layer; wherein the modification operation includes shrinking, enlarging, moving, or adding the second drawing content of the second layer; in response to the operation of adding a new layer, the electronic device adds a third layer; the third layer is an empty layer; based on the modified second layer, the electronic device retains a slice of the second layer containing the second drawing content, the slice of the second layer being a part of the second layer.
[0033] Thirdly, this application provides an electronic device including: a processor and a memory coupled to the processor, the memory being used to store computer program code including computer instructions, wherein when the processor reads the computer instructions from the memory, the electronic device causes the electronic device to perform the methods described in the first and second aspects.
[0034] Fourthly, this application provides a chip system applied to an electronic device, the chip system including one or more processors, the processors being configured to invoke computer instructions to cause the execution of methods as described in the first and second aspects.
[0035] Fifthly, this application provides a computer-readable storage medium including a computer program that, when run on an electronic device, causes the electronic device to perform the methods described in the first and second aspects.
[0036] In a sixth aspect, this application provides a computer program product that, when run on a computer, causes the electronic device to perform the methods described in the first and second aspects.
[0037] Understandably, the electronic device provided in the third aspect, the chip system provided in the fourth aspect, the computer-readable storage medium provided in the fifth aspect, and the computer program product provided in the sixth aspect are all used to execute the method provided in this application. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods, and will not be repeated here. Attached Figure Description
[0038] Figure 1 This is a schematic diagram of the drawing interface of the electronic device 100 provided in the embodiments of this application;
[0039] Figure 2 This is a schematic diagram illustrating the process of layer compositing in an electronic device according to an embodiment of this application;
[0040] Figure 3A This is a schematic diagram of a layer pre-compositing technique provided in an embodiment of this application;
[0041] Figure 3B This is a schematic diagram of an empty layer removal technique provided in an embodiment of this application;
[0042] Figure 4 This is a schematic diagram of the hardware structure of the electronic device 100 provided in the embodiments of this application;
[0043] Figure 5 This is a schematic diagram of the software structure of the electronic device 100 provided in the embodiments of this application;
[0044] Figure 6 This is a flowchart illustrating the steps of the layer processing method provided in the embodiments of this application;
[0045] Figure 7 This is a schematic diagram of the drawing interface of another electronic device 100 provided in this application embodiment;
[0046] Figure 8 This is a schematic diagram of a layer slicing provided in an embodiment of this application;
[0047] Figure 9 This is a schematic diagram of a layer slicing calculation process provided in an embodiment of this application;
[0048] Figure 10 This is a schematic diagram provided in an embodiment of this application;
[0049] Figure 11A This is a schematic diagram of a layer bounding box and slice marker provided in an embodiment of this application;
[0050] Figure 11B This is a schematic diagram of a layer bounding box and slice marker provided in an embodiment of this application;
[0051] Figure 11C This is a schematic diagram of a layer bounding box and slice marker provided in an embodiment of this application;
[0052] Figure 11D This is a schematic diagram of a layer bounding box and slice marker provided in an embodiment of this application;
[0053] Figure 12A This is a schematic diagram of a layer rough bounding box and slice marker provided in an embodiment of this application;
[0054] Figure 12B This is a schematic diagram of a layer rough bounding box and slice marker provided in an embodiment of this application;
[0055] Figure 13A This is a schematic diagram illustrating how the electronic device 100 determines the active layer according to an embodiment of this application;
[0056] Figure 13B This is a schematic diagram of a dirty area provided in an embodiment of this application;
[0057] Figure 14 This is a schematic diagram of the process of real-time layer compositing in the electronic device 100 provided in this application embodiment. Detailed Implementation
[0058] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0059] The terminology used in the following embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to include the plural expressions as well, unless the context clearly indicates otherwise. The terms “first” and “second” are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as “first” or “second” may explicitly or implicitly include one or more of that feature. “First” and “second,” etc., are used to distinguish different objects, not to describe a particular order of objects. For example, a first object and a second object are used to distinguish different objects, not to describe a particular order of objects.
[0060] In the description of the embodiments in this application, unless otherwise stated, "multiple" means two or more. For example, multiple processing units refer to two or more processing units; multiple systems refer to two or more systems.
[0061] In the embodiments of this application, the terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or description. Any embodiment or related scheme described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of the terms "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0062] The term "and / or" in this application is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent three cases: A existing alone, A and B existing simultaneously, and B existing alone.
[0063] To better understand the technical solutions provided in this application, before describing the technical solutions, we will first refer to the accompanying drawings to explain the electronic device 100 with a camera function to which this application applies. In the embodiments of this application, the electronic device 100 may include, but is not limited to, devices with camera functions such as mobile phones, tablets, and smartwatches. The embodiments of this application do not limit the specific form or type of the electronic device 100.
[0064] The term "user interface (UI)" used in the following embodiments of this application refers to the medium interface through which an application or operating system interacts and exchanges information with a user. It realizes the conversion between the internal form of information and the form that the user can accept. The user interface can be source code written in a specific computer language such as arkts, js, objective-c, swift, kotlin, java, or extensible markup language (XML). The interface source code is parsed and rendered on the electronic device, ultimately presenting content that the user can recognize. A common form of user interface is the graphical user interface (GUI), which refers to a user interface related to computer operation displayed graphically. It can be visible interface elements such as text, icons, buttons, menus, tabs, text boxes, dialog boxes, status bars, navigation bars, and widgets displayed on the screen of an electronic device.
[0065] To better understand the technical solutions provided in this application, before describing the technical solutions, we will first refer to the accompanying drawings to explain the applicable electronic device 100 with drawing and image processing functions. For example, the electronic device 100 includes drawing software or image processing software. In the embodiments of this application, the electronic device 100 may include, but is not limited to, devices with drawing and image processing functions such as mobile phones, tablets, and smartwatches. The embodiments of this application do not limit the specific form or type of the electronic device 100.
[0066] First, the technical terms involved in the embodiments of this application will be introduced:
[0067] 1) Pixel: The basic unit of image display, which cannot be further divided. Each pixel is a small square of a single color.
[0068] 2) Texture: A data object containing image information. For example, this data object can be an array of pixels, where the data of each pixel represents the color of that pixel, and the array of pixels can represent the entire image.
[0069] 3) Image Layer: In image processing / painting software, layers are components of a work of art. A work can consist of multiple layers, each containing different visual elements. Layers can be stacked and blended to create the final effect. Each layer can be modified independently without affecting the content of other layers.
[0070] 4) Active Layer: The layer that the user is currently drawing.
[0071] 5) Atlas (ATLAS): Texture sets used for performance and memory optimization. Multiple images are combined into a single large image and retrieved via an index.
[0072] 6) Layer list: The layers in the artwork are arranged in order from bottom to top.
[0073] 7) Blend: Takes multiple layers as input and outputs a single resulting image.
[0074] 8) Dirty Region: The area that needs to be redrawn during the rendering process due to changes in its content.
[0075] 9) Local Blend: Blends a portion of the layer's texture while leaving the rest of the texture unchanged.
[0076] 10) Painting Latency: The delay in the appearance of pen marks on the screen when the pen tip is drawing on the screen.
[0077] 11) Tile Flag: Divides a layer into multiple small blocks according to a fixed size. The tile flag is used to record whether there is content on each small block.
[0078] 12) MipMap: A series of texture images, each texture image being half the size of the previous one, mainly used for sampling at different resolutions.
[0079] 13) Bounding Box: A rectangular box aligned with the width and height of the layer, accurately enclosing all pixels containing content in the layer.
[0080] 14) Pre-blend: Pre-blends a portion of layers that meet certain conditions, combines multiple layers into one layer, and uses the blended layer to replace the original multiple layers, participating in subsequent layer blending.
[0081] 15) Vertex Shader: A shader that performs a series of operations on vertices in the rendering pipeline.
[0082] 16) Fragment Shader: The shader that the rendering pipeline is responsible for calculating and outputting colors.
[0083] It should be understood that not all of the terms described above are existing terms, and some of them may be terms proposed based on examples in this application.
[0084] Currently, drawing or image processing applications in electronic devices 100 can perform real-time blending (or compositing) of multiple layers. Taking a drawing application as an example, in a drawing scenario, a user can create multiple layers on the drawing interface of the electronic device 100's drawing application. Then, the user breaks down the artwork into multiple areas, drawing each area on a different layer. For instance, when drawing a cartoon character, the user can draw the character's body, clothing, face, hairstyle, and other areas on different layers and make real-time adjustments. The user can draw hairstyle-related content on one layer, facial features on another, and torso-related content on yet another layer. The electronic device 100 can then composite the user's various layers in real time and display the composited content.
[0085] For example, such as Figure 2 As shown, users can create five layers in the drawing interface 101. When a user draws a cartoon character 110 in the drawing interface 101, the cartoon character 110 can be divided into multiple areas such as a hairstyle area, a face area, and a body area. The hairstyle area is drawn in layer 1, the face area is drawn in layer 3, and the body area is drawn in layer 4.
[0086] In this case, layers 2 and 5 contain no content. In some examples, layers 2 and 5 can be referred to as empty layers.
[0087] like Figure 1As shown, the drawing interface 101 may include a toolbar 102. The toolbar 102 may include a control 103. The control 103 can be used to open a layer management list 104. The layer management list 104 may include controls 105, 106, 107, 108, and 109. The electronic device 100 can, in response to a click on control 105, set layer 1 as the active layer. When the electronic device 100 sets layer 1 as the active layer, the user can draw in layer 1. The electronic device 100 can, in response to a click on control 106, set layer 2 as the active layer. When the electronic device 100 sets layer 2 as the active layer, the user can draw in layer 2. The electronic device 100 can, in response to a click on control 107, set layer 3 as the active layer. When the electronic device 100 sets layer 3 as the active layer, the user can draw in layer 3. The electronic device 100 can, in response to a click on control 108, set layer 4 as the active layer. When electronic device 100 sets layer 4 as the active layer, the user can draw in layer 4. Electronic device 100 can also set layer 5 as the active layer in response to a click on control 109. When electronic device 100 sets layer 5 as the active layer, the user can draw in layer 5.
[0088] While the user is drawing, the electronic device 100 can composite the newly drawn content with the existing drawing content in real time, and display the effect of the user's drawing operation on the drawn image in real time. For example, the electronic device 100 can composite layers 1 to 5 in real time and display the final composite cartoon character 110 on the drawing interface 101.
[0089] Users can create more or fewer layers in the drawing interface 101. This application embodiment does not limit the number of layers.
[0090] When the electronic device 100 composites user-drawn content in real time, it can composite multiple layers sequentially from bottom to top according to their arrangement. For example, as... Figure 2 As shown, with Figure 1Taking the cartoon character 110 shown as an example, which contains five layers (layer 1, layer 2, layer 3, layer 4, and layer 5), layer 5 is at the bottom. Therefore, the electronic device 100 can start layer compositing from layer 5 upwards. The electronic device 100 can first composite layer 5 and layer 4 to obtain intermediate result 1. Then, the electronic device 100 can composite intermediate result 1 and layer 3 to obtain intermediate result 2. Next, the electronic device 100 can blend layer 2 and intermediate result 2 to obtain intermediate result 3. Finally, the electronic device 100 can composite layer 1 and intermediate result 3 to obtain the final composite result.
[0091] The computational cost of layer blending is positively correlated with the number of layers; the more layers, the greater the computational cost. When a user draws many layers, the computational cost of layer blending on the electronic device 100 will be relatively high. A high computational cost for layer blending leads to longer blending times and increased rendering latency, which in turn causes stuttering in the real-time rendering of the artwork, affecting the user's creative process.
[0092] Additionally, for each layer created by the electronic device 100, the electronic device 100 allocates a memory space for that layer upon creation. The size of this memory space is related to the canvas size of the layer. The larger the canvas size of the layer, the larger the memory space allocated by the electronic device 100. The canvas size can be the range that the user can draw on the layer. For example, such as... Figure 2 As shown, electronic device 100 creates five layers (Layer 1, Layer 2, Layer 3, Layer 4, and Layer 5) and allocates corresponding memory spaces (Memory Space 1, Memory Space 2, Memory Space 3, Memory Space 4, and Memory Space 5) to each layer. In this way, electronic device 100 can store the drawing content in each layer using the corresponding memory space. It should be understood that the memory space allocated to a layer by electronic device 100 is related to the canvas size of that layer, and is independent of whether there is drawing content on that layer. Even if there is no drawing content on a layer, electronic device 100 will still allocate memory space for that layer; that is, once a layer is created, it will occupy the memory of electronic device 100 regardless of whether the user adds drawing content to it. Therefore, the memory occupied by the drawing application is positively correlated with the number of layers created by the user.
[0093] As the number of layers created by users increases, the memory usage of drawing applications on electronic devices also increases dramatically. This can lead to issues such as lag and crashes due to low memory usage, thus affecting the user experience. Although some drawing applications strictly limit the number of layers to avoid these problems, this still results in a limited number of layers available to the user, failing to meet the drawing needs of advanced users.
[0094] In one possible implementation, to reduce rendering latency and memory usage, the electronic device 100 can employ layer pre-compositing and disk storage techniques. This improves the performance of real-time multi-layer compositing by reducing the number of layers composited in real-time and the number of layers actually stored in memory, thereby reducing layer memory usage. During user drawing, the electronic device 100 can pre-composit layers that meet the pre-compositing conditions to reduce the number of layers required for subsequent real-time compositing. For example, the pre-compositing condition could be "located at the bottom of the active layer." Figure 3A As shown, taking the user setting layer 2 as the active layer as an example, the electronic device 100 can pre-composite layers 3, 4, and 5 located at the bottom of layer 2 to obtain a pre-composite result. Then, the active layer is composited with the pre-composite result to obtain an intermediate result. Finally, layer 1 is composited with the intermediate result to obtain the final composite result. This is because when the user is drawing, they will only perform drawing operations on the active layer, and the content of other layers will not change temporarily. Since the layer composite order is usually from bottom to top, the electronic device 100 can pre-composite the layers at the bottom of the active layer, which can reduce the number of layers to be composited in real time without affecting the composite result.
[0095] Optionally, after pre-compositing is complete, the electronic device 100 can save the contents of the pre-composited layers to the hard disk, i.e., write them to disk. For example, such as... Figure 3A As shown, after pre-compositing layers 5, 4, and 3, the electronic device 100 can write the contents of layers 5, 4, and 3 to disk and release the memory spaces 5, 4, and 3 corresponding to these three layers, thereby reducing the memory usage of these layers and lowering the overall memory usage of the drawing application.
[0096] In another possible implementation, the electronic device 100 may also employ an empty layer culling technique to remove empty layers during layer compositing and optimize the memory usage of empty layers, thereby improving layer compositing performance and reducing layer memory consumption. For example, with... Figure 1 The example shown is composed of five layers (Layer 1, Layer 2, Layer 3, Layer 4, and Layer 5). Figure 3B As shown, the electronic device 100 can traverse layers 1 to 5, determining that layers 2 and 5 are empty layers. Then, the electronic device 100 can release the memory spaces 2 and 5 allocated to layers 2 and 5, respectively. During real-time compositing, layers 2 and 5 can also be removed from the composition list, preventing them from participating in real-time compositing. This reduces the memory pressure on the electronic device 100 for storing layers and the computational pressure on real-time compositing layers.
[0097] The layer pre-compositing and disk dumping techniques, as well as the empty layer culling technique mentioned above, can reduce the memory usage of layers and improve layer compositing performance to some extent, but they still have certain drawbacks. For layer pre-compositing and disk dumping, if the active layer selected by the user is at the bottom of the layer list, the number of pre-compositing layers will decrease, and the layer pre-compositing technique cannot effectively optimize performance and memory usage. Furthermore, for layers that have already been dumped to disk, if the user wants to manipulate that layer, a disk read operation is required, resulting in noticeable lag and impacting the user experience.
[0098] As for the empty layer culling technique, it does not work if the user-created layers are not empty. However, users typically do not create many empty layers. When the vast majority of layers contain drawing content, the performance and memory optimization provided by the technique based on the limited scenario of empty layers is minimal.
[0099] To effectively address the issues mentioned above, such as the long real-time compositing time for multiple layers in painting applications with a large number of layers, leading to application lag, and the high memory consumption causing application crashes due to low memory usage, this application provides a layer processing method.
[0100] In the layer processing method provided in this application embodiment, the electronic device 100 can adjust the layer storage method, storing only the valid drawing content in the layer, thereby reducing the memory usage of the layer. For the real-time layer compositing stage, the electronic device 100 can also confirm whether the newly drawn content overlaps with previously drawn content, and based on this, construct a list of layers to be composited. Only layers that overlap with the newly drawn content are composited, which can improve the performance of real-time layer compositing.
[0101] The following describes an exemplary electronic device 100 provided in an embodiment of this application.
[0102] Figure 4 This is a schematic diagram of the hardware structure of the electronic device 100 provided in the embodiments of this application.
[0103] The following description uses electronic device 100 as an example to illustrate the embodiment. It should be understood that electronic device 100 may have more than Figure 4 The more or fewer components shown can be combined into two or more components, or they can have different component configurations. Figure 4 The various components shown can be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application-specific integrated circuits.
[0104] Electronic device 100 may include: processor 110, external memory interface 120, internal memory 121, universal serial bus (USB) interface 130, charging management module 140, power management module 141, battery 142, antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, sensor module 180, button 190, motor 191, indicator 192, camera 193, display screen 194, and subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0105] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0106] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of fetching and executing instructions.
[0107] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0108] In some embodiments, the processor 110 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0109] The MIPI interface can be used to connect the processor 110 to peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI) and a display serial interface (DSI). In some embodiments, the processor 110 and the display screen 194 communicate via the DSI interface to realize the display function of the electronic device 100.
[0110] It is understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a structural limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.
[0111] The wireless communication function of electronic device 100 can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.
[0112] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover one or more communication frequency bands. Different antennas can also be multiplexed to improve antenna utilization. For example, antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in conjunction with tuning switches.
[0113] The mobile communication module 150 can provide solutions for wireless communication, including 2G / 3G / 4G / 5G, applied to the electronic device 100. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves via antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to a modem processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation via antenna 1.
[0114] The modem processor may include a modulator and a demodulator. The modulator modulates the low-frequency baseband signal to be transmitted into a mid-to-high frequency signal. The demodulator demodulates the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After processing by the baseband processor, the low-frequency baseband signal is transmitted to the application processor. The application processor outputs sound signals through audio devices (not limited to speaker 170A, receiver 170B, etc.) or displays images or videos through the display screen 194.
[0115] The wireless communication module 160 can provide solutions for wireless communication applications on the electronic device 100, including wireless local area networks (WLANs) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via antenna 2, performs frequency modulation and filtering of the electromagnetic wave signals, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.
[0116] Electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.
[0117] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a Mini LED, a MicroLED, a Micro-OLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, electronic device 100 may include one or N displays 194, where N is a positive integer greater than 1. Display screen 194 can be used to display the drawing interface of a drawing application in electronic device 100.
[0118] Digital signal processors (DSPs) are used to process digital signals. Besides digital image signals, they can also process other digital signals. For example, when electronic device 100 selects a frequency, the DSP can perform Fourier transforms on the frequency energy.
[0119] Video codecs are used to compress or decompress digital video. Electronic device 100 may support one or more video codecs. Thus, electronic device 100 can play or record videos in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
[0120] An NPU (Neural Processing Unit) is a computational processor for neural networks (NNs). By borrowing the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it can rapidly process input information and continuously learn on its own. NPUs enable intelligent cognitive applications in electronic devices, such as image recognition, facial recognition, speech recognition, and text understanding.
[0121] The external storage interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external storage interface 120 to perform data storage functions. For example, images, layers, and other files can be saved on the external memory card.
[0122] Internal memory 121 can be used to store computer executable program code, which includes instructions. Processor 110 executes various functional applications and data processing of electronic device 100 by running the instructions stored in internal memory 121. Internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application required for a function (such as facial recognition, fingerprint recognition, mobile payment, etc.). The data storage area may store data created during the use of electronic device 100 (such as facial information template data, fingerprint information templates, etc.). Furthermore, internal memory 121 may include high-speed random access memory and non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.
[0123] Pressure sensor 180A is used to sense pressure signals and convert them into electrical signals. In some embodiments, pressure sensor 180A may be disposed on display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, and capacitive pressure sensors. A capacitive pressure sensor may include at least two parallel plates with conductive material. When a force is applied to pressure sensor 180A, the capacitance between the electrodes changes. Electronic device 100 determines the pressure intensity based on the change in capacitance. When a touch operation is applied to display screen 194, electronic device 100 detects the intensity of the touch operation based on pressure sensor 180A. Electronic device 100 may also calculate the touch position based on the detection signal from pressure sensor 180A.
[0124] The accelerometer 180E can detect the magnitude of the acceleration of the electronic device 100 in various directions (generally three axes). When the electronic device 100 is stationary, it can detect the magnitude and direction of gravity.
[0125] Touch sensor 180K, also known as a "touch panel," can be located on display screen 194. The touch sensor 180K and display screen 194 together form a touchscreen, also known as a "touch screen." Touch sensor 180K detects touch operations applied to or near it. The touch sensor can transmit the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through display screen 194. In other embodiments, touch sensor 180K may also be located on the surface of electronic device 100, in a different position than display screen 194.
[0126] Buttons 190 include a power button, volume buttons, etc. Buttons 190 can be mechanical buttons or touch-sensitive buttons. Electronic device 100 can receive button input and generate key signal inputs related to user settings and function control of electronic device 100.
[0127] Figure 5 This is a schematic diagram of the software structure of the electronic device 100 provided in the embodiments of this application.
[0128] like Figure 5 As shown, the electronic device 100 may include: an application program, an application framework layer, a system library, a rendering hardware interface, a graphics processing unit (GPU) driver, and GPU hardware.
[0129] The application layer can include an application interface module, which may include user interface, artwork management, layer management, brushes, filters, transformations, etc. The application interface module can provide users with various business functions of image processing and painting software, including the logic for user interface, artwork management, layer management, brushes, filters, transformations, and other business functions.
[0130] The application layer can also include a rendering engine, which may include multiple units such as brush drawing, filter operations, transformation operations, layer compositing, etc., and may also include a rendering pipeline. The rendering engine can be used to implement the underlying drawing functions of image processing and painting software. The drawing of brushes, filters, etc., can be handled by the application logic assembling the rendering pipeline. Transformations and layer compositing can be implemented internally by the rendering engine using corresponding rendering pipelines. The rendering pipeline can generate rendering instructions by calling the underlying rendering hardware interface. The rendering pipeline may also include vertex shaders and fragment shaders. The vertex shader can be used to calculate the vertex colors, texture coordinates, etc., of the image to be rendered. The fragment shader can be used to calculate the color of each pixel in the image to be rendered and to color each pixel.
[0131] Optionally, the application layer may also include applications such as contacts, memos, calls, clipboard, gallery, maps, camera, and video.
[0132] The application framework layer may include a window manager, content provider, view system, phone manager, resource manager, notification manager, etc.
[0133] The window manager is used to manage windowed applications. It can retrieve screen size, determine the presence of a status bar, lock the screen, and capture screenshots, among other things.
[0134] Content providers store and retrieve data, making that data accessible to applications. This data may include videos, images, audio, made and received phone calls, browsing history and bookmarks, phone books, etc.
[0135] A view system includes visual controls, such as controls for displaying text and controls for displaying images. View systems can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text notification icon could include views for displaying text and views for displaying images.
[0136] The phone manager is used to provide communication functions for electronic device 100. For example, it manages call status (including connection and disconnection).
[0137] The file explorer provides applications with various resources, such as localized strings, icons, images, layout files, video files, and more.
[0138] The notification manager allows applications to display notifications in the status bar. These notifications can be used to deliver informational messages and can disappear automatically after a short pause, requiring no user interaction. For example, the notification manager can be used to notify users of completed downloads or message alerts. The notification manager can also display notifications as icons or scrolling text in the top status bar, such as notifications from background applications, or as dialog boxes on the screen. Examples include displaying text messages in the status bar, emitting sounds, vibrating electronic devices, and flashing indicator lights.
[0139] The system library can also include several other functional modules. For example: surface manager, media libraries, 3D graphics processing libraries (e.g., OpenGL ES), 2D graphics engines (e.g., SGL), etc.
[0140] The Surface Manager is used to manage the display subsystem and provides the fusion of two-dimensional (2D) and three-dimensional (3D) layers for multiple applications.
[0141] The media library supports playback and recording of various common audio and video formats, as well as still image files. It supports multiple audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, and AMR.
[0142] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0143] A 2D graphics engine is a drawing engine for 2D graphics. In some examples, the drawing engine includes both a 3D graphics processing library and a 2D graphics engine.
[0144] The rendering hardware interface can include multiple interfaces such as DX12 interface, metal interface, vulkan interface, and openGL interface, which can be used to record and generate corresponding rendering and drawing instructions.
[0145] GPU drivers can parse the drawing instructions from the rendering hardware interface and send low-level drawing instructions to the GPU hardware.
[0146] GPU hardware can be used to execute drawing instructions and output the corresponding drawing results.
[0147] The layer processing method provided in the embodiments of this application will now be described in detail with reference to the accompanying drawings:
[0148] Figure 6 A schematic flowchart of the layer processing method provided in the embodiments of this application is shown.
[0149] like Figure 6 As shown, the layer processing method provided in this application embodiment may include the following steps:
[0150] S601. Display composite result 1. Composite result 1 is obtained by compositing multiple layers. Divide the multiple layers into layer slices and calculate the layer slice mark of each layer.
[0151] During the user's drawing process, the electronic device 100 can create multiple layers. For each layer, the electronic device 100 can divide it into virtual slices to calculate whether each slice contains drawing content, facilitating subsequent layer compositing and layer memory optimization. The electronic device 100 can use slice markers to indicate whether each slice of each layer contains drawing content.
[0152] In some examples, electronic device 100 can create N layers. Electronic device 100 can composite these N layers in a bottom-up order to obtain composite result 1, which includes all the drawn content of the N layers. Electronic device 100 can display composite result 1 so that the user can observe the result of the drawing operation, where N is an integer greater than 0.
[0153] For the Mth layer out of N layers, the electronic device 100 can divide the Mth layer into K layer slices and calculate the slice label 1 of the Mth layer. Slice label 1 corresponds to each of the K layer slices. The K slice labels include a first type of label and a second type of label. The layer slice corresponding to the first type of label does not include the drawing content, and the layer slice corresponding to the second type of label includes the drawing content. M is an integer greater than 0 and less than or equal to N.
[0154] like Figure 7 As shown, when N is 5, the electronic device 100 can create 5 layers (layer a, layer b, layer c, layer d, and layer e) and display the drawing interface 701. Layer a contains no drawing content and can be called an empty layer. Layer b can include drawing content 702 and 703, layer c can include drawing content 704, layer d can include drawing content 705, and layer e can include drawing content 706. The electronic device 100 can composite these five layers from layer e to layer a, ultimately obtaining the content presented by the drawing interface 701. The drawing content displayed in the drawing interface 701 can be called the composite result 1 in step S601.
[0155] In the following text, taking the Mth layer out of N layers already created by the electronic device 100 as an example, the text describes how the electronic device 100 executes the layer processing method provided in this application embodiment, performs calculations on the layer, and processes it. After the electronic device 100 detects that the user has completed drawing on the Mth layer, the electronic device 100 can process that layer. In some examples, the indicator that the electronic device 100 has detected that the user has completed drawing on the Mth layer may be that the electronic device 100 detects that the user has switched from selecting the Mth layer to selecting another layer in the drawing application.
[0156] It is understood that the embodiments of this application are only described exemplarily using the electronic device 100 processing one layer as an example, and the Mth layer can be any one of the N layers. In the layer processing method provided in this application, the electronic device 100 can process all its created layers synchronously or in stages.
[0157] In the software structure of the aforementioned electronic device 100, the layer management unit in the application interface module of the electronic device 100 can be used to calculate the layer slice markers of the layers. For each layer created by the electronic device 100, the electronic device 100 can divide these layers into multiple small blocks according to a fixed slice size. This fixed slice size can be preset in the electronic device 100 or can be changed by the user. This application embodiment does not limit the specific size of the fixed slice size.
[0158] For example, in one possible implementation, the Mth layer can be Figure 7 Layer e is shown in the image. Figure 8 As shown in a, Figure 8 An example is shown with layer 801. Layer 801 is... Figure 7Layer e in the diagram. Layer 801 may include drawing content 706. For layer 801, the electronic device 100 may divide it into 6 layer slices, each of the same size. It should be understood that, considering that the size of the layer canvas may not be divisible by the number of slices, "same" should be understood as substantially the same. For example, the number of pixel rows or columns differing between slices is within a single or double digit.
[0159] In some examples, layer 801 can be a layer with dimensions of 12 pixels * 8 pixels. The fixed slice size can be preset to 4. Thus, layer 801 can be divided into (12 / 4) * (8 / 4) = 3 * 2 layer slices.
[0160] After dividing a layer into layer slices, the electronic device 100 can calculate the slice markers corresponding to that layer. The slice markers for a layer can consist of pixels, and the number of pixels in the slice markers can be the same as the number of layer slices into which that layer is divided. For example... Figure 8 As shown in b, the size of the slice marker in layer 801 can be 3 pixels * 2 pixels. Each pixel in the slice marker of layer 801 corresponds to a slice in layer 801, and each pixel in the slice marker can also be called the marker of the corresponding slice.
[0161] For example, the layer slices segmented from layer 801 may include slice 802a and slice 803a. In terms of relative position, slice 802a is the first layer slice from the left in the first row of layer 801, and slice 803a is the first slice from the left in the second row of layer 801. The slice markers of layer 801 may include markers 802b and 803b. Marker 802b corresponds to slice 802a, and the relative position of marker 802b in the slice markers is the same as the relative position of slice 802a in layer 801, being the first marker from the left in the first row. Similarly, marker 803b also corresponds to slice 803a.
[0162] In layer slice markers, pixel values can range from 0 to 1. Pixels with a value of 0 in the slice markers are referred to as the first type of marker mentioned above, which indicates that the corresponding layer slice contains no drawn content. Pixels with a value of 1 are referred to as the second type of marker mentioned above, which indicates that the corresponding layer slice contains drawn content.
[0163] Taking layer 801 as an example, it can be derived from... Figure 8As shown in 'a', the drawn content 706 passed through slice 802a but not slice 803a. That is, slice 802a includes the drawn content, while slice 803a does not. Based on this, the value of marker 802b corresponding to slice 802a is 1, and marker 802b can be called a second-type marker. The value of marker 803b corresponding to slice 803a is 0, and marker 803b can be called a first-type marker.
[0164] In one possible implementation, when calculating the slice markers of a layer, the electronic device 100 can serially traverse the pixel values of each pixel in the layer slice for each layer slice, determining whether the layer slice contains drawing content by confirming whether each pixel in the slice contains drawing content. Then, based on whether the layer slice contains drawing content, the corresponding slice marker is calculated. However, since painting applications typically have high latency requirements, and when the number of pixels in a layer slice is large, the serial calculation of slice markers is substantial. For example, when calculating the slice marker of slice 802a, it is necessary to serially traverse all pixel values in slice 802a before the marker 802b can be calculated. This may cause the painting application to lag, affecting the user experience.
[0165] Based on this, embodiments of this application also provide a parallel computing scheme to achieve fast calculation of layer tile markers. This calculation scheme can use an iterative method to break down the calculation of layer tile markers into multiple rounds of iterative calculations. Each round of calculation only requires serial calculation of four pixel values, thereby improving the parallelism of the algorithm.
[0166] For example, refer to Figure 9 , Figure 9 The iterative calculation process will still be introduced using layer 801 as an example.
[0167] 1) First iteration:
[0168] like Figure 9 As shown in (a), the electronic device 100 can perform the first iteration calculation on layer 801, calculating the value corresponding to each pixel in layer 801 in parallel, and marking pixels with content. If a pixel contains drawing content, the electronic device 100 sets the value corresponding to that pixel to 1; if a pixel does not contain drawing content, the electronic device 100 sets the value corresponding to that pixel to 0.
[0169] After the first iteration of calculation, electronic device 100 obtains intermediate marker 1, such as Figure 9 As shown in (b), the size of the middle marker 1 is 12 pixels * 8 pixels. One pixel in the middle marker 1 corresponds to one pixel in layer 801.
[0170] During the first iteration, the electronic device 100 can calculate all pixel values in parallel, regardless of the number of pixels in the layer. The time required for the electronic device 100 to perform the first iteration is only the time consumed by calculating the pixel value of one pixel.
[0171] 2) Second iteration:
[0172] In the calculations following the first iteration, the electronic device 100 can divide the pixels into groups of four and calculate the pixel value of each group in parallel. The electronic device 100 only needs to calculate the pixel value of each group of four pixels sequentially for each iteration.
[0173] For example, electronic device 100 can perform a second iteration calculation based on intermediate marker 1. Electronic device 100 can merge every four pixel markers in intermediate marker 1 into one pixel marker. In this way, electronic device 100 can obtain the result of the second iteration.
[0174] For example, such as Figure 9 As shown in (c), intermediate marker 2 can include 6*4 pixel markers. One pixel marker in intermediate marker 2 corresponds to four pixel markers in intermediate marker 1, and corresponds to four pixels in layer 801.
[0175] The merging rule specifically involves taking the maximum value among the four pixel markers as the new pixel marker value. That is, if at least one of the four pixel markers has a value of 1, the merged pixel marker will have a value of 1. If all four pixel markers have a value of 0, the merged pixel marker will also have a value of 0. (See reference...) Figure 9 In (b) and (c), set 901 includes the four pixel markers from intermediate marker 1, and set 902 includes the other four pixel markers from intermediate marker 1. It can be seen that all four pixel markers in set 901 have a value of 0, while set 902 contains a pixel marker with a value of 1. Therefore, in intermediate marker 2, the value of pixel marker 903 corresponding to set 901 is 0, and the value of pixel marker 904 corresponding to set 902 is 1.
[0176] 3) Third iteration:
[0177] Electronic device 100 can perform a third iteration calculation based on intermediate marker 2, merging every four pixel markers in intermediate marker 2 into one pixel marker. The merging rules can be referred to the description of the second iteration calculation above, and will not be repeated here. Electronic device 100 obtains the slice markers of layer 801 through the third iteration calculation, such as... Figure 9As shown in (d), the slice markers consist of 3*2 markers, where each marker corresponds to 4 pixel markers in intermediate marker 2, 16 pixel markers in intermediate marker 1, and 16 pixels in layer 801.
[0178] It should be understood that the three iterative calculations described above are merely an exemplary process for layer 801. This application does not limit the specific number of iterative calculations in its embodiments.
[0179] In practice, the exact number of iterations depends on the size of the layer and the size of the layer slice. For a layer with size X*Y, if the size of the layer slice is set to Z, then log2(Z)+1 iterations are needed, and the size of the slice marker obtained is (X / Z)*(Y / Z). Therefore, K in the above can also be (X / Z)*(Y / Z). Thus, once the layer and layer slice are determined, the value of K is also determined.
[0180] In this way, the electronic device 100 can quickly calculate the layer slice markers through parallel computing, thus optimizing the operation latency caused by the calculation of slice markers in the painting application.
[0181] S602. Based on layer slice tags, store layer slices with drawing content and delete layer slices without drawing content.
[0182] In the layer processing method provided in this application, the electronic device 100 can selectively store the parts of a layer that have drawn content. For a part of a layer that does not have drawn content, the electronic device 100 can delete the part that does not have drawn content and release its corresponding memory control.
[0183] In some examples, electronic device 100 can determine the portions of a layer containing drawing content using slice markers. After calculating the slice markers of a layer, electronic device 100 can divide the layer into two parts based on the layer slices and slice markers: those containing drawing content and those not containing drawing content. Electronic device 100 can choose to store the portions containing drawing content and delete the portions not containing drawing content. In this way, electronic device 100 can retain the drawing content in the layer while reducing the memory occupied by the layer. For example, electronic device 100 can divide each layer into multiple parts using layer slices. Then, electronic device 100 can determine which slices contain drawing content. Electronic device 100 can choose to store the layer slices containing drawing content and delete the layer slices not containing drawing content. For each layer slice, electronic device 100 can use slice markers to identify whether the layer slice contains drawing content.
[0184] For the Mth layer, since the first type of marker in its slice labels indicates that there is no drawing content in the layer slice, and the second type of marker indicates that there is drawing content in the layer slice, the electronic device 100 can selectively store part of the content of the Mth layer based on its slice labels. After dividing the Mth layer into K layer slices, the electronic device 100 can choose to store the layer slices corresponding to the second type of marker among these K layer slices, and delete the layer slices corresponding to the first type of marker, releasing the memory allocated to the layer slices corresponding to the first type of marker. In this way, the electronic device 100 can reduce the memory occupied by a layer from the memory occupied by a complete layer to the memory occupied by a partial layer slice while storing the drawing content of a layer, thus alleviating the memory pressure of the electronic device 100.
[0185] In some examples, the layer tile markers calculated by electronic device 100 can have a first-class marker of 0 and a second-class marker of 1. Electronic device 100 can divide each layer that the user is not currently drawing into into multiple layer tiles, and calculate the tile marker for each layer separately. Then, electronic device 100 can retain tiles with a tile marker of 1 and delete tiles with a tile marker of 0. In this way, electronic device 100 can change from storing a complete layer to storing only the tiles with a tile marker of 1 within that layer. Electronic device 100 can integrate the tiles with a tile marker of 1 into an atlas and store the position information of these tiles in the original layer. When the user wants to operate on these atlas-like layers, electronic device 100 can also restore the atlas-like layers to their original layers based on the position information.
[0186] For example, you can refer to Figure 10 .like Figure 10 As shown in (a), taking layer 801 as an example, the electronic device 100 divides layer 801 into 6 layer slices and obtains the slice markers corresponding to layer 801, determining that three of the layer slices contain drawing content. Then, the electronic device 100 can atlasize layer 801, extracting the layer slices containing drawing content from layer 801 into an atlas. For example... Figure 10 As shown in (b), atlas 1001 corresponds to layer 801, and the three layer slices in atlas 1001 are the three layer slices in layer 801 that include the drawing content.
[0187] Electronic device 100 can also determine the relative position information of three layer slices, including the drawn content, within layer 801. Electronic device 100 can record the mapping relationship between slices in the atlas and the original layer in the form of a two-dimensional matrix. For example... Figure 10As shown in (c), the position information of the first layer slice from the left in Atlas 1001 can be recorded as (0, 0), which can be used to indicate that the position of this layer slice in layer 801 is the first column from the left in the first row. Similarly, the relative position information of the other two layer slices in Atlas 1001 can be recorded as (0, 1) and (1, 1) respectively.
[0188] In this way, the electronic device 100 can retain the mapping relationship between the atlas and the layers after converting the layers into an atlas. When the user does not need to operate on the layer, the drawn content in the layer can be retained in the form of an atlas, reducing memory usage. When the user needs to operate on the layer, the electronic device 100 can quickly restore the atlas to a layer based on the mapping relationship, reducing the operation latency of the drawing application.
[0189] S603. Calculate the layer bounding box.
[0190] The electronic device 100 can also determine the approximate area occupied by the drawn content in the layer. This makes it easier for the electronic device 100 to determine the positional relationship between the drawn content in each layer and to determine whether the drawn content in two layers overlaps in subsequent steps.
[0191] In some examples, the electronic device 100 can also identify the area with drawn content in a layer using a bounding box. The electronic device 100 can calculate the bounding box for each layer. The bounding box can accurately include all pixels with drawn content in the layer. In this embodiment, the bounding box is described as a rectangle aligned with the width and height of the layer. The bounding box can also be of various shapes, and this embodiment does not limit the specific shape of the bounding box.
[0192] Electronic device 100 can traverse the pixels in a layer to identify a rectangle that can enclose all drawn content within the layer as the layer's bounding box. Then, electronic device 100 can establish an XY coordinate system within the layer, using the horizontal and vertical coordinates of its four sides to identify the bounding box. For example, for a bounding box, electronic device 100 can record the horizontal coordinates of the two sides parallel to the Y-axis and the vertical coordinates of the two sides parallel to the X-axis. Electronic device 100 can store these four coordinates as a set and establish a relationship between this set of coordinates and the layer. In this way, electronic device 100 can obtain the bounding box of this layer.
[0193] For example, you can refer to Figures 11A-11D , Figures 11A-11D The examples illustrate the drawn content, bounding box, and slice markers for layers b through e, respectively. Figure 11A As shown, Figure 11A (a) in the example shows the bounding box of layer b. Figure 11A(b) in the example illustrates the slice marker b of layer b. The bounding box of layer b can be... Figure 11A The bounding box 1101 is shown in (a). The electronic device 100 can represent the bounding box 1101 using four parameters.
[0194] Electronic device 100 can select a point in layer b as the origin to establish a coordinate axis, with the two coordinates parallel to the width and height of layer a, respectively. For example, electronic device 100 can use the lower left vertex of layer b as the origin, the left edge of layer b as the y-axis, and the lower edge of layer b as the x-axis to establish a coordinate system. Then, electronic device 100 can represent the bounding box 1101 using coordinates b(A1, B1, C1, D1), where A1 represents the x-axis coordinate corresponding to the left edge of bounding box 1101, B1 represents the x-axis coordinate corresponding to the right edge of bounding box 1101, C1 represents the y-axis coordinate corresponding to the top edge of bounding box 1101, and D1 represents the left side of the y-axis corresponding to the bottom edge of bounding box 1101. In this way, electronic device 100 can use coordinates b(A1, B1, C1, D1) to represent the coverage area of bounding box 1101. Electronic device 100 can store coordinates b (A1, B1, C1, D1) and establish a mapping relationship between the coordinates b and the layer b.
[0195] Electronic device 100 can also calculate the slice marker b of layer b, such as Figure 11A As shown in (b), the electronic device 100 can store slice marker b.
[0196] like Figure 11B As shown, Figure 11B (a) in the diagram exemplifies layer c and its bounding box. Electronic device 100 can store the coordinates (A2, B2, C2, D2) corresponding to the bounding box 1102 of layer c. In some examples, electronic device 100 can establish a coordinate system with the lower left vertex of layer c as the origin, the left edge of layer c as the y-axis, and the lower edge of layer c as the x-axis. Then, electronic device 100 can represent the bounding box 1102 using coordinates c (A2, B2, C2, D2), where A2 represents the x-axis coordinate corresponding to the left edge of bounding box 1102, B2 represents the x-axis coordinate corresponding to the right edge of bounding box 1102, C2 represents the y-axis coordinate corresponding to the top edge of bounding box 1102, and D2 represents the left side of the y-axis corresponding to the bottom edge of bounding box 1102. Thus, electronic device 100 can use coordinates c (A2, B2, C2, D2) to represent the coverage area of bounding box 1102. Electronic device 100 can store coordinates c (A2, B2, C2, D2) and establish a mapping relationship between the coordinates c and the layer c.
[0197] Electronic device 100 can also calculate the slice marker c of layer c. Figure 11B Example (b) illustrates slice marker c, which the electronic device 100 can store.
[0198] like Figure 11C As shown in (a), the electronic device 100 can also represent the bounding box 1103 of layer d using coordinates d (A3, B3, C3, D3), and store the slice marker d of layer d. The slice marker d of layer d can be referenced. Figure 11C As shown in (b) of the diagram.
[0199] like Figure 11D As shown in (a), the electronic device 100 can also represent the bounding box 1104 of layer e using coordinates e (A4, B4, C4, D4), and store the slice marker e of layer e. The slice marker e of layer e can be referenced. Figure 11D As shown in (b) above. The specific method by which electronic device 100 represents the bounding boxes of layers d and e can be found in the above content. Figure 11A The description will not be repeated here.
[0200] Optionally, after calculating the slice markers of each layer, the electronic device 100 can also roughly calculate the bounding box of the layer or draw dirty areas based on the slice markers. The electronic device 100 can use a rectangle that can cover all layer slices with a slice marker of 1 as the bounding box of that layer.
[0201] For example, refer to Figure 12A and Figure 12B .exist Figure 12A In China, with Figure 7 Taking layer b as an example, if the electronic device 100 calculates that the value of the third pixel in the first row and the first pixel in the second row of the slice marker b in layer b is 1, then the electronic device 100 can use the rectangle including the third slice in the first row and the first slice in the second row of layer b as the coarse bounding box of layer b. Figure 12A As shown in (a), the coarse bounding box of layer b can be bounding box 1201. The slice marker b of layer b can be found in [reference needed]. Figure 12A As shown in (b) of the diagram.
[0202] For example Figure 12B As shown, with Figure 7 Taking layer c as an example,
[0203] The drawn content 704 occupies the second layer slice from the left in the first row of layer c. The electronic device calculates that the value of the second pixel in the first row of slice marker a in layer c is 1. Based on this, when determining the bounding box of layer c, the electronic device 100 can use a rectangle that can include the second layer slice from the left in the first row of layer c as the coarse bounding box of layer c. For example... Figure 12BAs shown in (a), the coarse bounding box of layer c can be bounding box 1202. The slice marker c of layer c can be found in [reference needed]. Figure 12B As shown in (b) of the diagram.
[0204] In this way, the electronic device 100 can quickly calculate the coarse bounding box of a layer in real time through layer slice marking, reducing the time spent calculating the bounding box. It can also quickly implement subsequent bounding box-based layer culling functions and determine the layer composition list without requiring precise bounding boxes. Although the coarser granularity of the bounding box may result in some unnecessary layers being added to the layer list, leading to slightly lower performance optimization for layer composition compared to layer composition based on precisely calculated bounding boxes, in some possible situations, the electronic device 100 can achieve better performance by combining bounding box calculation latency with layer composition latency using this method.
[0205] S604. In response to user actions, determine the active layer and draw the dirty area.
[0206] The electronic device 100 can capture newly added drawing content on the drawn image based on the user's drawing operation. Then, the electronic device 100 can merge the newly added drawing content with the existing drawing content to represent the impact of the user's drawing operation on the overall drawn image.
[0207] In some examples, electronic device 100 can use the drawing dirty region to determine the area where newly added drawing content is located. Electronic device 100 can, in response to a user's selection of a layer, designate that layer as the active layer. Then, electronic device 100 can, in response to the user's drawing operation, add drawing content on the active layer. The area on the active layer where the newly added drawing content is located can be called the drawing dirty region. The drawing dirty region can be understood as the bounding box of the newly added drawing content. For the concept of the bounding box, please refer to the description of step S603 above; it will not be repeated here.
[0208] For example, you can refer to Figure 13A Electronic device 100 can display control 1301, which corresponds to layer a and can be used to select layer a. After the user selects layer a, electronic device 100 can display the drawing interface of layer a separately. At this time, layer a is empty and has no drawing content. Then, in response to the user's drawing operation, electronic device 100 can add drawing content 1302 to the drawing interface of layer a. This drawing content 1302 is the newly added drawing content on layer a by the user.
[0209] Electronic device 100 can determine the dirty drawing area based on the user's drawing operations. Taking the drawing content 1302 as an example, electronic device 100 can calculate its rectangle 1303. Rectangle 1303 includes all the pixels of the drawing content 1302 and is as close to the drawing content 1302 as possible. Electronic device 100 can use the rectangle 1303 corresponding to the drawing content 1302 as the dirty drawing area of layer a; rectangle 1303 can also be called dirty drawing area 1303.
[0210] It should be understood that the dirty drawing area can only be viewed as the bounding box of newly drawn content. Because Figure 13A The layer a shown in the diagram has no other drawing content before the addition of drawing content 1302, so rectangle 1303 can also be regarded as the bounding box of layer a. However, if there is other drawing content in layer a before the electronic device 100 adds drawing content 1302 to layer a, then the bounding box of layer a is no longer rectangle 1303, but based on the user's drawing operation, the dirty area of layer a is still rectangle 1303.
[0211] For reference Figure 13B The dirty area 1303 of electronic device 100 can be represented by coordinates (A5, B5, C5, D5). Specific rules can be found in the above content. Figure 11A The description will not be repeated here.
[0212] S605. Determine whether the layer bounding box and layer slice marker intersect with the drawn dirty area.
[0213] After adding new drawing content to the electronic device 100, before performing layer compositing, the electronic device 100 can determine whether the newly added drawing content overlaps with existing drawing content and determine which drawing content needs to be composited.
[0214] For the Mth layer, the electronic device 100 can determine whether the drawn content in the Mth layer overlaps with the newly added drawn content. When there is overlap, it means that the new drawn content will affect the drawn content in the Mth layer in the overall drawn image, and the electronic device 100 can composite the Mth layer with the active layer in subsequent steps. The electronic device 100 can determine whether the drawn content overlaps by using the bounding box 1 of the Mth layer, the slice marker 1, the dirty area of the active layer, and the slice marker of the active layer.
[0215] by Figure 13A Taking the electronic device 100 shown as an example, where layer a is the active layer and drawing content 1302 is the newly added drawing content, then for... Figure 7The layers b, c, d, and e shown can be used to determine whether the newly added drawing content 1302 in layer a may overlap with the drawing content already existing in other layers after the electronic device 100 determines the drawing dirty area 1303, bounding box 1101, bounding box 1102, bounding box 1103, and bounding box 1104.
[0216] For example, taking layers a and b as examples, electronic device 100 can first compare the corresponding coordinates of the drawn dirty area 1303 and the bounding box 1101 to determine whether the two areas intersect. (See reference...) Figure 11A In the bounding box 1101 shown in (a), it is clear that A1 is smaller than A5, B1 is larger than B5, C1 is larger than C5, and D1 is smaller than D5. Based on this comparison, the electronic device 100 can confirm that the bounding box 1101 of layer b intersects with the dirty drawing area 1303 of layer a. This indicates that the drawn content 1302 may overlap with the drawn content in layer b, and layer blending may be necessary subsequently. Based on this, the electronic device 100 can further compare the dirty drawing area with the slice marker b of layer b. (See reference...) Figure 11A (b) and Figure 13B As can be seen, for the layer slices corresponding to pixels with a value of 1 within slice marker b, no pixels in these layer slices are located within the dirty drawing area, meaning that slice marker b does not intersect with the dirty drawing area. Therefore, electronic device 100 can determine that the drawing content of layer b does not overlap with the newly added drawing content 1302 in layer a, and the newly added drawing content 1302 will not affect the existing drawing content in layer b.
[0217] For layers a and c, please refer to... Figure 13B and Figure 11B If the electronic device 100 can determine that the dirty drawing area 1303 intersects with the bounding box 1102, and that the dirty drawing area 1303 also intersects with the slice marker c, then the electronic device 100 can determine that the drawing content in layer c coincides with the newly added drawing content 1302 in layer a, and layer a and layer c need to be composited.
[0218] For layers a and d, please refer to... Figure 13B and Figure 11C Once the electronic device 100 determines that the dirty drawing area 1303 and the bounding box 1103 do not intersect, it can determine that the drawn content 1302 will not overlap with the drawn content in layer d, and the drawn content in layer d will not be affected by the drawn content 1302. The electronic device 100 no longer needs to determine whether the dirty drawing area 1303 and the slice mark d intersect, which can reduce the latency of the painting application.
[0219] For layers a and e, please refer to... Figure 13B and Figure 11DIf the electronic device 100 can determine that the dirty drawing area 1303 intersects with the bounding box 1104, and that the dirty drawing area 1303 also intersects with the slice marker e, then the electronic device 100 can determine that the drawing content in layer e coincides with the newly added drawing content 1302 in layer a, and layer a and layer e need to be composited.
[0220] When both the bounding box and the layer slice mark intersect with the drawn dirty area, the electronic device 100 executes step S606a.
[0221] S606a. Add the layer to the layer composition list, which includes the active layer.
[0222] For each drawing operation performed by the user, the electronic device 100 constructs a layer composition list and performs real-time layer composition. For layers whose drawing content is affected by newly added drawing content in the drawing dirty area, the electronic device 100 can add the layer to the layer composition list for subsequent real-time layer composition with layers including the active layer.
[0223] This description only uses the Mth layer as an example. In fact, when constructing the layer composition list, the electronic device 100 can traverse all layers and add all layers that meet the conditions to the layer composition list.
[0224] For example, with Figure 7 Taking the five layers shown as an example, in response to the user's selection of layer a, the electronic device 100, after confirming that layer a is the active layer, can add layer a to the layer composition list. Then, after the electronic device 100 determines that the drawing content of layers c and e will be affected by the newly added drawing content in layer a, the electronic device 100 can add layers c and e to the layer composition list.
[0225] If the bounding box and layer slice markers do not all intersect with the drawing dirty area, proceed to step S606b.
[0226] S606b. Exclude the layer from the layer composition list, which includes the active layer.
[0227] For layers that are not affected by dirty areas, the electronic device 100 can exclude these layers from the layer composition list, reducing the number of layers participating in real-time composition and improving the performance of real-time layer composition.
[0228] For example, as described above Figure 7 As shown in the figure, layers b and d do not overlap with the dirty drawing area and are not affected by the dirty drawing area. Therefore, the electronic device 100 can prevent layers b and d from participating in subsequent real-time compositing, thereby reducing the amount of calculation required for this compositing.
[0229] S607. Perform layer compositing on the layers in the layer compositing list to obtain compositing result 2 and display compositing result 2.
[0230] Electronic device 100 can perform real-time compositing based on the real-time compositing result of the previous frame. Electronic device 100 can modify the displayed compositing result by recompositing the dirty areas of the previous frame's real-time compositing result. For example, when generating the real-time compositing result, electronic device 100 can divide the result into two parts: drawing the inside of the dirty area and drawing the outside of the dirty area. For the inside of the dirty area, electronic device 100 can perform dirty area compositing on layers in the compositing layer list. That is, for each layer in the compositing list, electronic device 100 only mixes the pixels corresponding to the dirty area in these layers to obtain a compositing result with the same size as the dirty area, which serves as the inside of the dirty area in the real-time compositing result. For pixels outside the dirty area, electronic device 100 can reuse the corresponding pixels from the previous frame's real-time compositing result.
[0231] For example, you can refer to Figure 14 The electronic device 100 can determine, based on the judgment results described in steps S605, S606a, and S606b, that the layer composition list for this real-time compositing includes layer a, layer c, and layer e. The electronic device 100 can composite the areas in layers a, c, and e that overlap with the drawn dirty area 1303 to obtain a dirty area composition result. Then, the electronic device 100 can obtain composition result 2 by modifying some content of composition result 1. The electronic device 100 can replace the areas in composition result 1 that overlap with the drawn dirty area 1303 with the dirty area composition result, while reusing pixels from composition result 1 for other areas, ultimately obtaining composition result 2. The electronic device 100 can display composition result 2 to show the user the result of this real-time compositing.
[0232] In this way, the electronic device 100 can reduce the number of layers involved in real-time compositing, reduce the computational load of layer compositing, optimize layer compositing performance, thereby improving the user experience. It can also significantly reduce the memory usage of layers, thereby reducing the memory usage of the entire painting application, alleviating the memory pressure on the electronic device 100, and also improving the user experience.
[0233] It should be understood that, for ease of understanding, the layer slices, slice markers, and pixels shown in the accompanying drawings of the embodiments of this application have been simplified. However, for those skilled in the art, considering the number and density of pixels in electronic devices such as mobile phones or tablets, these simplifications will not hinder their understanding of the context. In some practical scenarios where creation is performed using electronic devices such as mobile phones or tablets, the electronic device can present the drawing content corresponding to the user's drawing operations and other user interface elements through a large number of pixels.
[0234] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
[0235] As used in the above embodiments, depending on the context, the term "when..." can be interpreted as meaning "if...", "after...", "in response to determining...", or "in response to detecting...". Similarly, depending on the context, the phrase "when determining..." or "if (the stated condition or event) is interpreted as meaning "if determining...", "in response to determining...", "when (the stated condition or event) is detected", or "in response to detecting (the stated condition or event)".
[0236] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive), etc.
[0237] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A layer processing method, characterized in that, The method is applied to an electronic device, and the method includes: The electronic device displays a first composite result, which is obtained by compositing N layers, where N is an integer greater than 0; For the Mth layer among the N layers, the electronic device determines that the Mth layer contains a first part of the first drawing content, the electronic device saves the first part, and does not save the part other than the first part in the Mth layer, where M is a positive integer less than or equal to N; In response to a drawing operation, add a second drawing element to the active layer; Based on the overlap between the second drawing content and the first drawing content in the Mth layer, the electronic device adds the Mth layer to the layer composition list. The layer composition list is used to indicate the layers that need to participate in the composition, and the layer composition list includes the active layer. The electronic device obtains a second composite result based on the layer composite list and the first composite result; The electronic device displays the second composite result, which includes the second drawn content.
2. The method according to claim 1, characterized in that, The first part includes a first rectangle, which is the smallest rectangle that encloses the first drawn content; The electronic device obtains a second composite result based on the layer composite list and the first composite result, specifically including: The electronic device obtains the second composite result based on the composite result of the first rectangle of the layer in the layer composite list.
3. The method according to claim 1, characterized in that, The first portion includes one or more layer slices, and the electronic device determines that the first portion of the Mth layer contains the first drawn content, specifically including: The electronic device divides the Mth layer into K layer slices, where the K layer slices are of the same size and K is an integer greater than 1; The electronic device calculates the slice markers of the Mth layer, the slice markers include K markers, and the K markers of the slice markers correspond to the slices of the K layers respectively; for the Mth layer, the relative positional relationship of the K markers in the slice markers is used to indicate the relative positional relationship of the corresponding layer slices in the Mth layer; The slice markers include a first type of marker and a second type of marker. The first type of marker is used to indicate that the layer slice corresponding to the first type of marker has no drawn content, and the second type of marker is used to indicate that the layer slice corresponding to the second type of marker has drawn content. The electronic device determines the first portion based on the slice marker.
4. The method according to claim 3, characterized in that, The electronic device stores the first part but does not store the part other than the first part in the Mth layer, specifically including: The electronic device records the first position information of the layer slice corresponding to the second type of mark in the slice mark in the Mth layer, and saves the layer slice corresponding to the second type of mark in the slice mark as a first image set; The electronic device does not save the layer slices corresponding to the first type of markers in the slice markers.
5. The method according to claim 4, characterized in that, After the electronic device saves the first part and does not save the parts of the Mth layer other than the first part, the method further includes: In response to the user's selection of the Mth layer, the electronic device restores the Mth layer based on the first location information and the first atlas.
6. The method according to any one of claims 3-5, characterized in that, Before the electronic device adds the Mth layer to the layer composition list, the method further includes: The electronic device calculates the bounding box of the Mth layer, the bounding box including the first drawn content in the Mth layer, and the bounding box is used to identify the area in the Mth layer where the first drawn content exists.
7. The method according to claim 6, characterized in that, The electronic device calculates the bounding box of the Mth layer, specifically including: The electronic device determines a second rectangle based on the slice markers. The second rectangle includes a layer slice in the slice markers that corresponds to the second type of marker. The edge of the second rectangle coincides with the edge of the layer slice in the slice markers that corresponds to the second type of marker.
8. The method according to claim 6 or 7, characterized in that, After the electronic device adds second drawing content to the active layer, the method further includes: The electronic device determines to draw a dirty area, which includes the second drawing content.
9. The method according to claim 8, characterized in that, Based on the overlap between the second drawn content and the first drawn content in the Mth layer, the electronic device adds the Mth layer to the layer composition list, specifically including: If the electronic device determines that the bounding box intersects with the dirty drawing area, and the electronic device determines that the slice marker intersects with the dirty drawing area, the electronic device determines that the second drawing content overlaps with the first drawing content in the Mth layer; The electronic device adds the Mth layer to the layer composition list.
10. The method according to claim 9, characterized in that, The electronic device obtains a second composite result based on the layer composite list and the first composite result, specifically including: The electronic device combines the layers in the layer composition list with the areas that overlap with the drawn dirty areas to obtain a dirty area composition result; The electronic device replaces the region in the first synthesis result that overlaps with the drawn dirty region with the dirty region synthesis result to obtain the second synthesis result.
11. A layer processing method, characterized in that, The method is applied to an electronic device, and the method includes: The electronic device displays a first layer, wherein the first layer has a first drawing content; In response to the operation of adding a new layer, the electronic device adds a second layer and displays a first composite result of the first layer and the second layer; wherein, the second layer is a non-empty layer; the electronic device saves a slice of the first layer containing the first drawn content; the first layer slice is a part of the first layer; In response to a drawing operation on the second layer, a second drawing content is added to the second layer; wherein the second drawing content overlaps with a slice of the first layer; The electronic device obtains a second composite result based on the second layer and slices of the first layer; The electronic device displays the second synthesis result.
12. The method according to claim 11, characterized in that, The electronic device stores a slice of the first layer containing the first drawn content, specifically including: The electronic device divides the first layer into multiple layer slices; The electronic device determines the slice marker of the first layer based on the first drawn content. The slice marker includes a first type of marker and a second type of marker. The first type of marker is used to indicate that the layer slice has no drawn content, and the second type of marker is used to indicate that the layer slice has drawn content. The layer slice corresponding to the second type of marker is the first layer slice. For the first layer, the electronic device does not save the layer slice corresponding to the first type of mark, but saves the first layer slice.
13. The method according to claim 12, characterized in that, In response to a drawing operation on the second layer, the electronic device adds second drawing content to the second layer, specifically including: The electronic device adds the second drawing content to the second layer based on the drawing operation on the second layer; The electronic device determines the dirty area of the second layer based on the second drawing content, and the dirty area includes the second drawing content.
14. The method according to claim 13, characterized in that, The electronic device obtains a second composite result based on the second layer and slices of the first layer, specifically including: The electronic device merges the pixels of the drawn dirty area in the second layer with the pixels in the slice of the first layer that correspond to the drawn dirty area to obtain a dirty area synthesis result; The electronic device replaces the portion of the first synthesis result that overlaps with the drawn dirty region with the dirty region synthesis result to obtain the second synthesis result.
15. The method according to any one of claims 11-14, characterized in that, After the electronic device adds the second drawing content to the second layer, the method further includes: In response to a modification operation on the second layer, the second drawing content of the second layer is modified; wherein, the modification operation includes shrinking, enlarging, moving, or adding the second drawing content of the second layer; In response to the operation of adding a new layer, the electronic device adds a third layer; the third layer is an empty layer. The electronic device is based on the modified second layer, retaining a slice of the second layer containing the second drawing content, and the slice of the second layer is a part of the second layer.
16. An electronic device, characterized in that, include: A processor and a memory, the memory being coupled to the processor, the memory being used to store computer program code, the computer program code including computer instructions, which, when the processor reads the computer instructions from the memory, cause the electronic device to perform the method as described in any one of claims 1-15.
17. A chip system applied to an electronic device, the chip system comprising one or more processors, characterized in that, The processor is used to invoke computer instructions to perform the method as described in any one of claims 1-15.
18. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a computer program that, when run on an electronic device, causes the electronic device to perform the method as described in any one of claims 1-15.
19. A computer program product, characterized in that, When the computer program product is run on a computer, it causes the electronic device to perform the method as described in any one of claims 1-15.