Flutter Engine
The Flutter Engine
SkKeyedImage.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
12#include "include/core/SkRect.h"
15
16#include <utility>
17
19 if (!image) {
20 return {{0, 0, 0, 0}, 0};
21 }
22 if (const SkBitmap* bm = as_IB(image)->onPeekBitmap()) {
23 SkIPoint o = bm->pixelRefOrigin();
24 return {image->bounds().makeOffset(o), bm->getGenerationID()};
25 }
26 return {image->bounds(), image->uniqueID()};
27}
28
30 fKey = SkBitmapKeyFromImage(fImage.get());
31}
32
33SkKeyedImage::SkKeyedImage(const SkBitmap& bm) : fImage(bm.asImage()) {
34 if (fImage) {
35 fKey = {bm.getSubset(), bm.getGenerationID()};
36 }
37}
38
40 SkKeyedImage img;
41 if (fImage && subset.intersect(fImage->bounds())) {
42 img.fImage = fImage->makeSubset(nullptr, subset);
43 if (img.fImage) {
44 img.fKey = {subset.makeOffset(fKey.fSubset.topLeft()), fKey.fID};
45 }
46 }
47 return img;
48}
49
51 sk_sp<SkImage> image = std::move(fImage);
52 SkASSERT(nullptr == fImage);
53 fKey = {{0, 0, 0, 0}, 0};
54 return image;
55}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkImage_Base * as_IB(SkImage *image)
Definition: SkImage_Base.h:201
SkBitmapKey SkBitmapKeyFromImage(const SkImage *image)
SkIRect getSubset() const
Definition: SkBitmap.h:394
uint32_t getGenerationID() const
Definition: SkBitmap.cpp:361
uint32_t uniqueID() const
Definition: SkImage.h:311
SkIRect bounds() const
Definition: SkImage.h:303
virtual sk_sp< SkImage > makeSubset(GrDirectContext *direct, const SkIRect &subset) const =0
const sk_sp< SkImage > & image() const
Definition: SkKeyedImage.h:35
SkKeyedImage subset(SkIRect subset) const
sk_sp< SkImage > release()
T * get() const
Definition: SkRefCnt.h:303
sk_sp< const SkImage > image
Definition: SkRecords.h:269
Definition: ref_ptr.h:256
uint32_t fID
Definition: SkBitmapKey.h:16
SkIRect fSubset
Definition: SkBitmapKey.h:15
Definition: SkRect.h:32
constexpr SkIRect makeOffset(int32_t dx, int32_t dy) const
Definition: SkRect.h:300
constexpr SkIPoint topLeft() const
Definition: SkRect.h:151