Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: src/codec/SkAndroidCodec.cpp

Issue 1406223002: Create an SkAndroidCodec API separate from SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Refactored some test code in DMSrcSink.cpp Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 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 "SkAndroidCodec.h"
9 #include "SkCodec.h"
10 #include "SkCodecPriv.h"
11 #include "SkSampledCodec.h"
12 #include "SkWebpAdapterCodec.h"
13
14 static bool is_valid_sample_size(int sampleSize) {
15 // FIXME: As Leon has mentioned elsewhere, surely there is also a maximum sa mpleSize?
16 return sampleSize > 0;
17 }
18
19 SkAndroidCodec::SkAndroidCodec(const SkImageInfo& info)
20 : fInfo(info)
21 {}
22
23 SkAndroidCodec* SkAndroidCodec::NewFromStream(SkStream* stream) {
24 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream));
25 if (nullptr == codec) {
26 return nullptr;
27 }
28
29 switch (codec->getEncodedFormat()) {
30 case kWEBP_SkEncodedFormat:
31 return new SkWebpAdapterCodec((SkWebpCodec*) codec.detach());
32 case kPNG_SkEncodedFormat:
33 case kJPEG_SkEncodedFormat:
34 return new SkSampledCodec(codec.detach());
35 default:
36 // FIXME: SkSampledCodec is temporarily disabled for other formats
37 // while focusing on the formats that are supported by
38 // BitmapRegionDecoder.
39 return nullptr;
40 }
41 }
42
43 SkAndroidCodec* SkAndroidCodec::NewFromData(SkData* data) {
44 if (!data) {
45 return nullptr;
46 }
47
48 return NewFromStream(new SkMemoryStream(data));
49 }
50
51 SkISize SkAndroidCodec::getSampledDimensions(int sampleSize) const {
52 // Android makes zero the default sample size and treats it as if the
53 // sample size is one.
54 if (0 == sampleSize) {
55 sampleSize = 1;
56 }
57
58 if (!is_valid_sample_size(sampleSize)) {
59 return SkISize::Make(0, 0);
60 }
61
62 return this->onGetSampledDimensions(sampleSize);
63 }
64
65 bool SkAndroidCodec::getSupportedSubset(SkIRect* desiredSubset) const {
66 if (!desiredSubset || !is_valid_subset(*desiredSubset, fInfo.dimensions())) {
67 return false;
68 }
69
70 return this->onGetSupportedSubset(desiredSubset);
71 }
72
73 SkISize SkAndroidCodec::getSampledSubsetDimensions(int sampleSize, const SkIRect & subset) const {
74 // Android makes zero the default sample size and treats it as if the
75 // sample size is one.
76 if (0 == sampleSize) {
77 sampleSize = 1;
78 }
79
80 if (!is_valid_sample_size(sampleSize)) {
81 return SkISize::Make(0, 0);
82 }
83
84 // We require that the input subset is a subset that is supported by SkAndro idCodec.
85 // We test this by calling getSupportedSubset() and verifying that no modifi cations
86 // are made to the subset.
87 SkIRect copySubset = subset;
88 if (!this->getSupportedSubset(&copySubset) || copySubset != subset) {
89 return SkISize::Make(0, 0);
90 }
91
92 // If the subset is the entire image, for consistency, use onGetSampledDimen sions().
93 if (fInfo.dimensions() == subset.size()) {
94 return onGetSampledDimensions(sampleSize);
95 }
96
97 return SkISize::Make(get_scaled_dimension(subset.width(), sampleSize),
98 get_scaled_dimension(subset.height(), sampleSize));
99 }
100
101 SkCodec::Result SkAndroidCodec::getAndroidPixels(const SkImageInfo& info, void* pixels,
102 size_t rowBytes, AndroidOptions* options) {
103 if (!pixels) {
104 return SkCodec::kInvalidParameters;
105 }
106 if (rowBytes < info.minRowBytes()) {
107 return SkCodec::kInvalidParameters;
108 }
109
110 AndroidOptions defaultOptions;
111 if (!options) {
112 options = &defaultOptions;
113 } else if (0 == options->fSampleSize) {
114 // Android makes zero the default sample size and treats it as if the
115 // sample size is one.
116 options->fSampleSize = 1;
117 }
118
119 return this->onGetAndroidPixels(info, pixels, rowBytes, *options);
120 }
121
122 SkCodec::Result SkAndroidCodec::getAndroidPixels(const SkImageInfo& info, void* pixels,
123 size_t rowBytes) {
124 return this->getAndroidPixels(info, pixels, rowBytes, nullptr);
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698