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

Side by Side Diff: src/image/SkSurface_Raster.cpp

Issue 536003002: Hide fields in SkImageInfo (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix qt Created 6 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/image/SkSurface.cpp ('k') | src/images/SkDecodingImageGenerator.cpp » ('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 2012 Google Inc. 2 * Copyright 2012 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 "SkSurface_Base.h" 8 #include "SkSurface_Base.h"
9 #include "SkImagePriv.h" 9 #include "SkImagePriv.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 23 matching lines...) Expand all
34 34
35 typedef SkSurface_Base INHERITED; 35 typedef SkSurface_Base INHERITED;
36 }; 36 };
37 37
38 /////////////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////////////
39 39
40 bool SkSurface_Raster::Valid(const SkImageInfo& info, size_t rowBytes) { 40 bool SkSurface_Raster::Valid(const SkImageInfo& info, size_t rowBytes) {
41 static const size_t kMaxTotalSize = SK_MaxS32; 41 static const size_t kMaxTotalSize = SK_MaxS32;
42 42
43 int shift = 0; 43 int shift = 0;
44 switch (info.fColorType) { 44 switch (info.colorType()) {
45 case kAlpha_8_SkColorType: 45 case kAlpha_8_SkColorType:
46 shift = 0; 46 shift = 0;
47 break; 47 break;
48 case kRGB_565_SkColorType: 48 case kRGB_565_SkColorType:
49 shift = 1; 49 shift = 1;
50 break; 50 break;
51 case kN32_SkColorType: 51 case kN32_SkColorType:
52 shift = 2; 52 shift = 2;
53 break; 53 break;
54 default: 54 default:
55 return false; 55 return false;
56 } 56 }
57 57
58 if (kIgnoreRowBytesValue == rowBytes) { 58 if (kIgnoreRowBytesValue == rowBytes) {
59 return true; 59 return true;
60 } 60 }
61 61
62 uint64_t minRB = (uint64_t)info.fWidth << shift; 62 uint64_t minRB = (uint64_t)info.width() << shift;
63 if (minRB > rowBytes) { 63 if (minRB > rowBytes) {
64 return false; 64 return false;
65 } 65 }
66 66
67 size_t alignedRowBytes = rowBytes >> shift << shift; 67 size_t alignedRowBytes = rowBytes >> shift << shift;
68 if (alignedRowBytes != rowBytes) { 68 if (alignedRowBytes != rowBytes) {
69 return false; 69 return false;
70 } 70 }
71 71
72 uint64_t size = sk_64_mul(info.fHeight, rowBytes); 72 uint64_t size = sk_64_mul(info.height(), rowBytes);
73 if (size > kMaxTotalSize) { 73 if (size > kMaxTotalSize) {
74 return false; 74 return false;
75 } 75 }
76 76
77 return true; 77 return true;
78 } 78 }
79 79
80 SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, void* pixels, size_t rb, 80 SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, void* pixels, size_t rb,
81 void (*releaseProc)(void* pixels, void* conte xt), void* context) 81 void (*releaseProc)(void* pixels, void* conte xt), void* context)
82 : INHERITED(info) 82 : INHERITED(info)
83 { 83 {
84 fBitmap.installPixels(info, pixels, rb, NULL, releaseProc, context); 84 fBitmap.installPixels(info, pixels, rb, NULL, releaseProc, context);
85 fWeOwnThePixels = false; // We are "Direct" 85 fWeOwnThePixels = false; // We are "Direct"
86 } 86 }
87 87
88 SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr) 88 SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr)
89 : INHERITED(pr->info().fWidth, pr->info().fHeight) 89 : INHERITED(pr->info().width(), pr->info().height())
90 { 90 {
91 const SkImageInfo& info = pr->info(); 91 const SkImageInfo& info = pr->info();
92 92
93 fBitmap.setInfo(info, info.minRowBytes()); 93 fBitmap.setInfo(info, info.minRowBytes());
94 fBitmap.setPixelRef(pr); 94 fBitmap.setPixelRef(pr);
95 fWeOwnThePixels = true; 95 fWeOwnThePixels = true;
96 96
97 if (!info.isOpaque()) { 97 if (!info.isOpaque()) {
98 fBitmap.eraseColor(SK_ColorTRANSPARENT); 98 fBitmap.eraseColor(SK_ColorTRANSPARENT);
99 } 99 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 if (!SkSurface_Raster::Valid(info)) { 162 if (!SkSurface_Raster::Valid(info)) {
163 return NULL; 163 return NULL;
164 } 164 }
165 165
166 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); 166 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL));
167 if (NULL == pr.get()) { 167 if (NULL == pr.get()) {
168 return NULL; 168 return NULL;
169 } 169 }
170 return SkNEW_ARGS(SkSurface_Raster, (pr)); 170 return SkNEW_ARGS(SkSurface_Raster, (pr));
171 } 171 }
OLDNEW
« no previous file with comments | « src/image/SkSurface.cpp ('k') | src/images/SkDecodingImageGenerator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698