Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e22ae62 authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge "add DeviceInfo"

parents 5e219cdd 704bed0d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ hwui_src_files := \
    DamageAccumulator.cpp \
    DeferredDisplayList.cpp \
    DeferredLayerUpdater.cpp \
    DeviceInfo.cpp \
    DisplayList.cpp \
    DisplayListCanvas.cpp \
    Dither.cpp \
@@ -208,6 +209,7 @@ LOCAL_SRC_FILES += \
    unit_tests/CanvasStateTests.cpp \
    unit_tests/ClipAreaTests.cpp \
    unit_tests/DamageAccumulatorTests.cpp \
    unit_tests/DeviceInfoTests.cpp \
    unit_tests/FatVectorTests.cpp \
    unit_tests/LayerUpdateQueueTests.cpp \
    unit_tests/LinearAllocatorTests.cpp \
+48 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <DeviceInfo.h>

#include "Extensions.h"

#include <GLES2/gl2.h>

#include <thread>
#include <mutex>

namespace android {
namespace uirenderer {

static DeviceInfo* sDeviceInfo = nullptr;
static std::once_flag sInitializedFlag;

const DeviceInfo* DeviceInfo::get() {
    return sDeviceInfo;
}

void DeviceInfo::initialize() {
    std::call_once(sInitializedFlag, []() {
        sDeviceInfo = new DeviceInfo();
        sDeviceInfo->load();
    });
}

void DeviceInfo::load() {
    mExtensions.load();
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
}

} /* namespace uirenderer */
} /* namespace android */

libs/hwui/DeviceInfo.h

0 → 100644
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef DEVICEINFO_H
#define DEVICEINFO_H

#include "Extensions.h"
#include "utils/Macros.h"

namespace android {
namespace uirenderer {

class DeviceInfo {
    PREVENT_COPY_AND_ASSIGN(DeviceInfo);
public:
    // returns nullptr if DeviceInfo is not initialized yet
    // Note this does not have a memory fence so it's up to the caller
    // to use one if required. Normally this should not be necessary
    static const DeviceInfo* get();

    // only call this after GL has been initialized, or at any point if compiled
    // with HWUI_NULL_GPU
    static void initialize();

    const Extensions& extensions() const { return mExtensions; }

    int maxTextureSize() const { return mMaxTextureSize; }

private:
    DeviceInfo() {}
    ~DeviceInfo() {}

    void load();

    Extensions mExtensions;
    int mMaxTextureSize;
};

} /* namespace uirenderer */
} /* namespace android */

#endif /* DEVICEINFO_H */
+2 −2
Original line number Diff line number Diff line
@@ -35,8 +35,8 @@ namespace uirenderer {
#endif


Extensions::Extensions() {
    StringCollection extensions((const char*) glGetString(GL_EXTENSIONS));
void Extensions::load() {
    auto extensions = StringUtils::split((const char*) glGetString(GL_EXTENSIONS));
    mHasNPot = extensions.has("GL_OES_texture_npot");
    mHasFramebufferFetch = extensions.has("GL_NV_shader_framebuffer_fetch");
    mHasDiscardFramebuffer = extensions.has("GL_EXT_discard_framebuffer");
+5 −2
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@

#include <cutils/compiler.h>

#include <string>
#include <unordered_set>

namespace android {
namespace uirenderer {

@@ -26,9 +29,9 @@ namespace uirenderer {
// Classes
///////////////////////////////////////////////////////////////////////////////

class ANDROID_API Extensions {
class Extensions {
public:
    Extensions();
    void load();

    inline bool hasNPot() const { return mHasNPot; }
    inline bool hasFramebufferFetch() const { return mHasFramebufferFetch; }
Loading