Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef UI_GFX_OZONE_IMPL_SOFTWARE_SURFACE_OZONE_H_ | |
| 6 #define UI_GFX_OZONE_IMPL_SOFTWARE_SURFACE_OZONE_H_ | |
| 7 | |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/memory/scoped_vector.h" | |
| 11 #include "ui/gfx/skia_util.h" | |
| 12 | |
| 13 class SkBitmapDevice; | |
| 14 class SkCanvas; | |
| 15 | |
| 16 namespace gfx { | |
| 17 | |
| 18 class BufferGeneratorOzone; | |
| 19 class DrmSkBitmapOzone; | |
| 20 class HardwareDisplayControllerOzone; | |
| 21 | |
| 22 // SoftwareSurfaceOzone is used to represent a surface that can be scanned out | |
|
rjkroege
2013/10/11 17:26:51
this is awesome comment
| |
| 23 // to a monitor. It will store the internal state associated with the drawing | |
| 24 // surface associated with it. SoftwareSurfaceOzone also performs all the needed | |
| 25 // operations to initialize and update the drawing surface. | |
| 26 // | |
| 27 // The implementation uses dumb buffers, which is used for software rendering. | |
| 28 // The intent is to have one SoftwareSurfaceOzone implementation for a | |
| 29 // HardwareDisplayControllerOzone. | |
| 30 // | |
| 31 // DoubleBufferedSurface is intended to be the software analog to | |
| 32 // EGLNativeSurface while SoftwareSurfaceOzone is intended to provide the glue | |
| 33 // necessary to initialize and display the surface to the screen. | |
| 34 // | |
| 35 // The typical usage pattern is: | |
| 36 // ----------------------------------------------------------------------------- | |
| 37 // HardwareDisplayControllerOzone controller; | |
| 38 // // Initialize controller | |
| 39 // | |
| 40 // SoftwareSurfaceOzone* surface = new SoftwareSurfaceOzone(); | |
| 41 // controller.Initialize(); | |
|
rjkroege
2013/10/11 17:26:51
your example is missing the call to surface->Initi
dnicoara
2013/10/11 19:20:07
Done.
| |
| 42 // | |
| 43 // while (true) { | |
| 44 // SkCanvas* canvas = surface->GetDrawableForWidget(); | |
| 45 // DrawStuff(canvas); | |
| 46 // controller.SchedulePageFlip(); | |
| 47 // | |
| 48 // Wait for page flip event. The DRM page flip handler will call | |
| 49 // surface.SwapBuffers(); | |
| 50 // } | |
| 51 // | |
| 52 // delete surface; | |
| 53 // ----------------------------------------------------------------------------- | |
| 54 // In the above example the wait consists of reading a DRM pageflip event from | |
| 55 // the graphics card file descriptor. This is done by calling |drmHandleEvent|, | |
| 56 // which will read and process the event. |drmHandleEvent| will call a callback | |
| 57 // registered by |SchedulePageFlip| which will update the internal state. | |
| 58 // | |
| 59 // |SchedulePageFlip| can also be used to limit drawing to the screen's vsync | |
| 60 // since page flips only happen on vsync. In a threaded environment a message | |
| 61 // loop would listen on the graphics card file descriptor for an event and | |
| 62 // |drmHandleEvent| would be called from the message loop. The event handler | |
| 63 // would also be responsible for updating the renderer's state and signal that | |
| 64 // it is OK to start drawing the next frame. | |
| 65 // | |
| 66 // The following example will illustrate the system state transitions in one | |
| 67 // iteration of the above loop. | |
| 68 // | |
| 69 // 1. Both buffers contain the same image with b[0] being the front buffer | |
| 70 // (star will represent the frontbuffer). | |
| 71 // ------- ------- | |
| 72 // | | | | | |
| 73 // | | | | | |
| 74 // | | | | | |
| 75 // | | | | | |
| 76 // ------- ------- | |
| 77 // b[0]* b[1] | |
| 78 // | |
| 79 // 2. Call |GetBackbuffer| to get a SkCanvas wrapper for the backbuffer and draw | |
| 80 // to it. | |
| 81 // ------- ------- | |
| 82 // | | | | | |
| 83 // | | | d | | |
| 84 // | | | | | |
| 85 // | | | | | |
| 86 // ------- ------- | |
| 87 // b[0]* b[1] | |
| 88 // | |
| 89 // 3. Call |SchedulePageFlip| to display the backbuffer. At this point we can't | |
| 90 // modify b[0] because it is the frontbuffer and we can't modify b[1] since it | |
| 91 // has been scheduled for pageflip. If we do draw in b[1] it is possible that | |
| 92 // the pageflip and draw happen at the same time and we could get tearing. | |
| 93 // | |
| 94 // 4. The pageflip callback is called which will call |SwapSurfaces|. Before | |
| 95 // |SwapSurfaces| is called the state is as following from the hardware's | |
| 96 // perspective: | |
| 97 // ------- ------- | |
| 98 // | | | | | |
| 99 // | | | d | | |
| 100 // | | | | | |
| 101 // | | | | | |
| 102 // ------- ------- | |
| 103 // b[0] b[1]* | |
| 104 // | |
| 105 // 5. |SwapSurfaces| will update out internal reference to the front buffer and | |
| 106 // synchronize the damaged area such that both buffers are identical. The | |
| 107 // damaged area is used from the SkCanvas clip. | |
| 108 // ------- ------- | |
| 109 // | | | | | |
| 110 // | d | | d | | |
| 111 // | | | | | |
| 112 // | | | | | |
| 113 // ------- ------- | |
| 114 // b[0] b[1]* | |
| 115 // | |
| 116 // The synchronization consists of copying the damaged area from the frontbuffer | |
| 117 // to the backbuffer. | |
| 118 // | |
| 119 // At this point we're back to step 1 and can start a new draw iteration. | |
| 120 class SoftwareSurfaceOzone { | |
| 121 public: | |
| 122 SoftwareSurfaceOzone(HardwareDisplayControllerOzone* controller, | |
| 123 BufferGeneratorOzone* buffer_generator); | |
| 124 | |
| 125 ~SoftwareSurfaceOzone(); | |
| 126 | |
| 127 // Used to allocate all necessary buffers for this surface. If the | |
| 128 // initialization succeeds, the device is ready to be used for drawing | |
| 129 // operations. | |
| 130 // Returns true if the initialization is successful, false otherwise. | |
| 131 bool Initialize(); | |
| 132 | |
| 133 // Returns the ID of the current backbuffer. | |
| 134 uint32_t GetFramebufferId() const; | |
| 135 | |
| 136 // Synchronizes and swaps the back buffer with the front buffer. | |
| 137 void SwapBuffers(); | |
| 138 | |
| 139 // Get a Skia canvas for a backbuffer. | |
| 140 SkCanvas* GetDrawableForWidget(); | |
| 141 | |
| 142 private: | |
| 143 friend class HardwareDisplayControllerOzone; | |
| 144 | |
| 145 // Used to create the backing buffers. | |
| 146 BufferGeneratorOzone* buffer_generator_; | |
| 147 | |
| 148 // Stores DRM information for this output device (connector, encoder, last | |
| 149 // CRTC state). | |
| 150 HardwareDisplayControllerOzone* controller_; | |
| 151 | |
| 152 // The actual buffers used for painting. | |
| 153 ScopedVector<DrmSkBitmapOzone> bitmaps_; | |
|
rjkroege
2013/10/11 17:26:51
there are always two? use a fixed size scoped_ptr.
dnicoara
2013/10/11 19:20:07
Done.
| |
| 154 | |
| 155 // BitmapDevice for the current backbuffer. | |
| 156 skia::RefPtr<SkBitmapDevice> skia_device_; | |
| 157 | |
| 158 // Canvas for the current backbuffer. | |
| 159 skia::RefPtr<SkCanvas> skia_canvas_; | |
| 160 | |
| 161 // Keeps track of which bitmap is |buffers_| is the frontbuffer. | |
| 162 int front_buffer_; | |
| 163 | |
| 164 DISALLOW_COPY_AND_ASSIGN(SoftwareSurfaceOzone); | |
| 165 }; | |
| 166 | |
| 167 } // namespace gfx | |
| 168 | |
| 169 #endif // UI_GFX_OZONE_IMPL_SOFTWARE_SURFACE_OZONE_H_ | |
| OLD | NEW |