| 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 |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef Canvas2DLayerBridge_h | 26 #ifndef Canvas2DLayerBridge_h |
| 27 #define Canvas2DLayerBridge_h | 27 #define Canvas2DLayerBridge_h |
| 28 | 28 |
| 29 #include "cc/layers/texture_layer_client.h" |
| 30 #include "cc/resources/texture_mailbox.h" |
| 29 #include "platform/PlatformExport.h" | 31 #include "platform/PlatformExport.h" |
| 30 #include "platform/geometry/IntSize.h" | 32 #include "platform/geometry/IntSize.h" |
| 31 #include "platform/graphics/ImageBufferSurface.h" | 33 #include "platform/graphics/ImageBufferSurface.h" |
| 32 #include "public/platform/WebExternalTextureLayer.h" | 34 #include "public/platform/WebExternalTextureLayer.h" |
| 33 #include "public/platform/WebExternalTextureLayerClient.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/SkSurface.h" | 37 #include "third_party/skia/include/core/SkSurface.h" |
| 38 #include "wtf/Allocator.h" | 38 #include "wtf/Allocator.h" |
| 39 #include "wtf/Deque.h" | 39 #include "wtf/Deque.h" |
| 40 #include "wtf/RefCounted.h" | 40 #include "wtf/RefCounted.h" |
| 41 #include "wtf/RefPtr.h" | 41 #include "wtf/RefPtr.h" |
| 42 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
| 43 #include "wtf/WeakPtr.h" | 43 #include "wtf/WeakPtr.h" |
| 44 #include <memory> | 44 #include <memory> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 69 // IOSurfaces are a primitive only present on OS X. | 69 // IOSurfaces are a primitive only present on OS X. |
| 70 #define USE_IOSURFACE_FOR_2D_CANVAS 1 | 70 #define USE_IOSURFACE_FOR_2D_CANVAS 1 |
| 71 #else | 71 #else |
| 72 #define CANVAS2D_HIBERNATION_ENABLED 1 | 72 #define CANVAS2D_HIBERNATION_ENABLED 1 |
| 73 #define USE_IOSURFACE_FOR_2D_CANVAS 0 | 73 #define USE_IOSURFACE_FOR_2D_CANVAS 0 |
| 74 #endif | 74 #endif |
| 75 | 75 |
| 76 // TODO: Fix background rendering and remove this workaround. crbug.com/600386 | 76 // TODO: Fix background rendering and remove this workaround. crbug.com/600386 |
| 77 #define CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU 0 | 77 #define CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU 0 |
| 78 | 78 |
| 79 class PLATFORM_EXPORT Canvas2DLayerBridge : public WebExternalTextureLayerClient
, public WebThread::TaskObserver, public RefCounted<Canvas2DLayerBridge> { | 79 class PLATFORM_EXPORT Canvas2DLayerBridge : public NON_EXPORTED_BASE(cc::Texture
LayerClient), public WebThread::TaskObserver, public RefCounted<Canvas2DLayerBri
dge> { |
| 80 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); | 80 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); |
| 81 public: | 81 public: |
| 82 enum AccelerationMode { | 82 enum AccelerationMode { |
| 83 DisableAcceleration, | 83 DisableAcceleration, |
| 84 EnableAcceleration, | 84 EnableAcceleration, |
| 85 ForceAccelerationForTesting, | 85 ForceAccelerationForTesting, |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 static PassRefPtr<Canvas2DLayerBridge> create(const IntSize&, int msaaSample
Count, OpacityMode, AccelerationMode); | 88 static PassRefPtr<Canvas2DLayerBridge> create(const IntSize&, int msaaSample
Count, OpacityMode, AccelerationMode); |
| 89 | 89 |
| 90 ~Canvas2DLayerBridge() override; | 90 ~Canvas2DLayerBridge() override; |
| 91 | 91 |
| 92 // WebExternalTextureLayerClient implementation. | 92 // cc::TextureLayerClient implementation. |
| 93 bool prepareMailbox(WebExternalTextureMailbox*, WebExternalBitmap*) override
; | 93 bool PrepareTextureMailbox( |
| 94 void mailboxReleased(const WebExternalTextureMailbox&, bool lostResource) ov
erride; | 94 cc::TextureMailbox* outMailbox, |
| 95 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback, |
| 96 bool useSharedMemory) override; |
| 97 |
| 98 // Callback for mailboxes given to the compositor from PrepareTextureMailbox
. |
| 99 void mailboxReleased(const gpu::Mailbox&, const gpu::SyncToken&, |
| 100 bool lostResource); |
| 95 | 101 |
| 96 // ImageBufferSurface implementation | 102 // ImageBufferSurface implementation |
| 97 void finalizeFrame(const FloatRect &dirtyRect); | 103 void finalizeFrame(const FloatRect &dirtyRect); |
| 98 void willWritePixels(); | 104 void willWritePixels(); |
| 99 void willOverwriteAllPixels(); | 105 void willOverwriteAllPixels(); |
| 100 void willOverwriteCanvas(); | 106 void willOverwriteCanvas(); |
| 101 SkCanvas* canvas(); | 107 SkCanvas* canvas(); |
| 102 void disableDeferral(DisableDeferralReason); | 108 void disableDeferral(DisableDeferralReason); |
| 103 bool checkSurfaceValid(); | 109 bool checkSurfaceValid(); |
| 104 bool restoreSurface(); | 110 bool restoreSurface(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // The id of the CHROMIUM image. | 168 // The id of the CHROMIUM image. |
| 163 GLuint m_imageId = 0; | 169 GLuint m_imageId = 0; |
| 164 | 170 |
| 165 // The id of the texture bound to the CHROMIUM image. | 171 // The id of the texture bound to the CHROMIUM image. |
| 166 GLuint m_textureId = 0; | 172 GLuint m_textureId = 0; |
| 167 }; | 173 }; |
| 168 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 174 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 169 | 175 |
| 170 struct MailboxInfo { | 176 struct MailboxInfo { |
| 171 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 177 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 172 WebExternalTextureMailbox m_mailbox; | 178 gpu::Mailbox m_mailbox; |
| 173 RefPtr<SkImage> m_image; | 179 RefPtr<SkImage> m_image; |
| 174 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; | 180 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; |
| 175 | 181 |
| 176 #if USE_IOSURFACE_FOR_2D_CANVAS | 182 #if USE_IOSURFACE_FOR_2D_CANVAS |
| 177 // If this mailbox wraps an IOSurface-backed texture, the ids of the | 183 // If this mailbox wraps an IOSurface-backed texture, the ids of the |
| 178 // CHROMIUM image and the texture. | 184 // CHROMIUM image and the texture. |
| 179 ImageInfo m_imageInfo; | 185 ImageInfo m_imageInfo; |
| 180 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 186 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 181 | 187 |
| 182 MailboxInfo(const MailboxInfo&); | 188 MailboxInfo(const MailboxInfo&); |
| 183 MailboxInfo() {} | 189 MailboxInfo(); |
| 184 }; | 190 }; |
| 185 | 191 |
| 186 Canvas2DLayerBridge(std::unique_ptr<WebGraphicsContext3DProvider>, const Int
Size&, int msaaSampleCount, OpacityMode, AccelerationMode); | 192 Canvas2DLayerBridge(std::unique_ptr<WebGraphicsContext3DProvider>, const Int
Size&, int msaaSampleCount, OpacityMode, AccelerationMode); |
| 187 gpu::gles2::GLES2Interface* contextGL(); | 193 gpu::gles2::GLES2Interface* contextGL(); |
| 188 void startRecording(); | 194 void startRecording(); |
| 189 void skipQueuedDrawCommands(); | 195 void skipQueuedDrawCommands(); |
| 190 void flushRecordingOnly(); | 196 void flushRecordingOnly(); |
| 191 void unregisterTaskObserver(); | 197 void unregisterTaskObserver(); |
| 192 void reportSurfaceCreationFailure(); | 198 void reportSurfaceCreationFailure(); |
| 193 | 199 |
| 194 // WebThread::TaskOberver implementation | 200 // WebThread::TaskOberver implementation |
| 195 void willProcessTask() override; | 201 void willProcessTask() override; |
| 196 void didProcessTask() override; | 202 void didProcessTask() override; |
| 197 | 203 |
| 198 SkSurface* getOrCreateSurface(AccelerationHint = PreferAcceleration); | 204 SkSurface* getOrCreateSurface(AccelerationHint = PreferAcceleration); |
| 199 bool shouldAccelerate(AccelerationHint) const; | 205 bool shouldAccelerate(AccelerationHint) const; |
| 200 | 206 |
| 201 // Returns the GL filter associated with |m_filterQuality|. | 207 // Returns the GL filter associated with |m_filterQuality|. |
| 202 GLenum getGLFilter(); | 208 GLenum getGLFilter(); |
| 203 | 209 |
| 204 #if USE_IOSURFACE_FOR_2D_CANVAS | 210 #if USE_IOSURFACE_FOR_2D_CANVAS |
| 205 // Creates an IOSurface-backed texture. Copies |image| into the texture. | 211 // Creates an IOSurface-backed texture. Copies |image| into the texture. |
| 206 // Prepares a mailbox from the texture. The caller must have created a new | 212 // Prepares a mailbox from the texture. The caller must have created a new |
| 207 // MailboxInfo, and prepended it to |m_mailboxs|. Returns whether the | 213 // MailboxInfo, and prepended it to |m_mailboxs|. Returns whether the |
| 208 // mailbox was successfully prepared. |mailbox| is an out parameter only | 214 // mailbox was successfully prepared. |mailbox| is an out parameter only |
| 209 // populated on success. | 215 // populated on success. |
| 210 bool prepareIOSurfaceMailboxFromImage(SkImage*, WebExternalTextureMailbox*); | 216 bool prepareIOSurfaceMailboxFromImage(SkImage*, cc::TextureMailbox*); |
| 211 | 217 |
| 212 // Creates an IOSurface-backed texture. Returns an ImageInfo, which is empty | 218 // Creates an IOSurface-backed texture. Returns an ImageInfo, which is empty |
| 213 // on failure. The caller takes ownership of both the texture and the image. | 219 // on failure. The caller takes ownership of both the texture and the image. |
| 214 ImageInfo createIOSurfaceBackedTexture(); | 220 ImageInfo createIOSurfaceBackedTexture(); |
| 215 | 221 |
| 216 // Releases all resources associated with a CHROMIUM image. | 222 // Releases all resources associated with a CHROMIUM image. |
| 217 void deleteCHROMIUMImage(ImageInfo); | 223 void deleteCHROMIUMImage(ImageInfo); |
| 218 | 224 |
| 219 // Releases all resources in the CHROMIUM image cache. | 225 // Releases all resources in the CHROMIUM image cache. |
| 220 void clearCHROMIUMImageCache(); | 226 void clearCHROMIUMImageCache(); |
| 221 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 227 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 222 | 228 |
| 223 // Prepends a new MailboxInfo object to |m_mailboxes|. | 229 // Prepends a new MailboxInfo object to |m_mailboxes|. |
| 224 void createMailboxInfo(); | 230 void createMailboxInfo(); |
| 225 | 231 |
| 226 // Returns whether the mailbox was successfully prepared from the SkImage. | 232 // Returns whether the mailbox was successfully prepared from the SkImage. |
| 227 // The mailbox is an out parameter only populated on success. | 233 // The mailbox is an out parameter only populated on success. |
| 228 bool prepareMailboxFromImage(PassRefPtr<SkImage>, WebExternalTextureMailbox*
); | 234 bool prepareMailboxFromImage(PassRefPtr<SkImage>, cc::TextureMailbox*); |
| 229 | 235 |
| 230 // Resets Skia's texture bindings. This method should be called after | 236 // Resets Skia's texture bindings. This method should be called after |
| 231 // changing texture bindings. | 237 // changing texture bindings. |
| 232 void resetSkiaTextureBinding(); | 238 void resetSkiaTextureBinding(); |
| 233 | 239 |
| 234 std::unique_ptr<SkPictureRecorder> m_recorder; | 240 std::unique_ptr<SkPictureRecorder> m_recorder; |
| 235 RefPtr<SkSurface> m_surface; | 241 RefPtr<SkSurface> m_surface; |
| 236 RefPtr<SkImage> m_hibernationImage; | 242 RefPtr<SkImage> m_hibernationImage; |
| 237 int m_initialSurfaceSaveCount; | 243 int m_initialSurfaceSaveCount; |
| 238 std::unique_ptr<WebExternalTextureLayer> m_layer; | 244 std::unique_ptr<WebExternalTextureLayer> m_layer; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // Each element in this vector represents an IOSurface backed texture that | 283 // Each element in this vector represents an IOSurface backed texture that |
| 278 // is ready to be reused. | 284 // is ready to be reused. |
| 279 // Elements in this vector can safely be purged in low memory conditions. | 285 // Elements in this vector can safely be purged in low memory conditions. |
| 280 Vector<ImageInfo> m_imageInfoCache; | 286 Vector<ImageInfo> m_imageInfoCache; |
| 281 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 287 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 282 }; | 288 }; |
| 283 | 289 |
| 284 } // namespace blink | 290 } // namespace blink |
| 285 | 291 |
| 286 #endif | 292 #endif |
| OLD | NEW |