ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
ภาพรวมงาน
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ภาพหน้าจองานคือโครงสร้างพื้นฐานที่เปิดตัวใน Android 8.0 ซึ่งรวมภาพหน้าจอสำหรับภาพขนาดย่อล่าสุดและพื้นที่ทำงานที่บันทึกไว้จากเครื่องมือจัดการหน้าต่าง ภาพขนาดย่อล่าสุดแสดงสถานะล่าสุดของงานในมุมมองล่าสุด
เมื่อกิจกรรมเข้าสู่สถานะหยุดทำงาน ตัวจัดการหน้าต่างจะไม่ทำลายพื้นผิวของกิจกรรม ตราบใดที่กิจกรรมนั้นอยู่ด้านบนของงาน หากต้องแสดงกิจกรรมนี้อีกครั้ง เครื่องมือจัดการหน้าต่างจะเริ่มภาพเคลื่อนไหวได้โดยไม่ต้องรอให้กิจกรรมวาดเฟรมแรกเสร็จ เนื่องจากสามารถใช้พื้นผิวที่บันทึกไว้นี้
สถาปัตยกรรม
แนวคิดของภาพปกรายการล่าสุดและพื้นผิวที่บันทึกไว้จะรวมเข้ากับภาพหน้าจอของงาน เมื่องานทำงานอยู่เบื้องหลัง ตัวจัดการหน้าต่างจะวางภาพหน้าจอของงานนี้ลงใน GraphicBuffer ตราบใดที่แอปของกิจกรรมที่ทำงานอยู่สูงสุดของงานยังคงอยู่ในหน่วยความจำ GraphicBuffer นี้จะยังคงอยู่ในหน่วยความจำ ตอนนี้เมื่อนํากิจกรรมเดียวกันมาไว้ที่ด้านหน้าอีกครั้ง WindowManager จะสร้างหน้าต่างเริ่มต้น (TaskSnapshotSurface) และแนบ GraphicBuffer โดยไม่คัดลอกหน่วยความจําไปยังคิวบัฟเฟอร์ของหน้าต่างเริ่มต้น ทันทีที่กิจกรรมวาดเฟรมแรก หน้าต่างเริ่มต้นของภาพรวมงานจะค่อยๆ จางหายไปอย่างราบรื่นเหมือนหน้าจอเริ่มต้นปกติ
นอกจากนี้ ระบบจะส่ง GraphicBuffer เดียวกันผ่าน Binder ไปยัง SystemUI เพื่อใช้วาดสถานะแสดงตัวอย่างของงานในมุมมองรายการล่าสุด เนื่องจากนี่เป็นเพียงการอ้างอิงถึงบัฟเฟอร์ การส่งผ่าน Binder จึงใช้ทรัพยากรเพียงเล็กน้อย เมื่อ GraphicBuffer มาถึง SystemUI ระบบจะรวมไว้ในฮาร์ดแวร์บิตแมป จากนั้นจะวาดลงบนหน้าจอโดยไม่ต้องอัปโหลดหน่วยความจำไปยังหน่วยความจำกราฟิก
ประโยชน์
สถาปัตยกรรมใหม่นี้มีประโยชน์หลัก 3 ข้อดังนี้
- หากใช้ภาพหน้าจอของงานเป็นกรอบเวลาเริ่มต้น จะมีการเฟดภาพหน้าจอและเนื้อหาจริงเข้าด้วยกันอย่างสวยงาม
- เมื่อวาดภาพสแนปชอตงานใน SystemUI คุณจะวาดภาพได้โดยไม่ต้องคัดลอก ก่อนหน้านี้ต้องคัดลอกบิตแมปไปยัง Ashmem แล้วคัดลอกไปยังหน่วยความจำกราฟิก เนื่องจากวิธีการนี้จัดเก็บสแนปชอตในหน่วยความจำกราฟิกโดยตรง จึงไม่จำเป็นต้องคัดลอก
- สถานะที่คุณเห็นในส่วนล่าสุดจะตรงกับสถานะที่คุณจะเห็นเป็นครั้งแรกเมื่อเปิดแอปอีกครั้งเสมอ นอกจากนี้การมีบัฟเฟอร์เดียวกันที่นี่ยังช่วยประหยัดหน่วยความจำได้มากอีกด้วย
ด้วยเหตุนี้ ล่าสุดจึงแสดงรูปภาพเหล่านี้แบบเต็มความละเอียดได้
ก่อนหน้านี้ระบบจะลดขนาดภาพลง 64% เพื่อประหยัดหน่วยความจำ
การใช้งาน
ฟีเจอร์นี้มีอยู่ในแพลตฟอร์ม Android ทั้งหมด ไม่ต้องมีการผสานรวมและไม่รองรับการปรับแต่ง อย่างไรก็ตาม ผู้ผลิตอุปกรณ์สามารถปิดใช้ฟีเจอร์ภาพรวมงานทั้งหมดได้
หากต้องการปิดใช้ฟีเจอร์นี้ ให้แก้ไขฟังก์ชันนี้
frameworks/base/services/core/java/com/android/server/wm/TaskSnapshotController.java#215
โปรดทราบว่าหากปิดใช้ฟีเจอร์นี้ มุมมองล่าสุดจะไม่แสดงภาพปกใดๆ เลย
สแนปชอตความละเอียดสูงและความละเอียดต่ำ
ระบบจะเขียนภาพรวมงานลงในดิสก์ที่ 2 ระดับ เมื่อกู้คืนภาพรวมงานจากดิสก์ ระบบจะอ่านภาพรวมที่มีความละเอียดต่ำก่อน แล้วแทนที่ด้วยภาพรวมที่มีความละเอียดสูง การเพิ่มประสิทธิภาพนี้จะช่วยปรับปรุงเวลาในการโหลดรูปภาพ
มิเช่นนั้น ระบบอาจเกิดความล่าช้าเล็กน้อยเมื่ออ่านไฟล์สแนปชอตจากดิสก์ และผู้ใช้จะเห็นการ์ดงานว่างเปล่าจนกว่าจะมีรูปภาพ
คุณกำหนดค่ารูปแบบในไฟล์การกําหนดค่าการวางซ้อนอุปกรณ์
overlay/frameworks/base/core/res/res/values/config.xml
ได้โดยการตั้งค่า
config_highResTaskSnapshotScale
และ
config_lowResTaskSnapshotScale
โดยค่าเริ่มต้น ระบบจะตั้งค่าเหล่านี้เป็น 1.0 และ 0.5 ตามลำดับ ปิดใช้ภาพนิ่งที่มีความละเอียดต่ำโดยการตั้งค่า
config_lowResTaskSnapshotScale
เป็น 0.0
ตัวอย่างและแหล่งที่มา
ค้นหาโค้ดที่เหลือของฟีเจอร์นี้ภายในไฟล์ TaskSnapshot* ในส่วนต่อไปนี้
frameworks/base/+/android16-release/services/core/java/com/android/server/wm/
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# Task snapshots\n\n*Task Snapshots* is infrastructure introduced in Android 8.0 that combines\nscreenshots for *Recents Thumbnails* as well as *Saved Surfaces*\nfrom Window Manager. Recents Thumbnails represent the last state of a task in\nthe Recents view.\n\n\nWhen an activity went into a stopped state, Window Manager didn't destroy the\nsurfaces of the activity as long as that activity was on the top of the task. If\nthis activity had to be shown again, Window Manager was able to start the\nanimation without waiting for the activity to finish drawing its first frame, as\nit was able to use this Saved Surface.\n\nArchitecture\n------------\n\n\nThe two concepts of Recents Thumbnails and Saved Surfaces are unified with Task\nSnapshots. When a task goes into background, Window Manager places a screenshot\nof this task into a GraphicBuffer. As long as the app of the top\nactivity of the task stays in memory, this GraphicBuffer will be retained in\nmemory. Now, when the same activity is brought to the front again, Window\nManager will create a starting window (TaskSnapshotSurface), and attach the\nGraphicBuffer without copying any memory to the buffer queue of the starting\nwindow. As soon as the activity has drawn its first frame, the Task Snapshot\nstarting window will fade out smoothly like regular splash screens.\n\n\nThe same GraphicBuffer is also sent over Binder to SystemUI to be used to draw\nthe preview state of a task in the Recents view. Since this is just a reference\nto a buffer, sending it over binder expends few resources. When the\nGraphicBuffer arrives at SystemUI, it is wrapped into a hardware Bitmap and then\ndrawn onto the screen without any memory uploading to the graphics memory.\n\nBenefits\n--------\n\n\nThere are three main benefits to this new architecture:\n\n- If the task snapshot is used as a starting window, there is a nice crossfade between the snapshot and the real content.\n- When the task snapshot is drawn in SystemUI, it can be done so without any copying. Previously the bitmap had to be copied into Ashmem, then into graphics memory. Since this method stores the snapshot directly in graphics memory, no copying is needed.\n- The state you see in Recents always matches the state you'll first see when reopening the app. Having the same buffer here also saves a lot of memory. That's why Recents is now able to show these images at full resolution. Previously, it was down sampled by 64% to save memory.\n\nImplementation\n--------------\n\n\nThis feature exists entirely in the Android platform. No integration is\nrequired, and customization isn't supported. However, device manufacturers can\ndisable the Task Snapshots feature entirely.\n\n\nTo disable this feature, modify this function: \n\n```text\nframeworks/base/services/core/java/com/android/server/wm/TaskSnapshotController.java#215\n```\n\n\nNote that if the feature is disabled, the Recents view will not show any\nthumbnails whatsoever.\n\nHigh-res and low-res snapshots\n------------------------------\n\nTask snapshots are written to the disk at two scales. When restoring a task snapshot from the disk, low-res snapshots are read first, and then replaced by their high-res counterpart. This optimization improves image load times. Otherwise, there could be a slight delay when reading the snapshot file from the disk, and the user would see a blank task card until the image was available. You can configure the scales in the device overlay config file `overlay/frameworks/base/core/res/res/values/config.xml` by setting `config_highResTaskSnapshotScale` and `config_lowResTaskSnapshotScale`. By default, these are set to 1.0 and 0.5 respectively. Disable low-res snapshots by setting `config_lowResTaskSnapshotScale` to 0.0.\n\nExamples and source\n-------------------\n\n\nFind the rest of the code for this feature within the TaskSnapshot\\* files in: \n\n```text\nframeworks/base/+/android16-release/services/core/java/com/android/server/wm/\n```"]]