• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 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 
8 #include "include/core/SkImageGenerator.h"
9 
10 #include "include/core/SkImage.h"
11 #include "src/core/SkNextID.h"
12 
SkImageGenerator(const SkImageInfo & info,uint32_t uniqueID)13 SkImageGenerator::SkImageGenerator(const SkImageInfo& info, uint32_t uniqueID)
14     : fInfo(info)
15     , fUniqueID(kNeedNewImageUniqueID == uniqueID ? SkNextID::ImageID() : uniqueID)
16 {}
17 
getPixels(const SkImageInfo & info,void * pixels,size_t rowBytes)18 bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) {
19     if (kUnknown_SkColorType == info.colorType()) {
20         return false;
21     }
22     if (nullptr == pixels) {
23         return false;
24     }
25     if (rowBytes < info.minRowBytes()) {
26         return false;
27     }
28 
29     Options defaultOpts;
30     return this->onGetPixels(info, pixels, rowBytes, defaultOpts);
31 }
32 
queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes & supportedDataTypes,SkYUVAPixmapInfo * yuvaPixmapInfo) const33 bool SkImageGenerator::queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes& supportedDataTypes,
34                                      SkYUVAPixmapInfo* yuvaPixmapInfo) const {
35     SkASSERT(yuvaPixmapInfo);
36 
37     return this->onQueryYUVAInfo(supportedDataTypes, yuvaPixmapInfo) &&
38            yuvaPixmapInfo->isSupported(supportedDataTypes);
39 }
40 
getYUVAPlanes(const SkYUVAPixmaps & yuvaPixmaps)41 bool SkImageGenerator::getYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps) {
42     return this->onGetYUVAPlanes(yuvaPixmaps);
43 }
44 
45 #if SK_SUPPORT_GPU
46 #include "src/gpu/GrSurfaceProxyView.h"
47 
generateTexture(GrRecordingContext * ctx,const SkImageInfo & info,const SkIPoint & origin,GrMipmapped mipMapped,GrImageTexGenPolicy texGenPolicy)48 GrSurfaceProxyView SkImageGenerator::generateTexture(GrRecordingContext* ctx,
49                                                      const SkImageInfo& info,
50                                                      const SkIPoint& origin,
51                                                      GrMipmapped mipMapped,
52                                                      GrImageTexGenPolicy texGenPolicy) {
53     SkIRect srcRect = SkIRect::MakeXYWH(origin.x(), origin.y(), info.width(), info.height());
54     if (!SkIRect::MakeWH(fInfo.width(), fInfo.height()).contains(srcRect)) {
55         return {};
56     }
57     return this->onGenerateTexture(ctx, info, origin, mipMapped, texGenPolicy);
58 }
59 
onGenerateTexture(GrRecordingContext *,const SkImageInfo &,const SkIPoint &,GrMipmapped,GrImageTexGenPolicy)60 GrSurfaceProxyView SkImageGenerator::onGenerateTexture(GrRecordingContext*,
61                                                        const SkImageInfo&,
62                                                        const SkIPoint&,
63                                                        GrMipmapped,
64                                                        GrImageTexGenPolicy) {
65     return {};
66 }
67 #endif
68 
69 ///////////////////////////////////////////////////////////////////////////////////////////////////
70 
71 #include "include/core/SkBitmap.h"
72 #include "src/codec/SkColorTable.h"
73 
74 #include "include/core/SkGraphics.h"
75 
76 static SkGraphics::ImageGeneratorFromEncodedDataFactory gFactory;
77 
78 SkGraphics::ImageGeneratorFromEncodedDataFactory
SetImageGeneratorFromEncodedDataFactory(ImageGeneratorFromEncodedDataFactory factory)79 SkGraphics::SetImageGeneratorFromEncodedDataFactory(ImageGeneratorFromEncodedDataFactory factory)
80 {
81     ImageGeneratorFromEncodedDataFactory prev = gFactory;
82     gFactory = factory;
83     return prev;
84 }
85 
MakeFromEncoded(sk_sp<SkData> data)86 std::unique_ptr<SkImageGenerator> SkImageGenerator::MakeFromEncoded(sk_sp<SkData> data) {
87     if (!data) {
88         return nullptr;
89     }
90     if (gFactory) {
91         if (std::unique_ptr<SkImageGenerator> generator = gFactory(data)) {
92             return generator;
93         }
94     }
95     return SkImageGenerator::MakeFromEncodedImpl(std::move(data));
96 }
97