1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56

cc / paint / texture_backing.h [blame]

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_PAINT_TEXTURE_BACKING_H_
#define CC_PAINT_TEXTURE_BACKING_H_

#include "cc/paint/paint_export.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkImageInfo.h"

namespace gpu {
struct Mailbox;
}  // namespace gpu

namespace cc {

// Used for storing mailboxes in a PaintImage.
// This class must be created, used and destroyed on the same thread.
class CC_PAINT_EXPORT TextureBacking : public SkRefCnt {
 public:
  TextureBacking() = default;
  TextureBacking(const TextureBacking&) = delete;
  ~TextureBacking() override = default;

  TextureBacking& operator=(const TextureBacking&) = delete;

  // Returns the metadata for the associated texture.
  virtual const SkImageInfo& GetSkImageInfo() = 0;

  // Returns the shared image mailbox backing for this texture.
  virtual gpu::Mailbox GetMailbox() const = 0;

  // Returns a texture backed SkImage. Only supported if the context used to
  // create this image has a valid GrContext.
  virtual sk_sp<SkImage> GetAcceleratedSkImage() = 0;

  // Gets SkImage via a readback from GPU memory. Use this when actual SkImage
  // pixel data is required in software.
  virtual sk_sp<SkImage> GetSkImageViaReadback() = 0;

  // Read texture's pixels into caller owned |dstPixels|.
  virtual bool readPixels(const SkImageInfo& dst_info,
                          void* dst_pixels,
                          size_t dst_row_bytes,
                          int src_x,
                          int src_y) = 0;

  // Force a flush of any pending skia work. Only supported if this
  // TextureBacking wraps an SkImage.
  virtual void FlushPendingSkiaOps() = 0;
};

}  // namespace cc

#endif  // CC_PAINT_TEXTURE_BACKING_H_