Esempio n. 1
0
    bool getBitmapDeprecated(SkBitmap* result) const override {
        const SkImageInfo info = GrMakeInfoFromTexture(fTexture,
                                                       this->width(), this->height(),
                                                       this->isOpaque());
        if (!result->setInfo(info)) {
            return false;
        }

        const SkImageInfo prInfo = info.makeWH(fTexture->width(), fTexture->height());

        SkAutoTUnref<SkGrPixelRef> pixelRef(new SkGrPixelRef(prInfo, fTexture));
        result->setPixelRef(pixelRef, this->subset().fLeft, this->subset().fTop);
        return true;
    }
Esempio n. 2
0
TEST(DragImageTest, InvalidRotatedBitmapImage) {
  // This test is mostly useful with MSAN builds, which can actually detect
  // the use of uninitialized memory.

  // Create a BitmapImage which will fail to produce pixels, and hence not
  // draw.
  SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
  sk_sp<SkPixelRef> pixelRef(new InvalidPixelRef(info));
  SkBitmap invalidBitmap;
  invalidBitmap.setInfo(info);
  invalidBitmap.setPixelRef(pixelRef.get());
  RefPtr<BitmapImage> image = BitmapImage::createWithOrientationForTesting(
      invalidBitmap, OriginRightTop);

  // Create a DragImage from it. In MSAN builds, this will cause a failure if
  // the pixel memory is not initialized, if we have to respect non-default
  // orientation.
  std::unique_ptr<DragImage> dragImage =
      DragImage::create(image.get(), RespectImageOrientation);

  // With an invalid pixel ref, BitmapImage should have no backing SkImage =>
  // we don't allocate a DragImage.
  ASSERT_FALSE(dragImage);
}
Esempio n. 3
0
DEF_TEST(PixelRef_GenIDChange, r) {
    SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);

    SkAutoTUnref<SkPixelRef> pixelRef(SkMallocPixelRef::NewAllocate(info, 0, NULL));

    // Register a listener.
    int count = 0;
    pixelRef->addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count)));
    REPORTER_ASSERT(r, 0 == count);

    // No one has looked at our pixelRef's generation ID, so invalidating it doesn't make sense.
    // (An SkPixelRef tree falls in the forest but there's nobody around to hear it.  Do we care?)
    pixelRef->notifyPixelsChanged();
    REPORTER_ASSERT(r, 0 == count);

    // Force the generation ID to be calculated.
    REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID());

    // Our listener was dropped in the first call to notifyPixelsChanged().  This is a no-op.
    pixelRef->notifyPixelsChanged();
    REPORTER_ASSERT(r, 0 == count);

    // Force the generation ID to be recalculated, then add a listener.
    REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID());
    pixelRef->addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count)));
    pixelRef->notifyPixelsChanged();
    REPORTER_ASSERT(r, 1 == count);

    // Quick check that NULL is safe.
    REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID());
    pixelRef->addGenIDChangeListener(NULL);
    pixelRef->notifyPixelsChanged();

    test_install(r);
    test_dont_leak_install(r);
}
Esempio n. 4
0
int main() {

  edm::ProductID pid;

  typedef edm::Ref<edmNew::DetSetVector<SiPixelCluster>,SiPixelCluster > ClusterPixelRef;
  typedef edm::Ref<edmNew::DetSetVector<SiStripCluster>,SiStripCluster > ClusterRef;
  typedef edm::Ref< edm::LazyGetter<SiStripCluster>, SiStripCluster, edm::FindValue<SiStripCluster> >  ClusterRegionalRef;

  ClusterPixelRef pixelRef(pid,nullptr, 2,nullptr);
  ClusterRef stripRef(pid,nullptr, 2,nullptr);
  ClusterRegionalRef regionalRef(pid,nullptr, 2,nullptr);

  OmniClusterRef invalid;
  OmniClusterRef opixel(pixelRef);
  OmniClusterRef ostrip(stripRef);
  OmniClusterRef oregional(regionalRef);

  assert(invalid.index()> (1<<16));
  assert(opixel.index()==2);
  assert(ostrip.index()==2);
  assert(oregional.index()==2);

  assert(!invalid.isValid());
  assert(invalid.isPixel());  // empty looks as pixel!
  assert(!invalid.isStrip());
  assert(!invalid.isRegional());

  assert(opixel.isValid());
  assert(opixel.isPixel());
  assert(!opixel.isStrip());
  assert(!opixel.isRegional());
  assert(opixel.cluster_strip().isNull());
  assert(opixel.cluster_pixel().isNonnull());
  assert(opixel.cluster_regional().isNull());

  assert(ostrip.isValid());
  assert(!ostrip.isPixel());
  assert(ostrip.isStrip());
  assert(!ostrip.isRegional());
  assert(ostrip.cluster_strip().isNonnull());
  assert(ostrip.cluster_pixel().isNull());
  assert(ostrip.cluster_regional().isNull());


  assert(oregional.isValid());
  assert(!oregional.isPixel());
  assert(oregional.isStrip());
  assert(oregional.isRegional());
  assert(oregional.cluster_strip().isNull());
  assert(oregional.cluster_pixel().isNull());
  assert(oregional.cluster_regional().isNonnull());

  testForInvalid(invalid);
  {
    OmniClusterRef invalid{ClusterPixelRef()};
    testForInvalid(invalid);
  }
  {
    OmniClusterRef invalid{ClusterRef()};
    testForInvalid(invalid);
  }
  {
    OmniClusterRef invalid{ClusterRegionalRef()};
    testForInvalid(invalid);
  }

}