| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "public/platform/WebExternalTextureLayerClient.h" | 33 #include "public/platform/WebExternalTextureLayerClient.h" |
| 34 #include "public/platform/WebExternalTextureMailbox.h" | 34 #include "public/platform/WebExternalTextureMailbox.h" |
| 35 #include "public/platform/WebThread.h" | 35 #include "public/platform/WebThread.h" |
| 36 #include "third_party/khronos/GLES2/gl2.h" | 36 #include "third_party/khronos/GLES2/gl2.h" |
| 37 #include "third_party/skia/include/core/SkImage.h" | 37 #include "third_party/skia/include/core/SkImage.h" |
| 38 #include "wtf/Allocator.h" | 38 #include "wtf/Allocator.h" |
| 39 #include "wtf/Deque.h" | 39 #include "wtf/Deque.h" |
| 40 #include "wtf/PassOwnPtr.h" | 40 #include "wtf/PassOwnPtr.h" |
| 41 #include "wtf/RefCounted.h" | 41 #include "wtf/RefCounted.h" |
| 42 #include "wtf/RefPtr.h" | 42 #include "wtf/RefPtr.h" |
| 43 #include "wtf/Vector.h" |
| 43 #include "wtf/WeakPtr.h" | 44 #include "wtf/WeakPtr.h" |
| 44 | 45 |
| 45 class SkPictureRecorder; | 46 class SkPictureRecorder; |
| 46 | 47 |
| 47 namespace blink { | 48 namespace blink { |
| 48 | 49 |
| 49 class Canvas2DLayerBridgeHistogramLogger; | 50 class Canvas2DLayerBridgeHistogramLogger; |
| 50 class Canvas2DLayerBridgeTest; | 51 class Canvas2DLayerBridgeTest; |
| 51 class ImageBuffer; | 52 class ImageBuffer; |
| 52 class WebGraphicsContext3D; | 53 class WebGraphicsContext3D; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 class PLATFORM_EXPORT Logger { | 120 class PLATFORM_EXPORT Logger { |
| 120 public: | 121 public: |
| 121 virtual void reportHibernationEvent(HibernationEvent); | 122 virtual void reportHibernationEvent(HibernationEvent); |
| 122 virtual void didStartHibernating() { } | 123 virtual void didStartHibernating() { } |
| 123 virtual ~Logger() { } | 124 virtual ~Logger() { } |
| 124 }; | 125 }; |
| 125 | 126 |
| 126 void setLoggerForTesting(PassOwnPtr<Logger>); | 127 void setLoggerForTesting(PassOwnPtr<Logger>); |
| 127 | 128 |
| 128 private: | 129 private: |
| 130 // All information associated with a CHROMIUM image. |
| 131 struct ImageInfo { |
| 132 ImageInfo() {} |
| 133 ImageInfo(GLuint imageId, GLuint textureId); |
| 134 |
| 135 // Whether this structure holds references to a CHROMIUM image. |
| 136 bool empty(); |
| 137 |
| 138 // The id of the CHROMIUM image. |
| 139 GLuint m_imageId = 0; |
| 140 |
| 141 // The id of the texture bound to the CHROMIUM image. |
| 142 GLuint m_textureId = 0; |
| 143 }; |
| 144 |
| 145 struct MailboxInfo { |
| 146 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 147 WebExternalTextureMailbox m_mailbox; |
| 148 RefPtr<SkImage> m_image; |
| 149 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; |
| 150 |
| 151 // If this mailbox wraps an IOSurface-backed texture, the ids of the |
| 152 // CHROMIUM image and the texture. |
| 153 ImageInfo m_imageInfo; |
| 154 |
| 155 MailboxInfo(const MailboxInfo&); |
| 156 MailboxInfo() {} |
| 157 }; |
| 158 |
| 129 Canvas2DLayerBridge(PassOwnPtr<WebGraphicsContext3DProvider>, const IntSize&
, int msaaSampleCount, OpacityMode, AccelerationMode); | 159 Canvas2DLayerBridge(PassOwnPtr<WebGraphicsContext3DProvider>, const IntSize&
, int msaaSampleCount, OpacityMode, AccelerationMode); |
| 130 WebGraphicsContext3D* context(); | 160 WebGraphicsContext3D* context(); |
| 131 void startRecording(); | 161 void startRecording(); |
| 132 void skipQueuedDrawCommands(); | 162 void skipQueuedDrawCommands(); |
| 133 void flushRecordingOnly(); | 163 void flushRecordingOnly(); |
| 134 void unregisterTaskObserver(); | 164 void unregisterTaskObserver(); |
| 135 void reportSurfaceCreationFailure(); | 165 void reportSurfaceCreationFailure(); |
| 136 | 166 |
| 137 // WebThread::TaskOberver implementation | 167 // WebThread::TaskOberver implementation |
| 138 void willProcessTask() override; | 168 void willProcessTask() override; |
| 139 void didProcessTask() override; | 169 void didProcessTask() override; |
| 140 | 170 |
| 141 SkSurface* getOrCreateSurface(AccelerationHint = PreferAcceleration); | 171 SkSurface* getOrCreateSurface(AccelerationHint = PreferAcceleration); |
| 142 bool shouldAccelerate(AccelerationHint) const; | 172 bool shouldAccelerate(AccelerationHint) const; |
| 143 | 173 |
| 174 // Returns the GL filter associated with |m_filterQuality|. |
| 175 GLenum getGLFilter(); |
| 176 |
| 177 // Creates an IOSurface-backed texture. Copies |image| into the texture. |
| 178 // Prepares a mailbox from the texture. Stores all information in a newly |
| 179 // created MailboxInfo, which resides in |m_mailboxes|. Returns whether the |
| 180 // mailbox was successfully prepared. |mailbox| is an out parameter only |
| 181 // populated on success. |
| 182 bool prepareIOSurfaceMailboxFromImage(RefPtr<SkImage>, WebExternalTextureMai
lbox*); |
| 183 |
| 184 // Creates an IOSurface-backed texture. Returns an ImageInfo, which is empty |
| 185 // on failure. The caller takes ownership of both the texture and the image. |
| 186 ImageInfo createIOSurfaceBackedTexture(); |
| 187 |
| 188 // Prepends a new MailboxInfo object to |m_mailboxes|, and returns a |
| 189 // reference. The reference is no longer valid after |m_mailboxes| is |
| 190 // mutated. |
| 191 MailboxInfo& createMailboxInfo(); |
| 192 |
| 193 // Returns whether the mailbox was successfully prepared from the SkImage. |
| 194 // The mailbox is an out parameter only populated on success. |
| 195 bool prepareMailboxFromImage(RefPtr<SkImage>, WebExternalTextureMailbox*); |
| 196 |
| 197 // Resets Skia's texture bindings. This method should be called after |
| 198 // changing texture bindings. |
| 199 void resetSkiaTextureBinding(); |
| 200 |
| 201 // Releases all resources associated with a CHROMIUM image. |
| 202 void deleteCHROMIUMImage(ImageInfo); |
| 203 |
| 144 OwnPtr<SkPictureRecorder> m_recorder; | 204 OwnPtr<SkPictureRecorder> m_recorder; |
| 145 RefPtr<SkSurface> m_surface; | 205 RefPtr<SkSurface> m_surface; |
| 146 RefPtr<SkImage> m_hibernationImage; | 206 RefPtr<SkImage> m_hibernationImage; |
| 147 int m_initialSurfaceSaveCount; | 207 int m_initialSurfaceSaveCount; |
| 148 OwnPtr<WebExternalTextureLayer> m_layer; | 208 OwnPtr<WebExternalTextureLayer> m_layer; |
| 149 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; | 209 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; |
| 150 OwnPtr<SharedContextRateLimiter> m_rateLimiter; | 210 OwnPtr<SharedContextRateLimiter> m_rateLimiter; |
| 151 OwnPtr<Logger> m_logger; | 211 OwnPtr<Logger> m_logger; |
| 152 WeakPtrFactory<Canvas2DLayerBridge> m_weakPtrFactory; | 212 WeakPtrFactory<Canvas2DLayerBridge> m_weakPtrFactory; |
| 153 ImageBuffer* m_imageBuffer; | 213 ImageBuffer* m_imageBuffer; |
| 154 int m_msaaSampleCount; | 214 int m_msaaSampleCount; |
| 155 size_t m_bytesAllocated; | 215 size_t m_bytesAllocated; |
| 156 bool m_haveRecordedDrawCommands; | 216 bool m_haveRecordedDrawCommands; |
| 157 bool m_destructionInProgress; | 217 bool m_destructionInProgress; |
| 158 SkFilterQuality m_filterQuality; | 218 SkFilterQuality m_filterQuality; |
| 159 bool m_isHidden; | 219 bool m_isHidden; |
| 160 bool m_isDeferralEnabled; | 220 bool m_isDeferralEnabled; |
| 161 bool m_isRegisteredTaskObserver; | 221 bool m_isRegisteredTaskObserver; |
| 162 bool m_renderingTaskCompletedForCurrentFrame; | 222 bool m_renderingTaskCompletedForCurrentFrame; |
| 163 bool m_softwareRenderingWhileHidden; | 223 bool m_softwareRenderingWhileHidden; |
| 164 bool m_surfaceCreationFailedAtLeastOnce = false; | 224 bool m_surfaceCreationFailedAtLeastOnce = false; |
| 165 bool m_hibernationScheduled = false; | 225 bool m_hibernationScheduled = false; |
| 166 | 226 |
| 167 friend class Canvas2DLayerBridgeTest; | 227 friend class Canvas2DLayerBridgeTest; |
| 168 | 228 |
| 169 struct MailboxInfo { | |
| 170 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | |
| 171 WebExternalTextureMailbox m_mailbox; | |
| 172 RefPtr<SkImage> m_image; | |
| 173 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; | |
| 174 | |
| 175 MailboxInfo(const MailboxInfo&); | |
| 176 MailboxInfo() {} | |
| 177 }; | |
| 178 | |
| 179 uint32_t m_lastImageId; | 229 uint32_t m_lastImageId; |
| 180 | 230 |
| 181 enum { | 231 enum { |
| 182 // We should normally not have more that two active mailboxes at a time, | 232 // We should normally not have more that two active mailboxes at a time, |
| 183 // but sometime we may have three due to the async nature of mailbox han
dling. | 233 // but sometime we may have three due to the async nature of mailbox han
dling. |
| 184 MaxActiveMailboxes = 3, | 234 MaxActiveMailboxes = 3, |
| 185 }; | 235 }; |
| 186 | 236 |
| 187 Deque<MailboxInfo, MaxActiveMailboxes> m_mailboxes; | 237 Deque<MailboxInfo, MaxActiveMailboxes> m_mailboxes; |
| 188 GLenum m_lastFilter; | 238 GLenum m_lastFilter; |
| 189 AccelerationMode m_accelerationMode; | 239 AccelerationMode m_accelerationMode; |
| 190 OpacityMode m_opacityMode; | 240 OpacityMode m_opacityMode; |
| 191 IntSize m_size; | 241 const IntSize m_size; |
| 192 int m_recordingPixelCount; | 242 int m_recordingPixelCount; |
| 243 |
| 244 // Each element in this vector represents an IOSurface backed texture that |
| 245 // is ready to be reused. |
| 246 // Elements in this vector can safely be purged in low memory conditions. |
| 247 Vector<ImageInfo> m_imageInfoCache; |
| 193 }; | 248 }; |
| 194 | 249 |
| 195 } // namespace blink | 250 } // namespace blink |
| 196 | 251 |
| 197 #endif | 252 #endif |
| OLD | NEW |