summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/graphics/accelerated_static_bitmap_image.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/platform/graphics/accelerated_static_bitmap_image.h')
-rw-r--r--chromium/third_party/blink/renderer/platform/graphics/accelerated_static_bitmap_image.h180
1 files changed, 90 insertions, 90 deletions
diff --git a/chromium/third_party/blink/renderer/platform/graphics/accelerated_static_bitmap_image.h b/chromium/third_party/blink/renderer/platform/graphics/accelerated_static_bitmap_image.h
index f89408d112d..2b04e048281 100644
--- a/chromium/third_party/blink/renderer/platform/graphics/accelerated_static_bitmap_image.h
+++ b/chromium/third_party/blink/renderer/platform/graphics/accelerated_static_bitmap_image.h
@@ -10,12 +10,9 @@
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_checker.h"
-#include "third_party/blink/renderer/platform/graphics/mailbox_texture_holder.h"
-#include "third_party/blink/renderer/platform/graphics/skia_texture_holder.h"
#include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
-class GrContext;
struct SkImageInfo;
namespace viz {
@@ -30,29 +27,10 @@ class PLATFORM_EXPORT AcceleratedStaticBitmapImage final
public:
~AcceleratedStaticBitmapImage() override;
- // SkImage with a texture backing.
- // DO NOT USE. This is in the process of being removed. See crbug.com/962630.
- static scoped_refptr<AcceleratedStaticBitmapImage> CreateFromSkImage(
- sk_sp<SkImage>,
- base::WeakPtr<WebGraphicsContext3DProviderWrapper>);
-
- // Can specify the GrContext that created the texture backing. Ideally all
- // callers would use this option.
- // The |mailbox| is a name for the texture backing, allowing other contexts to
- // use the same backing.
- static scoped_refptr<AcceleratedStaticBitmapImage>
- CreateFromWebGLContextImage(
- const gpu::Mailbox&,
- const gpu::SyncToken&,
- unsigned texture_id,
- base::WeakPtr<WebGraphicsContext3DProviderWrapper>&&,
- IntSize mailbox_size,
- bool is_origin_top_left);
-
- // Creates an image wrapping a shared image mailbox. |release_callback| is a
- // callback to be invoked when this mailbox/texture can be safely destroyed.
- // It can be invoked on any thread. Note that it is assumed that the mailbox
- // can only be used for read operations, no writes are allowed.
+ // Creates an image wrapping a shared image mailbox.
+ //
+ // |sync_token| is the token that must be waited on before reading the
+ // contents of this mailbox.
//
// |shared_image_texture_id| is an optional texture bound to the shared image
// mailbox imported into the provided context. If provided the caller must
@@ -60,28 +38,42 @@ class PLATFORM_EXPORT AcceleratedStaticBitmapImage final
// and has a read lock on the shared image until the |release_callback| is
// invoked.
//
- // If the image is created on a different thread than |context_thread_id| then
- // the provided sync_token must be verified and no |shared_image_texture_id|
- // should be provided.
+ // |sk_image_info| provides the metadata associated with the backing.
+ //
+ // |texture_target| is the target that the texture should be bound to if the
+ // backing is used with GL.
+ //
+ // |is_origin_top_left| indicates whether the origin in texture space
+ // corresponds to the top-left content pixel.
+ //
+ // |context_provider| is the context that the mailbox was created with.
+ // |context_thread_ref| and |context_task_runner| refer to the thread the
+ // context is bound to. If the image is created on a different thread than
+ // |context_thread_ref| then the provided sync_token must be verified and no
+ // |shared_image_texture_id| should be provided.
+ //
+ // |release_callback| is a callback to be invoked when this mailbox can be
+ // safely destroyed. It is guaranteed to be invoked on the context thread.
+ //
+ // Note that it is assumed that the mailbox can only be used for read
+ // operations, no writes are allowed.
static scoped_refptr<AcceleratedStaticBitmapImage> CreateFromCanvasMailbox(
const gpu::Mailbox&,
const gpu::SyncToken&,
GLuint shared_image_texture_id,
const SkImageInfo& sk_image_info,
GLenum texture_target,
- base::WeakPtr<WebGraphicsContext3DProviderWrapper>,
- PlatformThreadId context_thread_id,
bool is_origin_top_left,
+ base::WeakPtr<WebGraphicsContext3DProviderWrapper>,
+ base::PlatformThreadRef context_thread_ref,
+ scoped_refptr<base::SingleThreadTaskRunner> context_task_runner,
std::unique_ptr<viz::SingleReleaseCallback> release_callback);
bool CurrentFrameKnownToBeOpaque() override;
IntSize Size() const override;
bool IsTextureBacked() const override { return true; }
- scoped_refptr<StaticBitmapImage> MakeAccelerated(
- base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_wrapper)
- override {
- return this;
- }
+ scoped_refptr<StaticBitmapImage> ConvertToColorSpace(sk_sp<SkColorSpace>,
+ SkColorType) override;
void Draw(cc::PaintCanvas*,
const cc::PaintFlags&,
@@ -105,82 +97,90 @@ class PLATFORM_EXPORT AcceleratedStaticBitmapImage final
bool unpack_flip_y,
const IntPoint& dest_point,
const IntRect& source_sub_rectangle) override;
-
- bool HasMailbox() const final { return !!mailbox_texture_holder_; }
- // To be called on sender thread before performing a transfer
+ // To be called on sender thread before performing a transfer to a different
+ // thread.
void Transfer() final;
- void EnsureMailbox(MailboxSyncMode, GLenum filter) final;
+ // Makes sure that the sync token associated with this mailbox is verified.
+ void EnsureSyncTokenVerified() final;
- const gpu::Mailbox& GetMailbox() const final {
- static const gpu::Mailbox mailbox;
- return mailbox_texture_holder_ ? mailbox_texture_holder_->GetMailbox()
- : mailbox;
- }
- const gpu::SyncToken& GetSyncToken() const final {
- static const gpu::SyncToken sync_token;
- return mailbox_texture_holder_ ? mailbox_texture_holder_->GetSyncToken()
- : sync_token;
+ // Updates the sync token that must be waited on before recycling or deleting
+ // the mailbox for this image. This must be set by callers using the mailbox
+ // externally to this class.
+ void UpdateSyncToken(const gpu::SyncToken& sync_token) final {
+ mailbox_ref_->set_sync_token(sync_token);
}
+ // Provides the mailbox backing for this image. The caller must wait on the
+ // sync token before accessing this mailbox.
+ gpu::MailboxHolder GetMailboxHolder() const final;
+ bool IsOriginTopLeft() const final { return is_origin_top_left_; }
+
PaintImage PaintImageForCurrentFrame() override;
private:
- AcceleratedStaticBitmapImage(
- sk_sp<SkImage>,
- base::WeakPtr<WebGraphicsContext3DProviderWrapper>&&);
- AcceleratedStaticBitmapImage(
- const gpu::Mailbox&,
- const gpu::SyncToken&,
- unsigned texture_id,
- base::WeakPtr<WebGraphicsContext3DProviderWrapper>&&,
- IntSize mailbox_size,
- bool is_origin_top_left);
+ class MailboxRef : public ThreadSafeRefCounted<MailboxRef> {
+ public:
+ MailboxRef(const gpu::SyncToken& sync_token,
+ base::PlatformThreadRef context_thread_ref,
+ scoped_refptr<base::SingleThreadTaskRunner> context_task_runner,
+ std::unique_ptr<viz::SingleReleaseCallback> release_callback);
+ ~MailboxRef();
+
+ bool is_cross_thread() const {
+ return base::PlatformThread::CurrentRef() != context_thread_ref_;
+ }
+ void set_sync_token(gpu::SyncToken token) { sync_token_ = token; }
+ const gpu::SyncToken& GetOrCreateSyncToken(
+ base::WeakPtr<WebGraphicsContext3DProviderWrapper>);
+ bool verified_flush() { return sync_token_.verified_flush(); }
+
+ private:
+ gpu::SyncToken sync_token_;
+ const base::PlatformThreadRef context_thread_ref_;
+ const scoped_refptr<base::SingleThreadTaskRunner> context_task_runner_;
+ std::unique_ptr<viz::SingleReleaseCallback> release_callback_;
+ };
+
+ struct ReleaseContext {
+ scoped_refptr<MailboxRef> mailbox_ref;
+ GLuint texture_id = 0u;
+ base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_provider_wrapper;
+ };
+
+ static void ReleaseTexture(void* ctx);
+
AcceleratedStaticBitmapImage(
const gpu::Mailbox&,
const gpu::SyncToken&,
GLuint shared_image_texture_id,
const SkImageInfo& sk_image_info,
GLenum texture_target,
- base::WeakPtr<WebGraphicsContext3DProviderWrapper>&&,
- PlatformThreadId context_thread_id,
bool is_origin_top_left,
+ const ImageOrientation& orientation,
+ base::WeakPtr<WebGraphicsContext3DProviderWrapper>,
+ base::PlatformThreadRef context_thread_ref,
+ scoped_refptr<base::SingleThreadTaskRunner> context_task_runner,
std::unique_ptr<viz::SingleReleaseCallback> release_callback);
void CreateImageFromMailboxIfNeeded();
- void WaitSyncTokenIfNeeded();
- void RetainOriginalSkImage();
-
- // TODO(khushalsagar): Its unclear what to use here for calls checking IsValid
- // or querying the ContextProvider for the image. This can differ in the 2,
- // for instance if the image was transferred between threads.
- const TextureHolder* texture_holder() const {
- if (skia_texture_holder_)
- return skia_texture_holder_.get();
- return mailbox_texture_holder_.get();
- }
+ void InitializeSkImage(GLuint shared_image_texture_id);
- scoped_refptr<TextureHolder::MailboxRef> mailbox_ref_;
+ const gpu::Mailbox mailbox_;
+ const SkImageInfo sk_image_info_;
+ const GLenum texture_target_;
+ const bool is_origin_top_left_;
- // The image is created with one of the texture holders below while the other
- // one is created lazily if needed and then persisted for the lifetime of the
- // image on a particular thread.
- // When Transfer is called, the image is detached from its current thread to
- // allow it to be used on a different thread. We create(if needed) and cache
- // the mailbox in this case, so the texture can be used with a different
- // context. The skia texture holder is released since the mailbox needs to be
- // imported into the GrContext on the new thread.
- std::unique_ptr<SkiaTextureHolder> skia_texture_holder_;
- std::unique_ptr<MailboxTextureHolder> mailbox_texture_holder_;
+ base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_provider_wrapper_;
+ scoped_refptr<MailboxRef> mailbox_ref_;
- THREAD_CHECKER(thread_checker_);
- PaintImage::ContentId paint_image_content_id_;
-
- // For RetainOriginalSkImageForCopyOnWrite()
- sk_sp<SkImage> original_skia_image_;
- scoped_refptr<base::SingleThreadTaskRunner> original_skia_image_task_runner_;
+ // The context this SkImage is bound to.
base::WeakPtr<WebGraphicsContext3DProviderWrapper>
- original_skia_image_context_provider_wrapper_;
+ skia_context_provider_wrapper_;
+ sk_sp<SkImage> sk_image_;
+
+ PaintImage::ContentId paint_image_content_id_;
+ THREAD_CHECKER(thread_checker_);
};
} // namespace blink