OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 SkiaTextureHolder_h |
| 6 #define SkiaTextureHolder_h |
| 7 |
| 8 #include "platform/PlatformExport.h" |
| 9 #include "platform/graphics/TextureHolder.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 class PLATFORM_EXPORT SkiaTextureHolder final : public TextureHolder { |
| 14 public: |
| 15 ~SkiaTextureHolder() override; |
| 16 |
| 17 bool isSkiaTextureHolder() final { return true; } |
| 18 bool isMailboxTextureHolder() final { return false; } |
| 19 unsigned sharedContextId() final; |
| 20 IntSize size() const final { |
| 21 return IntSize(m_image->width(), m_image->height()); |
| 22 } |
| 23 bool currentFrameKnownToBeOpaque(Image::MetadataMode) final { |
| 24 return m_image->isOpaque(); |
| 25 } |
| 26 WebThread* imageThread() final { return m_imageThreadDoNotCall; } |
| 27 |
| 28 sk_sp<SkImage> skImage() final { return m_image; } |
| 29 void setSharedContextId(unsigned contextId) final { |
| 30 m_sharedContextId = contextId; |
| 31 } |
| 32 void setImageThread(WebThread* thread) { m_imageThreadDoNotCall = thread; } |
| 33 void setImageThreadTaskRunner( |
| 34 std::unique_ptr<WebTaskRunner> taskRunner) final { |
| 35 m_imageThreadTaskRunner = std::move(taskRunner); |
| 36 } |
| 37 |
| 38 // When creating a AcceleratedStaticBitmap from a texture-backed SkImage, this |
| 39 // function will be called to create a TextureHolder object. |
| 40 SkiaTextureHolder(sk_sp<SkImage>); |
| 41 // This function consumes the mailbox in the input parameter and turn it into |
| 42 // a texture-backed SkImage. |
| 43 SkiaTextureHolder(std::unique_ptr<TextureHolder>); |
| 44 |
| 45 private: |
| 46 void releaseImageThreadSafe(); |
| 47 |
| 48 // The m_image should always be texture-backed |
| 49 sk_sp<SkImage> m_image; |
| 50 // Id of the shared context where m_image was created |
| 51 unsigned m_sharedContextId = 0; |
| 52 // Thread that |m_image| belongs to. Set to null when |m_image| belongs to the |
| 53 // same thread as the AcceleratedStaticBitmapImage. Should only be non-null |
| 54 // after a transfer. |
| 55 // VERY IMPORTANT: Used for pointer comparisons only. DO NOT call any of its |
| 56 // API because that would potentially CRASH. |
| 57 WebThread* m_imageThreadDoNotCall; |
| 58 // Keep a clone of the WebTaskRunner for m_imageThread. This is to handle |
| 59 // the case where |m_imageThread| goes out of scope, and we still need to use |
| 60 // the WebTaskRunner for the |m_imageThread|. |
| 61 std::unique_ptr<WebTaskRunner> m_imageThreadTaskRunner; |
| 62 }; |
| 63 |
| 64 } // namespace blink |
| 65 |
| 66 #endif // SkiaTextureHolder_h |
OLD | NEW |