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

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

Issue 1249543003: Creating functions for uploading a mipmapped texture. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Refactoring the mipmap level count out. Cleaning includes. Created 4 years, 11 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
9 #include "SkMath.h"
10 #include "SkMipMapLevel.h"
11 #include "SkTypes.h"
12
13 SkMipMapLevel::SkMipMapLevel(const void* texelsOrOffset, size_t rowBytes, int wi dth, int height)
14 : fTexelsOrOffset(texelsOrOffset)
15 , fRowBytes(rowBytes)
16 , fWidth(width)
17 , fHeight(height)
18 {
19 }
20
21 SkMipMapLevel::SkMipMapLevel(SkMipMapLevel&& rhs)
22 : fTexelsOrOffset(rhs.fTexelsOrOffset)
23 , fRowBytes(rhs.fRowBytes)
24 , fWidth(rhs.fWidth)
25 , fHeight(rhs.fHeight)
26 {
27 rhs.fTexelsOrOffset = nullptr;
28 rhs.fRowBytes = 0;
29 rhs.fWidth = 0;
30 rhs.fHeight = 0;
31 }
32
33 SkMipMapLevel& SkMipMapLevel::operator =(SkMipMapLevel&& rhs) {
34 fTexelsOrOffset = rhs.fTexelsOrOffset;
35 fRowBytes = rhs.fRowBytes;
36 fWidth = rhs.fWidth;
37 fHeight = rhs.fHeight;
38
39 rhs.fTexelsOrOffset = nullptr;
40 rhs.fRowBytes = 0;
41 rhs.fWidth = 0;
42 rhs.fHeight = 0;
43
44 return *this;
45 }
46
47 int SkMipMapLevelCount(int baseWidth, int baseHeight) {
48 // OpenGL's spec requires that each mipmap level have height/width equal to
49 // max(1, floor(original_height / 2^i)
50 // (or original_width) where i is the mipmap level.
51 // Continue scaling down until both axes are size 1.
52
53 const int largestAxis = SkTMax(baseWidth, baseHeight);
54 if (largestAxis < 0) {
55 return 0;
56 }
57 const int leadingZeros = SkCLZ(static_cast<uint32_t>(largestAxis));
58 // If the value 00011010 has 3 leading 0s then it has 5 significant bits
59 // (the bits which are not leading zeros)
60 const int significantBits = (sizeof(uint32_t) * 8) - leadingZeros;
61 // This is making the assumption that the size of a byte is 8 bits
62 // and that sizeof(uint32_t)'s implementation-defined behavior is 4.
63 const int mipLevelCount = significantBits;
64
65 return mipLevelCount;
66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698