| 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; |
| 53 class WebGraphicsContext3DProvider; | 54 class WebGraphicsContext3DProvider; |
| 54 class SharedContextRateLimiter; | 55 class SharedContextRateLimiter; |
| 55 | 56 |
| 56 #if OS(MACOSX) | 57 #if OS(MACOSX) |
| 57 // Canvas hibernation is currently disabled on MacOS X due to a bug that causes
content loss | 58 // Canvas hibernation is currently disabled on MacOS X due to a bug that causes
content loss |
| 58 // TODO: Find a better fix for crbug.com/588434 | 59 // TODO: Find a better fix for crbug.com/588434 |
| 59 #define CANVAS2D_HIBERNATION_ENABLED 0 | 60 #define CANVAS2D_HIBERNATION_ENABLED 0 |
| 61 |
| 62 // IOSurfaces are a primitive only present on OS X. |
| 63 #define USE_IOSURFACE_FOR_2D_CANVAS 1 |
| 60 #else | 64 #else |
| 61 #define CANVAS2D_HIBERNATION_ENABLED 1 | 65 #define CANVAS2D_HIBERNATION_ENABLED 1 |
| 66 #define USE_IOSURFACE_FOR_2D_CANVAS 0 |
| 62 #endif | 67 #endif |
| 63 | 68 |
| 64 class PLATFORM_EXPORT Canvas2DLayerBridge : public WebExternalTextureLayerClient
, public WebThread::TaskObserver, public RefCounted<Canvas2DLayerBridge> { | 69 class PLATFORM_EXPORT Canvas2DLayerBridge : public WebExternalTextureLayerClient
, public WebThread::TaskObserver, public RefCounted<Canvas2DLayerBridge> { |
| 65 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); | 70 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); |
| 66 public: | 71 public: |
| 67 enum AccelerationMode { | 72 enum AccelerationMode { |
| 68 DisableAcceleration, | 73 DisableAcceleration, |
| 69 EnableAcceleration, | 74 EnableAcceleration, |
| 70 ForceAccelerationForTesting, | 75 ForceAccelerationForTesting, |
| 71 }; | 76 }; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 class PLATFORM_EXPORT Logger { | 132 class PLATFORM_EXPORT Logger { |
| 128 public: | 133 public: |
| 129 virtual void reportHibernationEvent(HibernationEvent); | 134 virtual void reportHibernationEvent(HibernationEvent); |
| 130 virtual void didStartHibernating() { } | 135 virtual void didStartHibernating() { } |
| 131 virtual ~Logger() { } | 136 virtual ~Logger() { } |
| 132 }; | 137 }; |
| 133 | 138 |
| 134 void setLoggerForTesting(PassOwnPtr<Logger>); | 139 void setLoggerForTesting(PassOwnPtr<Logger>); |
| 135 | 140 |
| 136 private: | 141 private: |
| 142 #if USE_IOSURFACE_FOR_2D_CANVAS |
| 143 // All information associated with a CHROMIUM image. |
| 144 struct ImageInfo { |
| 145 ImageInfo() {} |
| 146 ImageInfo(GLuint imageId, GLuint textureId); |
| 147 |
| 148 // Whether this structure holds references to a CHROMIUM image. |
| 149 bool empty(); |
| 150 |
| 151 // The id of the CHROMIUM image. |
| 152 GLuint m_imageId = 0; |
| 153 |
| 154 // The id of the texture bound to the CHROMIUM image. |
| 155 GLuint m_textureId = 0; |
| 156 }; |
| 157 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 158 |
| 137 struct MailboxInfo { | 159 struct MailboxInfo { |
| 138 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 160 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 139 WebExternalTextureMailbox m_mailbox; | 161 WebExternalTextureMailbox m_mailbox; |
| 140 RefPtr<SkImage> m_image; | 162 RefPtr<SkImage> m_image; |
| 141 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; | 163 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; |
| 142 | 164 |
| 165 #if USE_IOSURFACE_FOR_2D_CANVAS |
| 166 // If this mailbox wraps an IOSurface-backed texture, the ids of the |
| 167 // CHROMIUM image and the texture. |
| 168 ImageInfo m_imageInfo; |
| 169 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 170 |
| 143 MailboxInfo(const MailboxInfo&); | 171 MailboxInfo(const MailboxInfo&); |
| 144 MailboxInfo() {} | 172 MailboxInfo() {} |
| 145 }; | 173 }; |
| 146 | 174 |
| 147 Canvas2DLayerBridge(PassOwnPtr<WebGraphicsContext3DProvider>, const IntSize&
, int msaaSampleCount, OpacityMode, AccelerationMode); | 175 Canvas2DLayerBridge(PassOwnPtr<WebGraphicsContext3DProvider>, const IntSize&
, int msaaSampleCount, OpacityMode, AccelerationMode); |
| 148 WebGraphicsContext3D* context(); | 176 WebGraphicsContext3D* context(); |
| 149 void startRecording(); | 177 void startRecording(); |
| 150 void skipQueuedDrawCommands(); | 178 void skipQueuedDrawCommands(); |
| 151 void flushRecordingOnly(); | 179 void flushRecordingOnly(); |
| 152 void unregisterTaskObserver(); | 180 void unregisterTaskObserver(); |
| 153 void reportSurfaceCreationFailure(); | 181 void reportSurfaceCreationFailure(); |
| 154 | 182 |
| 155 // WebThread::TaskOberver implementation | 183 // WebThread::TaskOberver implementation |
| 156 void willProcessTask() override; | 184 void willProcessTask() override; |
| 157 void didProcessTask() override; | 185 void didProcessTask() override; |
| 158 | 186 |
| 159 SkSurface* getOrCreateSurface(AccelerationHint = PreferAcceleration); | 187 SkSurface* getOrCreateSurface(AccelerationHint = PreferAcceleration); |
| 160 bool shouldAccelerate(AccelerationHint) const; | 188 bool shouldAccelerate(AccelerationHint) const; |
| 161 | 189 |
| 162 // Returns the GL filter associated with |m_filterQuality|. | 190 // Returns the GL filter associated with |m_filterQuality|. |
| 163 GLenum getGLFilter(); | 191 GLenum getGLFilter(); |
| 164 | 192 |
| 165 // Prepends a new MailboxInfo object to |m_mailboxes|, and returns a | 193 #if USE_IOSURFACE_FOR_2D_CANVAS |
| 166 // reference. The reference is no longer valid after |m_mailboxes| is | 194 // Creates an IOSurface-backed texture. Copies |image| into the texture. |
| 167 // mutated. | 195 // Prepares a mailbox from the texture. The caller must have created a new |
| 168 MailboxInfo& createMailboxInfo(); | 196 // MailboxInfo, and prepended it to |m_mailboxs|. Returns whether the |
| 197 // mailbox was successfully prepared. |mailbox| is an out parameter only |
| 198 // populated on success. |
| 199 bool prepareIOSurfaceMailboxFromImage(SkImage*, WebExternalTextureMailbox*); |
| 200 |
| 201 // Creates an IOSurface-backed texture. Returns an ImageInfo, which is empty |
| 202 // on failure. The caller takes ownership of both the texture and the image. |
| 203 ImageInfo createIOSurfaceBackedTexture(); |
| 204 |
| 205 // Releases all resources associated with a CHROMIUM image. |
| 206 void deleteCHROMIUMImage(ImageInfo); |
| 207 |
| 208 // Releases all resources in the CHROMIUM image cache. |
| 209 void clearCHROMIUMImageCache(); |
| 210 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 211 |
| 212 // Prepends a new MailboxInfo object to |m_mailboxes|. |
| 213 void createMailboxInfo(); |
| 169 | 214 |
| 170 // Returns whether the mailbox was successfully prepared from the SkImage. | 215 // Returns whether the mailbox was successfully prepared from the SkImage. |
| 171 // The mailbox is an out parameter only populated on success. | 216 // The mailbox is an out parameter only populated on success. |
| 172 bool prepareMailboxFromImage(PassRefPtr<SkImage>, WebExternalTextureMailbox*
); | 217 bool prepareMailboxFromImage(PassRefPtr<SkImage>, WebExternalTextureMailbox*
); |
| 173 | 218 |
| 219 // Resets Skia's texture bindings. This method should be called after |
| 220 // changing texture bindings. |
| 221 void resetSkiaTextureBinding(); |
| 222 |
| 174 OwnPtr<SkPictureRecorder> m_recorder; | 223 OwnPtr<SkPictureRecorder> m_recorder; |
| 175 RefPtr<SkSurface> m_surface; | 224 RefPtr<SkSurface> m_surface; |
| 176 RefPtr<SkImage> m_hibernationImage; | 225 RefPtr<SkImage> m_hibernationImage; |
| 177 int m_initialSurfaceSaveCount; | 226 int m_initialSurfaceSaveCount; |
| 178 OwnPtr<WebExternalTextureLayer> m_layer; | 227 OwnPtr<WebExternalTextureLayer> m_layer; |
| 179 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; | 228 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; |
| 180 OwnPtr<SharedContextRateLimiter> m_rateLimiter; | 229 OwnPtr<SharedContextRateLimiter> m_rateLimiter; |
| 181 OwnPtr<Logger> m_logger; | 230 OwnPtr<Logger> m_logger; |
| 182 WeakPtrFactory<Canvas2DLayerBridge> m_weakPtrFactory; | 231 WeakPtrFactory<Canvas2DLayerBridge> m_weakPtrFactory; |
| 183 ImageBuffer* m_imageBuffer; | 232 ImageBuffer* m_imageBuffer; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 201 enum { | 250 enum { |
| 202 // We should normally not have more that two active mailboxes at a time, | 251 // We should normally not have more that two active mailboxes at a time, |
| 203 // but sometime we may have three due to the async nature of mailbox han
dling. | 252 // but sometime we may have three due to the async nature of mailbox han
dling. |
| 204 MaxActiveMailboxes = 3, | 253 MaxActiveMailboxes = 3, |
| 205 }; | 254 }; |
| 206 | 255 |
| 207 Deque<MailboxInfo, MaxActiveMailboxes> m_mailboxes; | 256 Deque<MailboxInfo, MaxActiveMailboxes> m_mailboxes; |
| 208 GLenum m_lastFilter; | 257 GLenum m_lastFilter; |
| 209 AccelerationMode m_accelerationMode; | 258 AccelerationMode m_accelerationMode; |
| 210 OpacityMode m_opacityMode; | 259 OpacityMode m_opacityMode; |
| 211 IntSize m_size; | 260 const IntSize m_size; |
| 212 int m_recordingPixelCount; | 261 int m_recordingPixelCount; |
| 262 |
| 263 #if USE_IOSURFACE_FOR_2D_CANVAS |
| 264 // Each element in this vector represents an IOSurface backed texture that |
| 265 // is ready to be reused. |
| 266 // Elements in this vector can safely be purged in low memory conditions. |
| 267 Vector<ImageInfo> m_imageInfoCache; |
| 268 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 213 }; | 269 }; |
| 214 | 270 |
| 215 } // namespace blink | 271 } // namespace blink |
| 216 | 272 |
| 217 #endif | 273 #endif |
| OLD | NEW |