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

Side by Side Diff: src/core/SkBitmapController.cpp

Issue 1346713002: move SkBitmapProvider to its own file (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix spelling Created 5 years, 3 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
« no previous file with comments | « src/core/SkBitmapController.h ('k') | src/core/SkBitmapProcShader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapController.h" 9 #include "SkBitmapController.h"
10 #include "SkImage_Base.h" 10 #include "SkBitmapProvider.h"
11 #include "SkMatrix.h" 11 #include "SkMatrix.h"
12 #include "SkPixelRef.h" 12 #include "SkPixelRef.h"
13 #include "SkTemplates.h" 13 #include "SkTemplates.h"
14 14
15 // RESIZE_LANCZOS3 is another good option, but chrome prefers mitchell at the mo ment 15 // RESIZE_LANCZOS3 is another good option, but chrome prefers mitchell at the mo ment
16 #define kHQ_RESIZE_METHOD SkBitmapScaler::RESIZE_MITCHELL 16 #define kHQ_RESIZE_METHOD SkBitmapScaler::RESIZE_MITCHELL
17 17
18 //////////////////////////////////////////////////////////////////////////////// /////////////////// 18 //////////////////////////////////////////////////////////////////////////////// ///////////////////
19 19
20 int SkBitmapProvider::width() const {
21 return fImage ? fImage->width() : fBitmap.width();
22 }
23
24 int SkBitmapProvider::height() const {
25 return fImage ? fImage->height() : fBitmap.height();
26 }
27
28 uint32_t SkBitmapProvider::getID() const {
29 return fImage ? fImage->uniqueID() : fBitmap.getGenerationID();
30 }
31
32 bool SkBitmapProvider::validForDrawing() const {
33 if (!fImage) {
34 if (0 == fBitmap.width() || 0 == fBitmap.height()) {
35 return false;
36 }
37 if (nullptr == fBitmap.pixelRef()) {
38 return false; // no pixels to read
39 }
40 if (fBitmap.getTexture()) {
41 // we can handle texture (ugh) since lockPixels will perform a read- back
42 return true;
43 }
44 if (kIndex_8_SkColorType == fBitmap.colorType()) {
45 SkAutoLockPixels alp(fBitmap); // but we need to call it before getC olorTable() is safe.
46 if (!fBitmap.getColorTable()) {
47 return false;
48 }
49 }
50 }
51 return true;
52 }
53
54 SkImageInfo SkBitmapProvider::info() const {
55 if (fImage) {
56 SkAlphaType at = fImage->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAl phaType;
57 return SkImageInfo::MakeN32(fImage->width(), fImage->height(), at);
58 } else {
59 return fBitmap.info();
60 }
61 }
62
63 SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc(int w, int h) const {
64 return fImage ? SkBitmapCacheDesc::Make(fImage, w, h) : SkBitmapCacheDesc::M ake(fBitmap, w, h);
65 }
66
67 SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc() const {
68 return fImage ? SkBitmapCacheDesc::Make(fImage) : SkBitmapCacheDesc::Make(fB itmap);
69 }
70
71 void SkBitmapProvider::notifyAddedToCache() const {
72 if (fImage) {
73 // TODO
74 } else {
75 fBitmap.pixelRef()->notifyAddedToCache();
76 }
77 }
78
79 bool SkBitmapProvider::asBitmap(SkBitmap* bm) const {
80 if (fImage) {
81 return as_IB(fImage)->getROPixels(bm);
82 } else {
83 *bm = fBitmap;
84 return true;
85 }
86 }
87
88 //////////////////////////////////////////////////////////////////////////////// ///////////////////
89
90 SkBitmapController::State* SkBitmapController::requestBitmap(const SkBitmapProvi der& provider, 20 SkBitmapController::State* SkBitmapController::requestBitmap(const SkBitmapProvi der& provider,
91 const SkMatrix& inv , 21 const SkMatrix& inv ,
92 SkFilterQuality qua lity, 22 SkFilterQuality qua lity,
93 void* storage, size _t storageSize) { 23 void* storage, size _t storageSize) {
94 if (!provider.validForDrawing()) { 24 if (!provider.validForDrawing()) {
95 return nullptr; 25 return nullptr;
96 } 26 }
97 27
98 State* state = this->onRequestBitmap(provider, inv, quality, storage, storag eSize); 28 State* state = this->onRequestBitmap(provider, inv, quality, storage, storag eSize);
99 if (state) { 29 if (state) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 fResultBitmap.getColorTable()); 210 fResultBitmap.getColorTable());
281 } 211 }
282 212
283 SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBi tmapProvider& bm, 213 SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBi tmapProvider& bm,
284 const SkMa trix& inverse, 214 const SkMa trix& inverse,
285 SkFilterQu ality quality, 215 SkFilterQu ality quality,
286 void* stor age, size_t size) { 216 void* stor age, size_t size) {
287 return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size, bm, inverse, quality); 217 return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size, bm, inverse, quality);
288 } 218 }
289 219
OLDNEW
« no previous file with comments | « src/core/SkBitmapController.h ('k') | src/core/SkBitmapProcShader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698