doc.go (3170B)
1 // Copyright 2017 The Ebiten Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package restorable offers an Image struct that stores image commands 16 // and restores its pixel data from the commands when context lost happens. 17 // 18 // When a function like DrawImage or Fill is called, an Image tries to record 19 // the information for restoring. 20 // 21 // * Context lost 22 // 23 // Contest lost is a process that information on GPU memory are removed by OS 24 // to make more room on GPU memory. 25 // This can happen e.g. when GPU memory usage is high, or just switching applications 26 // might cause context lost on mobiles. 27 // As Ebiten's image data is on GPU memory, the game can't continue when context lost happens 28 // without restoring image information. 29 // The package restorable is the package to record information for such restoring. 30 // 31 // * DrawImage 32 // 33 // DrawImage function tries to record an item of 'draw image history' in the target image. 34 // If a target image is stale or volatile, no item is created. 35 // If an item of the history is created, 36 // it can be said that the target image depends on the source image. 37 // In other words, If A.DrawImage(B, ...) is called, 38 // it can be said that the image A depends on the image B. 39 // 40 // * Fill, ReplacePixels and Dispose 41 // 42 // These functions are also drawing functions and the target image stores the pixel data 43 // instead of draw image history items. There is no dependency here. 44 // 45 // * Making images stale 46 // 47 // After any of the drawing functions is called, the target image can't be depended on by 48 // any other images. For example, if an image A depends on an image B, and B is changed 49 // by a Fill call after that, the image A can't depend on the image B any more. 50 // In this case, as the image B can no longer be used to restore the image A, 51 // the image A becomes 'stale'. 52 // As all the stale images are resolved before context lost happens, 53 // draw image history items are kept as they are 54 // (even if an image C depends on the stale image A, it is still fine). 55 // 56 // * Stale image 57 // 58 // A stale image is an image that can't be restored from the recorded information. 59 // All stale images must be resolved by reading pixels from GPU before the frame ends. 60 // If a source image of DrawImage is a stale image, the target always becomes stale. 61 // 62 // * Volatile image 63 // 64 // A volatile image is a special image that is always cleared when a frame starts. 65 // For instance, the game screen passed via the update function is a volatile image. 66 // A volatile image doesn't have to record the drawing history. 67 // If a source image of DrawImage is a volatile image, the target always becomes stale. 68 package restorable