提交 7ce0501a 编写于 作者: A Adam Barth

Remove some unneeded DEPS from //sky

We no longer actually need to depend on this code. It's cleaner if we don't
list these dependencies.

TBR=eseidel@google.com

Review URL: https://codereview.chromium.org/1229113003 .
上级 97c4fc80
......@@ -378,7 +378,6 @@ source_set("generated_bindings") {
"//base",
"//dart/runtime:libdart",
"//dart/runtime/vm:libdart_platform",
"//gpu/command_buffer/client:gles2_c_lib",
"//mojo/application",
"//mojo/common",
"//mojo/public/c/system",
......@@ -386,9 +385,6 @@ source_set("generated_bindings") {
"//mojo/public/cpp/system",
"//mojo/public/cpp/utility",
"//mojo/public/interfaces/application",
"//mojo/services/keyboard/public/interfaces",
"//mojo/services/navigation/public/interfaces",
"//mojo/services/view_manager/public/cpp",
"//skia",
"//sky/engine/core:core_names",
"//sky/engine/wtf",
......
......@@ -13,7 +13,6 @@ rel_sky_core_gen_dir = rebase_path(sky_core_output_dir, root_build_dir)
source_set("libraries") {
public_deps = [
"//base",
"//gpu/command_buffer/client:gles2_c_lib",
"//mojo/application",
"//mojo/common",
"//mojo/public/c/system",
......@@ -21,10 +20,6 @@ source_set("libraries") {
"//mojo/public/cpp/system",
"//mojo/public/cpp/utility",
"//mojo/public/interfaces/application",
"//mojo/services/keyboard/public/interfaces",
"//mojo/services/navigation/public/interfaces",
"//mojo/services/network/public/interfaces",
"//mojo/services/view_manager/public/cpp",
"//skia",
"//sky/engine/tonic:tonic",
"//sky/engine/wtf",
......
......@@ -9,7 +9,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "dart/runtime/include/dart_api.h"
#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
#include "mojo/public/cpp/system/data_pipe.h"
#include "sky/engine/wtf/OwnPtr.h"
#include "sky/engine/wtf/text/AtomicString.h"
#include "sky/engine/wtf/text/TextPosition.h"
......
......@@ -295,11 +295,6 @@ source_set("platform") {
"geometry/TransformState.h",
"graphics/BitmapImage.cpp",
"graphics/BitmapImage.h",
"graphics/Canvas2DImageBufferSurface.h",
"graphics/Canvas2DLayerBridge.cpp",
"graphics/Canvas2DLayerBridge.h",
"graphics/Canvas2DLayerManager.cpp",
"graphics/Canvas2DLayerManager.h",
"graphics/Color.cpp",
"graphics/Color.h",
"graphics/ColorSpace.cpp",
......@@ -330,7 +325,6 @@ source_set("platform") {
"graphics/GraphicsContextStateSaver.h",
"graphics/GraphicsTypes.cpp",
"graphics/GraphicsTypes.h",
"graphics/GraphicsTypes3D.h",
"graphics/Image.cpp",
"graphics/Image.h",
"graphics/ImageBuffer.cpp",
......@@ -420,14 +414,6 @@ source_set("platform") {
"graphics/filters/SourceGraphic.h",
"graphics/filters/SpotLightSource.cpp",
"graphics/filters/SpotLightSource.h",
"graphics/gpu/DrawingBuffer.cpp",
"graphics/gpu/DrawingBuffer.h",
"graphics/gpu/Extensions3DUtil.cpp",
"graphics/gpu/Extensions3DUtil.h",
"graphics/gpu/WebGLImageBufferSurface.cpp",
"graphics/gpu/WebGLImageBufferSurface.h",
"graphics/gpu/WebGLImageConversion.cpp",
"graphics/gpu/WebGLImageConversion.h",
"graphics/skia/GaneshUtils.cpp",
"graphics/skia/GaneshUtils.h",
"graphics/skia/NativeImageSkia.cpp",
......@@ -584,7 +570,6 @@ source_set("platform") {
deps = [
":make_platform_generated",
"//base:base",
"//gpu/command_buffer/client:gles2_c_lib",
"//mojo/application",
"//mojo/common",
"//mojo/environment:chromium",
......@@ -606,7 +591,6 @@ source_set("platform") {
]
forward_dependent_configs_from = [
"//gpu/command_buffer/client:gles2_c_lib",
"//skia",
"//third_party:jpeg",
"//third_party/iccjpeg",
......@@ -666,7 +650,6 @@ test("platform_unittests") {
"geometry/RoundedRectTest.cpp",
"graphics/GraphicsContextTest.cpp",
"graphics/ThreadSafeDataTransportTest.cpp",
"graphics/gpu/DrawingBufferTest.cpp",
"image-decoders/ImageDecoderTest.cpp",
"mac/ScrollElasticityControllerTest.mm",
"network/HTTPParsersTest.cpp",
......
/*
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SKY_ENGINE_PLATFORM_GRAPHICS_CANVAS2DIMAGEBUFFERSURFACE_H_
#define SKY_ENGINE_PLATFORM_GRAPHICS_CANVAS2DIMAGEBUFFERSURFACE_H_
#include "sky/engine/platform/graphics/Canvas2DLayerBridge.h"
#include "sky/engine/platform/graphics/ImageBufferSurface.h"
namespace blink {
// This shim necessary because ImageBufferSurfaces are not allowed to be RefCounted
class Canvas2DImageBufferSurface final : public ImageBufferSurface {
public:
Canvas2DImageBufferSurface(const IntSize& size, OpacityMode opacityMode = NonOpaque, int msaaSampleCount = 1)
: ImageBufferSurface(size, opacityMode)
, m_layerBridge(Canvas2DLayerBridge::create(size, opacityMode, msaaSampleCount))
{
clear();
}
virtual ~Canvas2DImageBufferSurface()
{
if (m_layerBridge)
m_layerBridge->beginDestruction();
}
// ImageBufferSurface implementation
virtual void finalizeFrame() override { m_layerBridge->finalizeFrame(); }
virtual void willAccessPixels() override { m_layerBridge->willAccessPixels(); }
virtual SkCanvas* canvas() const override { return m_layerBridge->canvas(); }
virtual bool isValid() const override { return m_layerBridge && m_layerBridge->checkSurfaceValid(); }
virtual bool restore() override { return m_layerBridge->restoreSurface(); }
virtual WebLayer* layer() const override { return m_layerBridge->layer(); }
virtual Platform3DObject getBackingTexture() const override { return m_layerBridge->getBackingTexture(); }
virtual bool isAccelerated() const override { return m_layerBridge->isAccelerated(); }
virtual void setIsHidden(bool hidden) override { m_layerBridge->setIsHidden(hidden); }
virtual void setImageBuffer(ImageBuffer* imageBuffer) override { m_layerBridge->setImageBuffer(imageBuffer); }
private:
RefPtr<Canvas2DLayerBridge> m_layerBridge;
};
} // namespace blink
#endif // SKY_ENGINE_PLATFORM_GRAPHICS_CANVAS2DIMAGEBUFFERSURFACE_H_
/*
* Copyright (C) 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SKY_ENGINE_PLATFORM_GRAPHICS_CANVAS2DLAYERBRIDGE_H_
#define SKY_ENGINE_PLATFORM_GRAPHICS_CANVAS2DLAYERBRIDGE_H_
#include "sky/engine/platform/PlatformExport.h"
#include "sky/engine/platform/geometry/IntSize.h"
#include "sky/engine/platform/graphics/ImageBufferSurface.h"
#include "sky/engine/public/platform/WebExternalTextureLayer.h"
#include "sky/engine/public/platform/WebExternalTextureLayerClient.h"
#include "sky/engine/public/platform/WebExternalTextureMailbox.h"
#include "sky/engine/wtf/DoublyLinkedList.h"
#include "sky/engine/wtf/PassOwnPtr.h"
#include "sky/engine/wtf/RefCounted.h"
#include "sky/engine/wtf/RefPtr.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/utils/SkDeferredCanvas.h"
class Canvas2DLayerBridgeTest;
namespace blink {
class ImageBuffer;
class WebGraphicsContext3D;
class WebGraphicsContext3DProvider;
class PLATFORM_EXPORT Canvas2DLayerBridge : public WebExternalTextureLayerClient, public SkDeferredCanvas::NotificationClient, public DoublyLinkedListNode<Canvas2DLayerBridge>, public RefCounted<Canvas2DLayerBridge> {
WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge);
public:
static PassRefPtr<Canvas2DLayerBridge> create(const IntSize&, OpacityMode, int msaaSampleCount);
virtual ~Canvas2DLayerBridge();
// WebExternalTextureLayerClient implementation.
virtual bool prepareMailbox(WebExternalTextureMailbox*, WebExternalBitmap*) override;
virtual void mailboxReleased(const WebExternalTextureMailbox&, bool lostResource) override;
// SkDeferredCanvas::NotificationClient implementation
virtual void prepareForDraw() override;
virtual void storageAllocatedForRecordingChanged(size_t) override;
virtual void flushedDrawCommands() override;
virtual void skippedPendingDrawCommands() override;
// ImageBufferSurface implementation
void finalizeFrame();
void willAccessPixels();
SkCanvas* canvas() const { return m_canvas.get(); }
bool checkSurfaceValid();
bool restoreSurface();
WebLayer* layer() const;
Platform3DObject getBackingTexture();
bool isAccelerated() const { return true; }
void setIsHidden(bool);
void setImageBuffer(ImageBuffer* imageBuffer) { m_imageBuffer = imageBuffer; }
// Methods used by Canvas2DLayerManager
virtual size_t freeMemoryIfPossible(size_t); // virtual for mocking
virtual void flush(); // virtual for mocking
virtual size_t storageAllocatedForRecording(); // virtual for faking
size_t bytesAllocated() const { return m_bytesAllocated; }
void limitPendingFrames();
void freeReleasedMailbox();
bool hasReleasedMailbox() const;
void freeTransientResources();
bool hasTransientResources() const;
bool isHidden() { return m_isHidden; }
void beginDestruction();
protected:
Canvas2DLayerBridge(PassOwnPtr<WebGraphicsContext3DProvider>, PassOwnPtr<SkDeferredCanvas>, PassRefPtr<SkSurface>, int, OpacityMode);
void setRateLimitingEnabled(bool);
bool releasedMailboxHasExpired();
WebGraphicsContext3D* context();
OwnPtr<SkDeferredCanvas> m_canvas;
RefPtr<SkSurface> m_surface;
OwnPtr<WebExternalTextureLayer> m_layer;
OwnPtr<WebGraphicsContext3DProvider> m_contextProvider;
ImageBuffer* m_imageBuffer;
int m_msaaSampleCount;
size_t m_bytesAllocated;
bool m_didRecordDrawCommand;
bool m_isSurfaceValid;
int m_framesPending;
int m_framesSinceMailboxRelease;
bool m_destructionInProgress;
bool m_rateLimitingEnabled;
bool m_isHidden;
friend class WTF::DoublyLinkedListNode<Canvas2DLayerBridge>;
friend class ::Canvas2DLayerBridgeTest;
Canvas2DLayerBridge* m_next;
Canvas2DLayerBridge* m_prev;
enum MailboxStatus {
MailboxInUse,
MailboxReleased,
MailboxAvailable,
};
struct MailboxInfo {
WebExternalTextureMailbox m_mailbox;
RefPtr<SkImage> m_image;
MailboxStatus m_status;
RefPtr<Canvas2DLayerBridge> m_parentLayerBridge;
MailboxInfo(const MailboxInfo&);
MailboxInfo() {}
};
MailboxInfo* createMailboxInfo();
MailboxInfo* releasedMailboxInfo();
uint32_t m_lastImageId;
Vector<MailboxInfo> m_mailboxes;
int m_releasedMailboxInfoIndex;
};
} // namespace blink
#endif // SKY_ENGINE_PLATFORM_GRAPHICS_CANVAS2DLAYERBRIDGE_H_
/*
Copyright (C) 2012 Google Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "sky/engine/platform/graphics/Canvas2DLayerManager.h"
#include "sky/engine/public/platform/Platform.h"
#include "sky/engine/wtf/StdLibExtras.h"
namespace {
enum {
DefaultMaxBytesAllocated = 64*1024*1024,
DefaultTargetBytesAllocated = 16*1024*1024,
};
} // unnamed namespace
namespace blink {
Canvas2DLayerManager::Canvas2DLayerManager()
: m_bytesAllocated(0)
, m_maxBytesAllocated(DefaultMaxBytesAllocated)
, m_targetBytesAllocated(DefaultTargetBytesAllocated)
, m_limitPendingFramesTimer(this, &Canvas2DLayerManager::limitPendingFramesTimerFired)
{
}
Canvas2DLayerManager::~Canvas2DLayerManager()
{
ASSERT(!m_bytesAllocated);
ASSERT(!m_layerList.head());
}
void Canvas2DLayerManager::init(size_t maxBytesAllocated, size_t targetBytesAllocated)
{
ASSERT(maxBytesAllocated >= targetBytesAllocated);
m_maxBytesAllocated = maxBytesAllocated;
m_targetBytesAllocated = targetBytesAllocated;
if (m_limitPendingFramesTimer.isActive())
m_limitPendingFramesTimer.stop();
}
Canvas2DLayerManager& Canvas2DLayerManager::get()
{
DEFINE_STATIC_LOCAL(Canvas2DLayerManager, manager, ());
return manager;
}
void Canvas2DLayerManager::limitPendingFramesTimerFired(Timer<Canvas2DLayerManager>*)
{
Canvas2DLayerBridge* layer = m_layerList.head();
while (layer) {
Canvas2DLayerBridge* currentLayer = layer;
// must increment iterator before calling limitPendingFrames, which
// may result in the layer being removed from the list.
layer = layer->next();
currentLayer->limitPendingFrames();
}
}
void Canvas2DLayerManager::layerDidDraw(Canvas2DLayerBridge* layer)
{
if (isInList(layer)) {
if (layer != m_layerList.head()) {
m_layerList.remove(layer);
m_layerList.push(layer); // Set as MRU
}
}
if (!m_limitPendingFramesTimer.isActive())
m_limitPendingFramesTimer.startOneShot(0, FROM_HERE);
}
void Canvas2DLayerManager::layerTransientResourceAllocationChanged(Canvas2DLayerBridge* layer, intptr_t deltaBytes)
{
ASSERT((intptr_t)m_bytesAllocated + deltaBytes >= 0);
m_bytesAllocated = (intptr_t)m_bytesAllocated + deltaBytes;
if (!isInList(layer) && layer->hasTransientResources()) {
m_layerList.push(layer);
} else if (isInList(layer) && !layer->hasTransientResources()) {
m_layerList.remove(layer);
layer->setNext(0);
layer->setPrev(0);
}
if (deltaBytes > 0)
freeMemoryIfNecessary();
}
void Canvas2DLayerManager::freeMemoryIfNecessary()
{
if (m_bytesAllocated >= m_maxBytesAllocated) {
// Pass 1: Free memory from caches
Canvas2DLayerBridge* layer = m_layerList.tail(); // LRU
while (layer && m_bytesAllocated > m_targetBytesAllocated) {
Canvas2DLayerBridge* currentLayer = layer;
layer = layer->prev();
currentLayer->freeMemoryIfPossible(m_bytesAllocated - m_targetBytesAllocated);
ASSERT(isInList(currentLayer) == currentLayer->hasTransientResources());
}
// Pass 2: Flush canvases
layer = m_layerList.tail();
while (m_bytesAllocated > m_targetBytesAllocated && layer) {
Canvas2DLayerBridge* currentLayer = layer;
layer = layer->prev();
currentLayer->flush();
currentLayer->freeMemoryIfPossible(m_bytesAllocated - m_targetBytesAllocated);
ASSERT(isInList(currentLayer) == currentLayer->hasTransientResources());
}
}
}
bool Canvas2DLayerManager::isInList(Canvas2DLayerBridge* layer) const
{
return layer->prev() || m_layerList.head() == layer;
}
} // namespace blink
/*
Copyright (C) 2012 Google Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SKY_ENGINE_PLATFORM_GRAPHICS_CANVAS2DLAYERMANAGER_H_
#define SKY_ENGINE_PLATFORM_GRAPHICS_CANVAS2DLAYERMANAGER_H_
#include "sky/engine/platform/Timer.h"
#include "sky/engine/platform/graphics/Canvas2DLayerBridge.h"
class Canvas2DLayerManagerTest;
namespace blink {
class PLATFORM_EXPORT Canvas2DLayerManager {
public:
static Canvas2DLayerManager& get();
void init(size_t maxBytesAllocated, size_t targetBytesAllocated);
virtual ~Canvas2DLayerManager();
void layerTransientResourceAllocationChanged(Canvas2DLayerBridge*, intptr_t deltaBytes = 0);
void layerDidDraw(Canvas2DLayerBridge*);
bool isInList(Canvas2DLayerBridge*) const;
private:
Canvas2DLayerManager();
// internal methods
void freeMemoryIfNecessary();
void addLayerToList(Canvas2DLayerBridge*);
void limitPendingFramesTimerFired(Timer<Canvas2DLayerManager>*);
size_t m_bytesAllocated;
size_t m_maxBytesAllocated;
size_t m_targetBytesAllocated;
Timer<Canvas2DLayerManager> m_limitPendingFramesTimer;
DoublyLinkedList<Canvas2DLayerBridge> m_layerList;
friend class ::Canvas2DLayerManagerTest; // for unit testing
};
} // namespace blink
#endif // SKY_ENGINE_PLATFORM_GRAPHICS_CANVAS2DLAYERMANAGER_H_
......@@ -72,15 +72,6 @@ public:
virtual SkCanvas* canvas() const override { return m_surface ? m_surface->getCanvas() : 0; }
virtual bool isValid() const override { return m_surface; }
virtual bool isAccelerated() const override { return isValid() && m_surface->getCanvas()->getTopDevice()->accessRenderTarget(); }
virtual Platform3DObject getBackingTexture() const override
{
ASSERT(isAccelerated());
GrRenderTarget* renderTarget = m_surface->getCanvas()->getTopDevice()->accessRenderTarget();
if (renderTarget) {
return renderTarget->asTexture()->getTextureHandle();
}
return 0;
};
private:
RefPtr<SkSurface> m_surface;
......
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SKY_ENGINE_PLATFORM_GRAPHICS_GRAPHICSTYPES3D_H_
#define SKY_ENGINE_PLATFORM_GRAPHICS_GRAPHICSTYPES3D_H_
#include <stdint.h>
#include "sky/engine/wtf/Forward.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
typedef unsigned Platform3DObject;
// WebGL-specific enums
const unsigned GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL = 0x821A;
const unsigned GC3D_UNPACK_FLIP_Y_WEBGL = 0x9240;
const unsigned GC3D_UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241;
const unsigned GC3D_CONTEXT_LOST_WEBGL = 0x9242;
const unsigned GC3D_UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243;
const unsigned GC3D_BROWSER_DEFAULT_WEBGL = 0x9244;
// GL_CHROMIUM_flipy
const unsigned GC3D_UNPACK_FLIP_Y_CHROMIUM = 0x9240;
// GL_CHROMIUM_copy_texture
const unsigned GC3D_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM = 0x9241;
const unsigned GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM = 0x9242;
// GL_AMD_compressed_ATC_texture
const unsigned GC3D_COMPRESSED_ATC_RGB_AMD = 0x8C92;
const unsigned GC3D_COMPRESSED_ATC_RGBA_EXPLICIT_ALPHA_AMD = 0x8C93;
const unsigned GC3D_COMPRESSED_ATC_RGBA_INTERPOLATED_ALPHA_AMD = 0x87EE;
// GL_CHROMIUM_image
const unsigned GC3D_IMAGE_ROWBYTES_CHROMIUM = 0x78F0;
const unsigned GC3D_IMAGE_MAP_CHROMIUM = 0x78F1;
const unsigned GC3D_IMAGE_SCANOUT_CHROMIUM = 0x78F2;
#endif // SKY_ENGINE_PLATFORM_GRAPHICS_GRAPHICSTYPES3D_H_
......@@ -38,11 +38,8 @@
#include "sky/engine/platform/geometry/IntRect.h"
#include "sky/engine/platform/graphics/BitmapImage.h"
#include "sky/engine/platform/graphics/GraphicsContext.h"
#include "sky/engine/platform/graphics/GraphicsTypes3D.h"
#include "sky/engine/platform/graphics/ImageBufferClient.h"
#include "sky/engine/platform/graphics/UnacceleratedImageBufferSurface.h"
#include "sky/engine/platform/graphics/gpu/DrawingBuffer.h"
#include "sky/engine/platform/graphics/gpu/Extensions3DUtil.h"
#include "sky/engine/platform/graphics/skia/NativeImageSkia.h"
#include "sky/engine/platform/graphics/skia/SkiaUtils.h"
#include "sky/engine/public/platform/Platform.h"
......@@ -164,82 +161,12 @@ WebLayer* ImageBuffer::platformLayer() const
return m_surface->layer();
}
bool ImageBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platform3DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premultiplyAlpha, bool flipY)
{
if (!m_surface->isAccelerated() || !platformLayer() || !isSurfaceValid())
return false;
if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, destType, level))
return false;
OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
if (!provider)
return false;
WebGraphicsContext3D* sharedContext = provider->context3d();
if (!sharedContext)
return false;
OwnPtr<WebExternalTextureMailbox> mailbox = adoptPtr(new WebExternalTextureMailbox);
// Contexts may be in a different share group. We must transfer the texture through a mailbox first
sharedContext->genMailboxCHROMIUM(mailbox->name);
sharedContext->produceTextureDirectCHROMIUM(getBackingTexture(), GL_TEXTURE_2D, mailbox->name);
sharedContext->flush();
mailbox->syncPoint = sharedContext->insertSyncPoint();
context->waitSyncPoint(mailbox->syncPoint);
Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox->name);
// The canvas is stored in a premultiplied format, so unpremultiply if necessary.
context->pixelStorei(GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, !premultiplyAlpha);
// The canvas is stored in an inverted position, so the flip semantics are reversed.
context->pixelStorei(GC3D_UNPACK_FLIP_Y_CHROMIUM, !flipY);
context->copyTextureCHROMIUM(GL_TEXTURE_2D, sourceTexture, texture, level, internalFormat, destType);
context->pixelStorei(GC3D_UNPACK_FLIP_Y_CHROMIUM, false);
context->pixelStorei(GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, false);
context->deleteTexture(sourceTexture);
context->flush();
sharedContext->waitSyncPoint(context->insertSyncPoint());
// Undo grContext texture binding changes introduced in this function
provider->grContext()->resetContext(kTextureBinding_GrGLBackendState);
return true;
}
static bool drawNeedsCopy(GraphicsContext* src, GraphicsContext* dst)
{
ASSERT(dst);
return (src == dst);
}
Platform3DObject ImageBuffer::getBackingTexture()
{
return m_surface->getBackingTexture();
}
bool ImageBuffer::copyRenderingResultsFromDrawingBuffer(DrawingBuffer* drawingBuffer, bool fromFrontBuffer)
{
if (!drawingBuffer)
return false;
OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
if (!provider)
return false;
WebGraphicsContext3D* context3D = provider->context3d();
Platform3DObject tex = m_surface->getBackingTexture();
if (!context3D || !tex)
return false;
m_surface->invalidateCachedBitmap();
return drawingBuffer->copyToPlatformTexture(context3D, tex, GL_RGBA,
GL_UNSIGNED_BYTE, 0, true, false, fromFrontBuffer);
}
void ImageBuffer::draw(GraphicsContext* context, const FloatRect& destRect, const FloatRect* srcPtr, CompositeOperator op, WebBlendMode blendMode)
{
if (!isSurfaceValid())
......
......@@ -31,10 +31,8 @@
#include "sky/engine/platform/PlatformExport.h"
#include "sky/engine/platform/geometry/FloatRect.h"
#include "sky/engine/platform/geometry/IntSize.h"
#include "sky/engine/platform/graphics/Canvas2DLayerBridge.h"
#include "sky/engine/platform/graphics/ColorSpace.h"
#include "sky/engine/platform/graphics/GraphicsTypes.h"
#include "sky/engine/platform/graphics/GraphicsTypes3D.h"
#include "sky/engine/platform/graphics/ImageBufferSurface.h"
#include "sky/engine/platform/transforms/AffineTransform.h"
#include "sky/engine/wtf/Forward.h"
......@@ -45,7 +43,6 @@
namespace blink {
class DrawingBuffer;
class GraphicsContext;
class Image;
class ImageBufferClient;
......@@ -109,16 +106,6 @@ public:
void transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstColorSpace);
WebLayer* platformLayer() const;
// FIXME: current implementations of this method have the restriction that they only work
// with textures that are RGB or RGBA format, UNSIGNED_BYTE type and level 0, as specified in
// Extensions3D::canUseCopyTextureCHROMIUM().
// Destroys the TEXTURE_2D binding for the active texture unit of the passed context
bool copyToPlatformTexture(WebGraphicsContext3D*, Platform3DObject, GLenum, GLenum, GLint, bool, bool);
Platform3DObject getBackingTexture();
bool copyRenderingResultsFromDrawingBuffer(DrawingBuffer*, bool fromFrontBuffer = false);
void flush();
void notifySurfaceInvalid();
......
......@@ -33,7 +33,6 @@
#include "sky/engine/platform/PlatformExport.h"
#include "sky/engine/platform/geometry/IntSize.h"
#include "sky/engine/platform/graphics/GraphicsTypes3D.h"
#include "sky/engine/wtf/FastAllocBase.h"
#include "sky/engine/wtf/Noncopyable.h"
#include "sky/engine/wtf/PassRefPtr.h"
......@@ -65,7 +64,6 @@ public:
virtual bool restore() { return false; };
virtual WebLayer* layer() const { return 0; };
virtual bool isAccelerated() const { return false; }
virtual Platform3DObject getBackingTexture() const { return 0; }
virtual bool cachedBitmapEnabled() const { return false; }
virtual const SkBitmap& cachedBitmap() const;
virtual void invalidateCachedBitmap() { }
......
/*
* Copyright (c) 2010, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SKY_ENGINE_PLATFORM_GRAPHICS_GPU_DRAWINGBUFFER_H_
#define SKY_ENGINE_PLATFORM_GRAPHICS_GPU_DRAWINGBUFFER_H_
#include "sky/engine/platform/PlatformExport.h"
#include "sky/engine/platform/geometry/IntSize.h"
#include "sky/engine/platform/graphics/GraphicsTypes3D.h"
#include "sky/engine/platform/graphics/gpu/WebGLImageConversion.h"
#include "sky/engine/public/platform/WebExternalTextureLayerClient.h"
#include "sky/engine/public/platform/WebExternalTextureMailbox.h"
#include "sky/engine/public/platform/WebGraphicsContext3D.h"
#include "sky/engine/wtf/Deque.h"
#include "sky/engine/wtf/Noncopyable.h"
#include "sky/engine/wtf/OwnPtr.h"
#include "sky/engine/wtf/PassOwnPtr.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace blink {
class Extensions3DUtil;
class ImageBuffer;
class WebExternalBitmap;
class WebExternalTextureLayer;
class WebGraphicsContext3D;
class WebLayer;
// Abstract interface to allow basic context eviction management
class PLATFORM_EXPORT ContextEvictionManager : public RefCounted<ContextEvictionManager> {
public:
virtual ~ContextEvictionManager() {};
virtual void forciblyLoseOldestContext(const String& reason) = 0;
virtual IntSize oldestContextSize() = 0;
};
// Manages a rendering target (framebuffer + attachment) for a canvas. Can publish its rendering
// results to a WebLayer for compositing.
class PLATFORM_EXPORT DrawingBuffer : public RefCounted<DrawingBuffer>, public WebExternalTextureLayerClient {
// If we used CHROMIUM_image as the backing storage for our buffers,
// we need to know the mapping from texture id to image.
struct TextureInfo {
Platform3DObject textureId;
WGC3Duint imageId;
TextureInfo()
: textureId(0)
, imageId(0)
{
}
};
struct MailboxInfo : public RefCounted<MailboxInfo> {
WebExternalTextureMailbox mailbox;
TextureInfo textureInfo;
IntSize size;
// This keeps the parent drawing buffer alive as long as the compositor is
// referring to one of the mailboxes DrawingBuffer produced. The parent drawing buffer is
// cleared when the compositor returns the mailbox. See mailboxReleased().
RefPtr<DrawingBuffer> m_parentDrawingBuffer;
};
public:
enum PreserveDrawingBuffer {
Preserve,
Discard
};
static PassRefPtr<DrawingBuffer> create(PassOwnPtr<WebGraphicsContext3D>, const IntSize&, PreserveDrawingBuffer, WebGraphicsContext3D::Attributes requestedAttributes, PassRefPtr<ContextEvictionManager>);
virtual ~DrawingBuffer();
// Destruction will be completed after all mailboxes are released.
void beginDestruction();
// Issues a glClear() on all framebuffers associated with this DrawingBuffer. The caller is responsible for
// making the context current and setting the clear values and masks. Modifies the framebuffer binding.
void clearFramebuffers(GLbitfield clearMask);
// Given the desired buffer size, provides the largest dimensions that will fit in the pixel budget.
static IntSize adjustSize(const IntSize& desiredSize, const IntSize& curSize, int maxTextureSize);
bool reset(const IntSize&);
void bind();
IntSize size() const { return m_size; }
// Copies the multisample color buffer to the normal color buffer and leaves m_fbo bound.
void commit(long x = 0, long y = 0, long width = -1, long height = -1);
// commit should copy the full multisample buffer, and not respect the
// current scissor bounds. Track the state of the scissor test so that it
// can be disabled during calls to commit.
void setScissorEnabled(bool scissorEnabled) { m_scissorEnabled = scissorEnabled; }
// The DrawingBuffer needs to track the texture bound to texture unit 0.
// The bound texture is tracked to avoid costly queries during rendering.
void setTexture2DBinding(Platform3DObject texture) { m_texture2DBinding = texture; }
// The DrawingBuffer needs to track the currently bound framebuffer so it
// restore the binding when needed.
void setFramebufferBinding(Platform3DObject fbo) { m_framebufferBinding = fbo; }
// Track the currently active texture unit. Texture unit 0 is used as host for a scratch
// texture.
void setActiveTextureUnit(GLint textureUnit) { m_activeTextureUnit = textureUnit; }
bool multisample() const;
Platform3DObject framebuffer() const;
void markContentsChanged();
void markLayerComposited();
bool layerComposited() const;
void setIsHidden(bool);
WebLayer* platformLayer();
void paintCompositedResultsToCanvas(ImageBuffer*);
WebGraphicsContext3D* context();
// Returns the actual context attributes for this drawing buffer which may differ from the
// requested context attributes due to implementation limits.
WebGraphicsContext3D::Attributes getActualAttributes() const { return m_actualAttributes; }
// WebExternalTextureLayerClient implementation.
virtual bool prepareMailbox(WebExternalTextureMailbox*, WebExternalBitmap*) override;
virtual void mailboxReleased(const WebExternalTextureMailbox&, bool lostResource = false) override;
// Destroys the TEXTURE_2D binding for the owned context
bool copyToPlatformTexture(WebGraphicsContext3D*, Platform3DObject texture, GLenum internalFormat,
GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, bool fromFrontBuffer = false);
void setPackAlignment(GLint param);
void paintRenderingResultsToCanvas(ImageBuffer*);
PassRefPtr<Uint8ClampedArray> paintRenderingResultsToImageData(int&, int&);
protected: // For unittests
DrawingBuffer(
PassOwnPtr<WebGraphicsContext3D>,
PassOwnPtr<Extensions3DUtil>,
bool multisampleExtensionSupported,
bool packedDepthStencilExtensionSupported,
PreserveDrawingBuffer,
WebGraphicsContext3D::Attributes requestedAttributes,
PassRefPtr<ContextEvictionManager>);
bool initialize(const IntSize&);
private:
void mailboxReleasedWithoutRecycling(const WebExternalTextureMailbox&);
unsigned createColorTexture();
// Create the depth/stencil and multisample buffers, if needed.
void createSecondaryBuffers();
bool resizeFramebuffer(const IntSize&);
bool resizeMultisampleFramebuffer(const IntSize&);
void resizeDepthStencil(const IntSize&);
// Bind to the m_framebufferBinding if it's not 0.
void restoreFramebufferBinding();
void clearPlatformLayer();
PassRefPtr<MailboxInfo> recycledMailbox();
PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&);
void deleteMailbox(const WebExternalTextureMailbox&);
void freeRecycledMailboxes();
// Updates the current size of the buffer, ensuring that s_currentResourceUsePixels is updated.
void setSize(const IntSize& size);
// Calculates the difference in pixels between the current buffer size and the proposed size.
static int pixelDelta(const IntSize& newSize, const IntSize& curSize);
// Given the desired buffer size, provides the largest dimensions that will fit in the pixel budget
// Returns true if the buffer will only fit if the oldest WebGL context is forcibly lost
IntSize adjustSizeWithContextEviction(const IntSize&, bool& evictContext);
void paintFramebufferToCanvas(int framebuffer, int width, int height, bool premultiplyAlpha, ImageBuffer*);
// This is the order of bytes to use when doing a readback.
enum ReadbackOrder {
ReadbackRGBA,
ReadbackSkia
};
// Helper function which does a readback from the currently-bound
// framebuffer into a buffer of a certain size with 4-byte pixels.
void readBackFramebuffer(unsigned char* pixels, int width, int height, ReadbackOrder, WebGLImageConversion::AlphaOp);
// Helper function to flip a bitmap vertically.
void flipVertically(uint8_t* data, int width, int height);
// Helper to texImage2D with pixel==0 case: pixels are initialized to 0.
// By default, alignment is 4, the OpenGL default setting.
void texImage2DResourceSafe(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLint alignment = 4);
// Allocate buffer storage to be sent to compositor using either texImage2D or CHROMIUM_image based on available support.
void allocateTextureMemory(TextureInfo*, const IntSize&);
void deleteChromiumImageForTexture(TextureInfo*);
PreserveDrawingBuffer m_preserveDrawingBuffer;
bool m_scissorEnabled;
Platform3DObject m_texture2DBinding;
Platform3DObject m_framebufferBinding;
GLenum m_activeTextureUnit;
OwnPtr<WebGraphicsContext3D> m_context;
OwnPtr<Extensions3DUtil> m_extensionsUtil;
IntSize m_size;
WebGraphicsContext3D::Attributes m_requestedAttributes;
bool m_multisampleExtensionSupported;
bool m_packedDepthStencilExtensionSupported;
Platform3DObject m_fbo;
// DrawingBuffer's output is double-buffered. m_colorBuffer is the back buffer.
TextureInfo m_colorBuffer;
TextureInfo m_frontColorBuffer;
// This is used when we have OES_packed_depth_stencil.
Platform3DObject m_depthStencilBuffer;
// These are used when we don't.
Platform3DObject m_depthBuffer;
Platform3DObject m_stencilBuffer;
// For multisampling.
Platform3DObject m_multisampleFBO;
Platform3DObject m_multisampleColorBuffer;
// True if our contents have been modified since the last presentation of this buffer.
bool m_contentsChanged;
// True if commit() has been called since the last time markContentsChanged() had been called.
bool m_contentsChangeCommitted;
bool m_layerComposited;
enum MultisampleMode {
None,
ImplicitResolve,
ExplicitResolve,
};
MultisampleMode m_multisampleMode;
WebGraphicsContext3D::Attributes m_actualAttributes;
unsigned m_internalColorFormat;
unsigned m_colorFormat;
unsigned m_internalRenderbufferFormat;
int m_maxTextureSize;
int m_sampleCount;
int m_packAlignment;
bool m_destructionInProgress;
bool m_isHidden;
OwnPtr<WebExternalTextureLayer> m_layer;
// All of the mailboxes that this DrawingBuffer has ever created.
Vector<RefPtr<MailboxInfo> > m_textureMailboxes;
// Mailboxes that were released by the compositor can be used again by this DrawingBuffer.
Deque<WebExternalTextureMailbox> m_recycledMailboxQueue;
RefPtr<ContextEvictionManager> m_contextEvictionManager;
// If the width and height of the Canvas's backing store don't
// match those that we were given in the most recent call to
// reshape(), then we need an intermediate bitmap to read back the
// frame buffer into. This seems to happen when CSS styles are
// used to resize the Canvas.
SkBitmap m_resizingBitmap;
// Used to flip a bitmap vertically.
Vector<uint8_t> m_scanline;
};
} // namespace blink
#endif // SKY_ENGINE_PLATFORM_GRAPHICS_GPU_DRAWINGBUFFER_H_
// Copyright 2014 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 "sky/engine/platform/graphics/gpu/Extensions3DUtil.h"
#include "sky/engine/public/platform/WebGraphicsContext3D.h"
#include "sky/engine/wtf/PassOwnPtr.h"
#include "sky/engine/wtf/text/CString.h"
#include "sky/engine/wtf/text/StringHash.h"
namespace blink {
namespace {
void splitStringHelper(const String& str, HashSet<String>& set)
{
Vector<String> substrings;
str.split(' ', substrings);
for (size_t i = 0; i < substrings.size(); ++i)
set.add(substrings[i]);
}
} // anonymous namespace
PassOwnPtr<Extensions3DUtil> Extensions3DUtil::create(WebGraphicsContext3D* context)
{
OwnPtr<Extensions3DUtil> out = adoptPtr(new Extensions3DUtil(context));
if (!out->initializeExtensions())
return nullptr;
return out.release();
}
Extensions3DUtil::Extensions3DUtil(WebGraphicsContext3D* context)
: m_context(context)
{
}
Extensions3DUtil::~Extensions3DUtil()
{
}
bool Extensions3DUtil::initializeExtensions()
{
if (m_context->isContextLost()) {
// Need to try to restore the context again later.
return false;
}
String extensionsString = m_context->getString(GL_EXTENSIONS);
splitStringHelper(extensionsString, m_enabledExtensions);
String requestableExtensionsString = m_context->getRequestableExtensionsCHROMIUM();
splitStringHelper(requestableExtensionsString, m_requestableExtensions);
return true;
}
bool Extensions3DUtil::supportsExtension(const String& name)
{
return m_enabledExtensions.contains(name) || m_requestableExtensions.contains(name);
}
bool Extensions3DUtil::ensureExtensionEnabled(const String& name)
{
if (m_enabledExtensions.contains(name))
return true;
if (m_requestableExtensions.contains(name)) {
m_context->requestExtensionCHROMIUM(name.ascii().data());
m_enabledExtensions.clear();
m_requestableExtensions.clear();
initializeExtensions();
}
return m_enabledExtensions.contains(name);
}
bool Extensions3DUtil::isExtensionEnabled(const String& name)
{
return m_enabledExtensions.contains(name);
}
bool Extensions3DUtil::canUseCopyTextureCHROMIUM(GLenum destFormat, GLenum destType, GLint level)
{
// FIXME: restriction of (RGB || RGBA)/UNSIGNED_BYTE/(Level 0) should be lifted when
// WebGraphicsContext3D::copyTextureCHROMIUM(...) are fully functional.
if ((destFormat == GL_RGB || destFormat == GL_RGBA)
&& destType == GL_UNSIGNED_BYTE
&& !level)
return true;
return false;
}
} // namespace blink
// Copyright 2014 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 SKY_ENGINE_PLATFORM_GRAPHICS_GPU_EXTENSIONS3DUTIL_H_
#define SKY_ENGINE_PLATFORM_GRAPHICS_GPU_EXTENSIONS3DUTIL_H_
#include "sky/engine/platform/PlatformExport.h"
#include "sky/engine/platform/graphics/GraphicsTypes3D.h"
#include "sky/engine/wtf/HashSet.h"
#include "sky/engine/wtf/text/WTFString.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
namespace blink {
class WebGraphicsContext3D;
class PLATFORM_EXPORT Extensions3DUtil {
public:
// Creates a new Extensions3DUtil. If the passed WebGraphicsContext3D has been spontaneously lost, returns null.
static PassOwnPtr<Extensions3DUtil> create(WebGraphicsContext3D*);
~Extensions3DUtil();
bool supportsExtension(const String& name);
bool ensureExtensionEnabled(const String& name);
bool isExtensionEnabled(const String& name);
static bool canUseCopyTextureCHROMIUM(GLenum destFormat, GLenum destType, GLint level);
private:
Extensions3DUtil(WebGraphicsContext3D*);
bool initializeExtensions();
WebGraphicsContext3D* m_context;
HashSet<String> m_enabledExtensions;
HashSet<String> m_requestableExtensions;
};
} // namespace blink
#endif // SKY_ENGINE_PLATFORM_GRAPHICS_GPU_EXTENSIONS3DUTIL_H_
/*
* Copyright (c) 2013, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "sky/engine/platform/graphics/gpu/WebGLImageBufferSurface.h"
#include "sky/engine/platform/graphics/skia/GaneshUtils.h"
#include "sky/engine/public/platform/Platform.h"
#include "sky/engine/public/platform/WebGraphicsContext3DProvider.h"
#include "sky/engine/wtf/PassOwnPtr.h"
#include "third_party/skia/include/core/SkPixelRef.h"
namespace blink {
WebGLImageBufferSurface::WebGLImageBufferSurface(const IntSize& size, OpacityMode opacityMode)
: ImageBufferSurface(size, opacityMode)
{
m_contextProvider = adoptPtr(Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
if (!m_contextProvider)
return;
GrContext* gr = m_contextProvider->grContext();
if (!gr)
return;
ensureTextureBackedSkBitmap(gr, m_bitmap, size, kDefault_GrSurfaceOrigin, kRGBA_8888_GrPixelConfig);
}
WebGLImageBufferSurface::~WebGLImageBufferSurface()
{
}
Platform3DObject WebGLImageBufferSurface::getBackingTexture() const
{
GrTexture* texture = m_bitmap.getTexture();
if (!texture)
return 0;
return texture->getTextureHandle();
}
void WebGLImageBufferSurface::invalidateCachedBitmap()
{
m_cachedBitmap.reset();
}
void WebGLImageBufferSurface::updateCachedBitmapIfNeeded()
{
if (m_cachedBitmap.isNull() && m_bitmap.pixelRef()) {
(m_bitmap.pixelRef())->readPixels(&m_cachedBitmap);
}
}
} // namespace blink
/*
* Copyright (c) 2013, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SKY_ENGINE_PLATFORM_GRAPHICS_GPU_WEBGLIMAGEBUFFERSURFACE_H_
#define SKY_ENGINE_PLATFORM_GRAPHICS_GPU_WEBGLIMAGEBUFFERSURFACE_H_
#include "sky/engine/platform/graphics/ImageBufferSurface.h"
#include "sky/engine/wtf/OwnPtr.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace blink {
class WebGraphicsContext3DProvider;
// This is a GPU backed surface that has no canvas or render target.
class PLATFORM_EXPORT WebGLImageBufferSurface : public ImageBufferSurface {
WTF_MAKE_NONCOPYABLE(WebGLImageBufferSurface); WTF_MAKE_FAST_ALLOCATED;
public:
WebGLImageBufferSurface(const IntSize&, OpacityMode = NonOpaque);
virtual ~WebGLImageBufferSurface();
virtual SkCanvas* canvas() const override { return 0; }
virtual const SkBitmap& bitmap() override { return m_bitmap; }
virtual bool isValid() const override { return m_bitmap.pixelRef(); }
virtual bool isAccelerated() const override { return true; }
virtual Platform3DObject getBackingTexture() const override;
virtual bool cachedBitmapEnabled() const override { return true; }
virtual const SkBitmap& cachedBitmap() const override { return m_cachedBitmap; }
virtual void invalidateCachedBitmap() override;
virtual void updateCachedBitmapIfNeeded() override;
private:
SkBitmap m_bitmap;
// This raw-pixel based SkBitmap works as a cache at CPU side to avoid heavy cost
// on readback from GPU side to CPU side in some cases.
SkBitmap m_cachedBitmap;
OwnPtr<WebGraphicsContext3DProvider> m_contextProvider;
};
} // namespace blink
#endif // SKY_ENGINE_PLATFORM_GRAPHICS_GPU_WEBGLIMAGEBUFFERSURFACE_H_
// Copyright 2014 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 SKY_ENGINE_PLATFORM_GRAPHICS_GPU_WEBGLIMAGECONVERSION_H_
#define SKY_ENGINE_PLATFORM_GRAPHICS_GPU_WEBGLIMAGECONVERSION_H_
#include "sky/engine/platform/PlatformExport.h"
#include "sky/engine/platform/graphics/Image.h"
#include "sky/engine/wtf/RefPtr.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
namespace blink {
class Image;
class IntSize;
// Helper functions for texture uploading and pixel readback.
class PLATFORM_EXPORT WebGLImageConversion {
public:
// Attempt to enumerate all possible native image formats to
// reduce the amount of temporary allocations during texture
// uploading. This enum must be public because it is accessed
// by non-member functions.
enum DataFormat {
DataFormatRGBA8 = 0,
DataFormatRGBA16F,
DataFormatRGBA32F,
DataFormatRGB8,
DataFormatRGB16F,
DataFormatRGB32F,
DataFormatBGR8,
DataFormatBGRA8,
DataFormatARGB8,
DataFormatABGR8,
DataFormatRGBA5551,
DataFormatRGBA4444,
DataFormatRGB565,
DataFormatR8,
DataFormatR16F,
DataFormatR32F,
DataFormatRA8,
DataFormatRA16F,
DataFormatRA32F,
DataFormatAR8,
DataFormatA8,
DataFormatA16F,
DataFormatA32F,
DataFormatNumFormats
};
enum ChannelBits {
ChannelRed = 1,
ChannelGreen = 2,
ChannelBlue = 4,
ChannelAlpha = 8,
ChannelDepth = 16,
ChannelStencil = 32,
ChannelRGB = ChannelRed | ChannelGreen | ChannelBlue,
ChannelRGBA = ChannelRGB | ChannelAlpha,
};
// Possible alpha operations that may need to occur during
// pixel packing. FIXME: kAlphaDoUnmultiply is lossy and must
// be removed.
enum AlphaOp {
AlphaDoNothing = 0,
AlphaDoPremultiply = 1,
AlphaDoUnmultiply = 2
};
enum ImageHtmlDomSource {
HtmlDomImage = 0,
HtmlDomCanvas = 1,
HtmlDomVideo = 2,
HtmlDomNone = 3
};
class PLATFORM_EXPORT ImageExtractor {
public:
ImageExtractor(Image*, ImageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
~ImageExtractor();
bool extractSucceeded() { return m_extractSucceeded; }
const void* imagePixelData() { return m_imagePixelData; }
unsigned imageWidth() { return m_imageWidth; }
unsigned imageHeight() { return m_imageHeight; }
DataFormat imageSourceFormat() { return m_imageSourceFormat; }
AlphaOp imageAlphaOp() { return m_alphaOp; }
unsigned imageSourceUnpackAlignment() { return m_imageSourceUnpackAlignment; }
ImageHtmlDomSource imageHtmlDomSource() { return m_imageHtmlDomSource; }
private:
// Extract the image and keeps track of its status, such as width, height, Source Alignment, format and AlphaOp etc.
// This needs to lock the resources or relevant data if needed and return true upon success
bool extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
RefPtr<NativeImageSkia> m_nativeImage;
RefPtr<NativeImageSkia> m_skiaImage;
Image* m_image;
ImageHtmlDomSource m_imageHtmlDomSource;
bool m_extractSucceeded;
const void* m_imagePixelData;
unsigned m_imageWidth;
unsigned m_imageHeight;
DataFormat m_imageSourceFormat;
AlphaOp m_alphaOp;
unsigned m_imageSourceUnpackAlignment;
};
// Computes the components per pixel and bytes per component
// for the given format and type combination. Returns false if
// either was an invalid enum.
static bool computeFormatAndTypeParameters(GLenum format, GLenum type, unsigned* componentsPerPixel, unsigned* bytesPerComponent);
// Computes the image size in bytes. If paddingInBytes is not null, padding
// is also calculated in return. Returns NO_ERROR if succeed, otherwise
// return the suggested GL error indicating the cause of the failure:
// INVALID_VALUE if width/height is negative or overflow happens.
// INVALID_ENUM if format/type is illegal.
static GLenum computeImageSizeInBytes(GLenum format, GLenum type, GLsizei width, GLsizei height, GLint alignment, unsigned* imageSizeInBytes, unsigned* paddingInBytes);
// Check if the format is one of the formats from the ImageData or DOM elements.
// The formats from ImageData is always RGBA8.
// The formats from DOM elements vary with Graphics ports. It can only be RGBA8 or BGRA8.
static ALWAYS_INLINE bool srcFormatComeFromDOMElementOrImageData(DataFormat SrcFormat)
{
return SrcFormat == DataFormatBGRA8 || SrcFormat == DataFormatRGBA8;
}
static unsigned getClearBitsByFormat(GLenum);
static unsigned getChannelBitsByFormat(GLenum);
// The Following functions are implemented in GraphicsContext3DImagePacking.cpp
// Packs the contents of the given Image which is passed in |pixels| into the passed Vector
// according to the given format and type, and obeying the flipY and AlphaOp flags.
// Returns true upon success.
static bool packImageData(Image*, const void* pixels, GLenum format, GLenum type, bool flipY, AlphaOp, DataFormat sourceFormat, unsigned width, unsigned height, unsigned sourceUnpackAlignment, Vector<uint8_t>& data);
// Extracts the contents of the given ImageData into the passed Vector,
// packing the pixel data according to the given format and type,
// and obeying the flipY and premultiplyAlpha flags. Returns true
// upon success.
static bool extractImageData(const uint8_t*, const IntSize&, GLenum format, GLenum type, bool flipY, bool premultiplyAlpha, Vector<uint8_t>& data);
// Helper function which extracts the user-supplied texture
// data, applying the flipY and premultiplyAlpha parameters.
// If the data is not tightly packed according to the passed
// unpackAlignment, the output data will be tightly packed.
// Returns true if successful, false if any error occurred.
static bool extractTextureData(unsigned width, unsigned height, GLenum format, GLenum type, unsigned unpackAlignment, bool flipY, bool premultiplyAlpha, const void* pixels, Vector<uint8_t>& data);
// End GraphicsContext3DImagePacking.cpp functions
private:
// Helper for packImageData/extractImageData/extractTextureData which implement packing of pixel
// data into the specified OpenGL destination format and type.
// A sourceUnpackAlignment of zero indicates that the source
// data is tightly packed. Non-zero values may take a slow path.
// Destination data will have no gaps between rows.
// Implemented in GraphicsContext3DImagePacking.cpp
static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataFormat, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned destinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool flipY);
};
} // namespace blink
#endif // SKY_ENGINE_PLATFORM_GRAPHICS_GPU_WEBGLIMAGECONVERSION_H_
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册