forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor TextureMap and Texture class out of resource_provider_unittest…
….cc and into TestWebGraphicsContext3D So that in a future patch, TestWebGraphicsContext3D will be able to store texture parameters. Review URL: https://codereview.chromium.org/23895005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227097 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
mvujovic@adobe.com
committed
Oct 4, 2013
1 parent
c54e197
commit 84bbc6f
Showing
10 changed files
with
330 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "cc/debug/ordered_texture_map.h" | ||
|
||
#include "base/logging.h" | ||
#include "cc/debug/test_texture.h" | ||
|
||
namespace cc { | ||
|
||
OrderedTextureMap::OrderedTextureMap() {} | ||
|
||
OrderedTextureMap::~OrderedTextureMap() {} | ||
|
||
void OrderedTextureMap::Append(WebKit::WebGLId id, | ||
scoped_refptr<TestTexture> texture) { | ||
DCHECK(texture.get()); | ||
DCHECK(!ContainsId(id)); | ||
|
||
textures_[id] = texture; | ||
ordered_textures_.push_back(id); | ||
} | ||
|
||
void OrderedTextureMap::Replace(WebKit::WebGLId id, | ||
scoped_refptr<TestTexture> texture) { | ||
DCHECK(texture.get()); | ||
DCHECK(ContainsId(id)); | ||
|
||
textures_[id] = texture; | ||
} | ||
|
||
void OrderedTextureMap::Remove(WebKit::WebGLId id) { | ||
TextureMap::iterator map_it = textures_.find(id); | ||
DCHECK(map_it != textures_.end()); | ||
textures_.erase(map_it); | ||
|
||
TextureList::iterator list_it = | ||
std::find(ordered_textures_.begin(), ordered_textures_.end(), id); | ||
DCHECK(list_it != ordered_textures_.end()); | ||
ordered_textures_.erase(list_it); | ||
} | ||
|
||
size_t OrderedTextureMap::Size() { return ordered_textures_.size(); } | ||
|
||
bool OrderedTextureMap::ContainsId(WebKit::WebGLId id) { | ||
return textures_.find(id) != textures_.end(); | ||
} | ||
|
||
scoped_refptr<TestTexture> OrderedTextureMap::TextureForId(WebKit::WebGLId id) { | ||
DCHECK(ContainsId(id)); | ||
scoped_refptr<TestTexture> texture = textures_[id]; | ||
DCHECK(texture.get()); | ||
return texture; | ||
} | ||
|
||
WebKit::WebGLId OrderedTextureMap::IdAt(size_t index) { | ||
DCHECK(index < Size()); | ||
return ordered_textures_[index]; | ||
} | ||
|
||
} // namespace cc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CC_DEBUG_ORDERED_TEXTURE_MAP_H_ | ||
#define CC_DEBUG_ORDERED_TEXTURE_MAP_H_ | ||
|
||
#include <vector> | ||
|
||
#include "base/containers/hash_tables.h" | ||
#include "base/memory/ref_counted.h" | ||
#include "cc/base/cc_export.h" | ||
#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | ||
|
||
namespace cc { | ||
|
||
struct TestTexture; | ||
|
||
class CC_EXPORT OrderedTextureMap { | ||
public: | ||
OrderedTextureMap(); | ||
~OrderedTextureMap(); | ||
|
||
void Append(WebKit::WebGLId id, scoped_refptr<TestTexture> texture); | ||
void Replace(WebKit::WebGLId id, scoped_refptr<TestTexture> texture); | ||
void Remove(WebKit::WebGLId id); | ||
|
||
size_t Size(); | ||
|
||
bool ContainsId(WebKit::WebGLId id); | ||
|
||
scoped_refptr<TestTexture> TextureForId(WebKit::WebGLId id); | ||
WebKit::WebGLId IdAt(size_t index); | ||
|
||
private: | ||
typedef base::hash_map<WebKit::WebGLId, scoped_refptr<TestTexture> > | ||
TextureMap; | ||
typedef std::vector<WebKit::WebGLId> TextureList; | ||
|
||
TextureMap textures_; | ||
TextureList ordered_textures_; | ||
}; | ||
|
||
} // namespace cc | ||
|
||
#endif // CC_DEBUG_ORDERED_TEXTURE_MAP_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "cc/debug/test_texture.h" | ||
|
||
#include "third_party/khronos/GLES2/gl2.h" | ||
|
||
namespace cc { | ||
|
||
size_t TextureSizeBytes(gfx::Size size, ResourceFormat format) { | ||
unsigned int components_per_pixel = 4; | ||
unsigned int bytes_per_component = 1; | ||
return size.width() * size.height() * components_per_pixel * | ||
bytes_per_component; | ||
} | ||
|
||
TestTexture::TestTexture() | ||
: format(RGBA_8888), filter(GL_NEAREST_MIPMAP_LINEAR) {} | ||
|
||
TestTexture::~TestTexture() {} | ||
|
||
void TestTexture::Reallocate(gfx::Size size, ResourceFormat format) { | ||
this->size = size; | ||
this->format = format; | ||
this->data.reset(new uint8_t[TextureSizeBytes(size, format)]); | ||
} | ||
|
||
} // namespace cc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/memory/ref_counted.h" | ||
#include "base/memory/scoped_ptr.h" | ||
#include "cc/base/cc_export.h" | ||
#include "cc/resources/resource_format.h" | ||
#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | ||
#include "ui/gfx/rect.h" | ||
|
||
#ifndef CC_DEBUG_TEST_TEXTURE_H_ | ||
#define CC_DEBUG_TEST_TEXTURE_H_ | ||
|
||
namespace cc { | ||
|
||
size_t CC_EXPORT TextureSizeBytes(gfx::Size size, ResourceFormat format); | ||
|
||
struct CC_EXPORT TestTexture : public base::RefCounted<TestTexture> { | ||
TestTexture(); | ||
|
||
void Reallocate(gfx::Size size, ResourceFormat format); | ||
|
||
gfx::Size size; | ||
ResourceFormat format; | ||
scoped_ptr<uint8_t[]> data; | ||
|
||
// TODO(mvujovic): Replace this with a hash map of texture parameter names | ||
// and values, which can hold this filter parameter value and more. | ||
WebKit::WGC3Denum filter; | ||
|
||
private: | ||
friend class base::RefCounted<TestTexture>; | ||
~TestTexture(); | ||
}; | ||
|
||
} // namespace cc | ||
|
||
#endif // CC_DEBUG_TEST_TEXTURE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.