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